《Wen外期策略團隊》
最近看國外的網站,看到一個簡單自適化均線策略,簡單測試一下小SP,發現還真有幾分樣子,給大家參考一下。
函數1: _AMA
Inputs: Period(Numeric);
Vars: Noise(0), Signal(0), Diff(0), efRatio(0), Smooth(1), Fastest(.6667),
Slowest(.0645), AdaptMA(0);
Diff = AbsValue(Close - Close[1]);
IF CurrentBar <= Period Then AdaptMA = Close;
IF CurrentBar > Period Then Begin
Signal = AbsValue(Close - Close[Period]);
Noise = Summation(Diff, Period);
efRatio = Signal / Noise;
Smooth = Power(efRatio * (Fastest - Slowest) + Slowest, 2);
AdaptMA = AdaptMA[1] + Smooth * (Close - AdaptMA[1]);
End;
_AMA = AdaptMA;
函數2: _AMAF
Inputs: Period(Numeric), Pcnt(Numeric);
Vars: Noise(0), Signal(0), Diff(0), efRatio(0), Smooth(1), Fastest(.6667),
Slowest(.0645), AdaptMA(0), AMAFltr(0);
Diff = AbsValue(Close - Close[1]);
IF CurrentBar <= Period Then AdaptMA = Close;
IF CurrentBar > Period Then Begin
Signal = AbsValue(Close - Close[Period]);
Noise = Summation(Diff, Period);
efRatio = Signal / Noise;
Smooth = Power(efRatio * (Fastest - Slowest) + Slowest, 2);
AdaptMA = AdaptMA[1] + Smooth * (Close - AdaptMA[1]);
AMAFltr = StdDev(AdaptMA-AdaptMA[1], Period) * Pcnt;
End;
_AMAF = AMAFltr;
策略:
Inputs: Period(10), Pcnt(.15);
Vars: AMAVal(0), AMAFVal(0), AMALs(0), AMAHs(0);
AMAVal = _AMA(Period);
AMAFVAl = _AMAF(Period, Pcnt);
IF CurrentBar = 1 Then Begin
AMALs = AMAVal;
AMAHs = AMAVal;
End Else Begin
IF AMAVal < AMAVal[1] Then
AMALs = AMAVal;
IF AMAVal > AMAVal[1] Then
AMAHs = AMAVal;
IF AMAVal - AMALs Crosses Above AMAFVal Then
Buy This Bar on Close;
IF AMAHs - AMAVal Crosses Above AMAFVal Then
Sell This Bar on Close;
End;
下圖為ES 的日K績效圖,期間:2008年到2014年,手續費為10美元:
結論:
上面的策略資料期間是日K的,所以留倉時間會稍微長,交易次數較少,但參數跟原作者使用的一樣,沒有再經過最佳化。讀者可再將此策略加一些其他的濾網,或是使用不同的時間區間,相信自適化均線可以成為寫策略一個不錯的選擇。
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!