EasyTrader ArtNo 218
建立自適應振盪區間的方法當我們使用任何具有超買超賣特性的振盪指標最常見的問題之一,是它使用固定的值來定義指標目前是位於超買區或是超賣區。這會導致指標本身和任何利用此振盪指標作為元素的交易系統,在市場遠離指標的超買超賣區外,或在此區間內擺蕩時變得無效
若要避免此限制,我們可以使用動態或變數的方法來計算超買和超賣的區間。例如,我們可以利用程式來追蹤擺蕩盪指標最近的 20 重要的轉折點,並使用這些轉折點的平均值作為超買和超賣的區域設定,而不是固定的值。
計算這些轉折點的平均值所形成的區間帶寬或許還不足夠,這是由於指標的特性造成交叉頻煩,為了能讓帶寬 (Band) 能儘量的加寬,我們可以儲存過去一段時間以來,發生創新高及創新低的轉折點,並將其平均值來建構超買超賣的區域。
我們來看透過上述的概念以及使用RSI振盪指標所建立的動態超買超賣區域。
{ 自訂函數 _MagicQS131_FTOP : 計算自適應超買線 }
Input: Price(Numeric), Length(numeric), Strength(Numeric), Factor(Numeric);
Vars: NewSwing(false), count(0), Summ(0), varBand(0), HighestHi(0);
Array: TopPoints[19](-1); {陣列初始值設 -1 表示未有新高或新低值 }
If Factor > 1 OR Factor < 0 then varBand = 1 else varBand = Factor;
{ 尋找轉折新高 }
NewSwing = false;
If SwingHighBar(1,Price,Strength,Strength+2) = Strength then Begin
{ 找到後作記錄 , 並將陣列內資料重新 update}
For count = 19 DownTo 1 Begin
TopPoints[count] = TopPoints[count-1];
end;
TopPoints[0] = Price[Strength];
NewSwing = True;
end;
HighestHi = 0;
Summ = 0;
For count = 19 DownTo 1 Begin
TopPoints[count] = TopPoints[count-1];
end;
TopPoints[0] = Price[Strength];
NewSwing = True;
end;
HighestHi = 0;
Summ = 0;
{ 尋找陣列內最高轉折點的值 }
For count = 0 to length-1 Begin
Summ = Summ + TopPoints[count];
If TopPoints[count] > HighestHi then HighestHi = TopPoints[count];
end;
If Length <> 0 then Begin
end else_MagicQS131_FTOP = 0;
{ 自訂函數 _MagicQS131_FBOT : 計算自適應超賣線 }
Input: Price(Numeric), Length(numeric), Strength(Numeric), Factor(Numeric);
Vars: NewSwing(false), count(0), Summ(0), varBand(0), LowestLo(0);
Array: BotPoints[19](-1);
If Factor > 1 OR Factor < 0 then varBand = 1 else varBand = Factor;
For count = 0 to length-1 Begin
Summ = Summ + TopPoints[count];
If TopPoints[count] > HighestHi then HighestHi = TopPoints[count];
end;
If Length <> 0 then Begin
{ 將平均值 + (最高值-平均值)*調整系數 }
If TopPoints[Length-1] <> -1 then
_MagicQS131_FTOP = ( Summ / Length ) + ( HighestHi - Summ / Length ) * VarBand
else _MagicQS131_FTOP = -9999999;
If TopPoints[Length-1] <> -1 then
_MagicQS131_FTOP = ( Summ / Length ) + ( HighestHi - Summ / Length ) * VarBand
else _MagicQS131_FTOP = -9999999;
end else_MagicQS131_FTOP = 0;
{ 自訂函數 _MagicQS131_FBOT : 計算自適應超賣線 }
Input: Price(Numeric), Length(numeric), Strength(Numeric), Factor(Numeric);
Vars: NewSwing(false), count(0), Summ(0), varBand(0), LowestLo(0);
Array: BotPoints[19](-1);
If Factor > 1 OR Factor < 0 then varBand = 1 else varBand = Factor;
{ 尋找轉折新低 }
NewSwing = false;
If SwingLowBar(1,Price,Strength,Strength+2) = Strength then Begin
NewSwing = false;
If SwingLowBar(1,Price,Strength,Strength+2) = Strength then Begin
{ 找到後作記錄 , 並將陣列內資料重新 update}
For count = 19 DownTo 1 Begin
BotPoints[count] = BotPoints[count-1];
end;
BotPoints[0] = Price[Strength];
NewSwing = True;
end;
LowestLo = 999999;
Summ = 0;
For count = 19 DownTo 1 Begin
BotPoints[count] = BotPoints[count-1];
end;
BotPoints[0] = Price[Strength];
NewSwing = True;
end;
LowestLo = 999999;
Summ = 0;
{ 尋找陣列內最低轉折點的值 }
For count = 0 to length-1 Begin
Summ = Summ + BotPoints[count];
If BotPoints[count] < LowestLo then
LowestLo = BotPoints[count];
end;
If Length <> 0 then Begin
For count = 0 to length-1 Begin
Summ = Summ + BotPoints[count];
If BotPoints[count] < LowestLo then
LowestLo = BotPoints[count];
end;
If Length <> 0 then Begin
{ 將平均值 - (平均值 - 最低值)*調整系數 }
If BotPoints[Length-1] <> -1 then
_MagicQS131_FBOT = ( Summ / Length ) - ( Summ / Length - LowestLo ) * VarBand
else _MagicQS131_FBOT = -9999999;
end else _MagicQS131_FBOT = 0;
{ 自訂指標 _MagicQS131_Idx : 隨盤勢自動調整的超買超賣區間 }
Input: Osc(RSI(Close,20)) , Swings(2), Strength(2), Factor(.75) ;
Vars: TopBand(0), BotBand(0);
TopBand = _MagicQS131_FTOP( Osc , Swings , Strength , Factor );
BotBand = _MagicQS131_FBOT( Osc , Swings , Strength , Factor );
Plot1( OSCValue , "Osc" );
Plot2( Topband, "Top" );
Plot3( Botband, "Bot" );
交易系統
_MagicQS131_FBOT = ( Summ / Length ) - ( Summ / Length - LowestLo ) * VarBand
else _MagicQS131_FBOT = -9999999;
end else _MagicQS131_FBOT = 0;
{ 自訂指標 _MagicQS131_Idx : 隨盤勢自動調整的超買超賣區間 }
Input: Osc(RSI(Close,20)) , Swings(2), Strength(2), Factor(.75) ;
Vars: TopBand(0), BotBand(0);
TopBand = _MagicQS131_FTOP( Osc , Swings , Strength , Factor );
BotBand = _MagicQS131_FBOT( Osc , Swings , Strength , Factor );
Plot1( OSCValue , "Osc" );
Plot2( Topband, "Top" );
Plot3( Botband, "Bot" );
交易系統
作多規則為 RSI值向上交叉超賣線
If Osc Crosses Over Botband then Buy next bar at market;
作空規則為 RSI值向下交叉超買線
If Osc Crosses Under TopBand then Sell next bar at market;
沒有留言:
張貼留言