1997年有一篇有名的文章討論 TRIX這個指標 "Playing TRIX: The triple exponential smoothing oscillator." 這個交易策略有一個值得提的地方就是運用到線性回歸這個工具,在使用上類似布林通道。老規矩我PO上程式碼及原文,有興趣的可以深入研究,語法是用TS2000i的easylanguage寫成。
我認為這個策略觀念很好,但是有點複雜,所以我一直沒有納入交易策略,不過就我所知國外不少交易模型是建構在TRIX指標上面,可能不失為一好方法。
先建函數NewTRIX:
Inputs: Price(NumericSeries), Length(NumericSimple);
Vars: LogP(0), alpha(0), sm1(0), sm2(0), sm3(0);
LogP = Log(Price);
IF CurrentBar = 1 Then Begin
sm1 = LogP;
sm2 = LogP;
sm3 = LogP;
alpha = 2 / (Length + 1);
End Else Begin
sm1 = (LogP - sm1) * alpha + sm1;
sm2 = (sm1 - sm2) * alpha + sm2;
sm3 = (sm2 - sm3) * alpha + sm3;
NewTrix = (sm3 - sm3[1]) * 100;
End;
Continuing on, the entries for the TRIX system code are based on the same premise as the alerts for the indicator code given above. The ZeroCrss and AvgCross inputs are used to determine the basis for the entry signals. If both inputs are set to Y, a zero cross or a linear regression average cross will trigger a long/short entry. If one of the two inputs is set to N, then only the other criteria will be used to generate entry signals.
TRIX策略範例:
Inputs: Price(Close), TrixLen(3), TSLen(8), ZeroCrss("Y"), AvgCrss("Y");
Vars: TRXval(0), AvgTRX(0), Zero(0);
TRXval = NewTRIX(Price, TRIXLen);
AvgTRX = LinearRegValue(TRXval, TSLen, 0);
IF UpperStr(ZeroCrss) = "Y" Then Begin
IF TRXval Crosses Above Zero Then
Buy ("B_ZCrss") This Bar on Close;
IF TRXval Crosses Below Zero Then
Sell ("S_ZCrss") This Bar on Close;
End;
IF UpperStr(AvgCrss) = "Y" Then Begin
IF TRXval Crosses Above AvgTRX Then
Buy ("B_AvgCrss") This Bar on Close;
IF TRXval Crosses Below AvgTRX Then
Sell ("S_AvgCrssS") This Bar on Close;
End;
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!