技術分析指標 SineWave / Multicharts 範例程式碼

以下 介紹這個較冷門的指標,最後並附上程式碼,有興趣的讀者請自行取用研究。

Sinewave 指標是由知名技術分析專家 John Ehlers 所開發。與傳統的 RSI 或 MACD 不同,它是基於「市場具有周期性」的假設

計算公式與原理

Sinewave 指標的核心在於判斷當前價格處於循環週期中的哪一個階段 主要由兩條線組成:

  1. Sine(正弦線): 當前週期的正弦值。
  2. Lead Sine(領先正弦線): 將正弦線向前推進 45 度的線,用來預測趨勢轉折。

指標使用方式

Sinewave 好用的地方在於它能區分 震盪行情 與趨勢行情。

震盪行情中的交易訊號

當市場處於橫盤整理或明顯的週期性震盪時,這兩條線的交叉極具參考價值:

  • 買入訊號: 當 Sine 線「由下往上」穿過 Lead Sine 線時,代表週期底部已過,價格即將回升。
  • 賣出訊號: 當 Sine 線「由上往下」穿過 Lead Sine 線時,代表週期頂部已過,價格即將回落。

趨勢行情中的判斷

當強大趨勢出現時,Sinewave 會呈現特殊的形狀,兩條線會趨於平行或出現類似階梯狀的波動,且不再頻繁交叉。

指標公式有些複雜,直接轉換成multicharts語法 如下:

Inputs: Price((H+L)/2);

Vars: InPhase(0), Quadrature(0),Phase(0),DeltaPhase(0),count(0),InstPeriod(0),Period(0),DCPhase(0),RealPart(0),ImagPart(0);

 If CurrentBar > 5 then begin

Value1 = Price - Price[6];
Value2 =Value1[3];
Value3 =.75*(Value1 - Value1[6]) + .25*(Value1[2] - Value1[4]);

InPhase = .33*Value2 + .67*InPhase[1];
Quadrature = .2*Value3 + .8*Quadrature[1];

If AbsValue(InPhase +InPhase[1]) > 0 then Phase =
ArcTangent(AbsValue((Quadrature+Quadrature[1]) / (InPhase+InPhase[1])));

If InPhase < 0 and Quadrature > 0 then Phase = 180 - Phase;
If InPhase < 0 and Quadrature < 0 then Phase = 180 + Phase;
If InPhase > 0 and Quadrature < 0 then Phase = 360 - Phase;

DeltaPhase = Phase[1] - Phase;

If Phase[1] < 90 and Phase > 270 then DeltaPhase = 360 + Phase[1] - Phase;
If DeltaPhase < 1 then DeltaPhase = 1;
If DeltaPhase > 60 then Deltaphase = 60;

InstPeriod = 0;
Value4 = 0;

For count = 0 to 40 begin
  Value4 = Value4 + DeltaPhase[count];
  If Value4 > 360 and InstPeriod = 0 then begin
  InstPeriod = count;
end;
end;

If InstPeriod = 0 then InstPeriod = InstPeriod[1];

Value5 = .25*InstPeriod + .75*Value5[1];
Period = IntPortion(Value5);
RealPart = 0;
ImagPart = 0;

For count = 0 To Period - 1 begin
  RealPart = RealPart + Sine(360 * count / Period) * (Price[count]);
  ImagPart = ImagPart + Cosine(360 * count / Period) * (Price[count]);
end;

If AbsValue(ImagPart) > 0.001 then DCPhase = Arctangent(RealPart / ImagPart);
If AbsValue(ImagPart) <= 0.001 then DCPhase = 90 * Sign(RealPart);

 DCPhase = DCPhase + 90;

If ImagPart < 0 then DCPhase = DCPhase + 180;
If DCPhase > 315 then DCPhase = DCPhase - 360;

Plot1(Sine(DCPhase), "Sine");
Plot2(Sine(DCPhase + 45), "LeadSine");

end;

套用到multicharts 圖表視窗 放在副圖

當粉紅色的Sine大於黃色的LeadSine表示目前的行情呈現趨勢盤,建議順勢交易;反之 當粉紅色的Sine小於黃色的LeadSine,表示現階段是震盪盤整 應該區間操作

個人心得: SineWave 本身不具備價格方向性的判斷, SineWave 指標在橫盤震盪時表現較佳,但在強勢趨勢中,指標會頻繁交叉造成連續停損。

套用在台指期市場 我還找不太到適合的應用方法開發理想交易策略,如果你有更好的想法歡迎和我分享

分享你的喜愛