您好,我寫了一個狹幅盤整N日後,出量突破做多的策略,但是寫出來跑回測(週期為日線),結果卻和我想達成的目標不同,想請問是不是有什麼地方寫錯了?
進場邏輯:
1、至少連續15天高低點震幅低於5%。
2、5,10,20均線糾結(三條均線間的倆倆差異都低於3%)
3、最近一天大漲3%以上,當天成交量大於10日均量1倍以上,且收盤價高於5,10,20均線。
上述3個條件同時符合時,進場做多(次日開盤價市價進場)。
移動停利:
當獲利狀態時,收盤價跌破5日均出場。
停損機制:
當收盤價低於買進當根K線的5,10,20均線的3%(取最低值)時停損出場。
語法如下:
inputs:
Length1(5), //MA5
Length2(10), //MA10
Length3(20), //MA20
VolLength(10), //10日均量
AmpThreshold(3), //震幅小於3%
MA_Diff_Threshold(3), //兩兩均線差異小於3%
VolumeThreshold(1), //成交量大於10均量N倍
Num_Threshold(15); //至少N日震幅小於3%
variables:
Amp(0), //震幅
Num(0), //連續N日
MA_Diff1(0), //MA5及MA10差異
MA_Diff2(0), //MA5及MA20差異
MA_Diff3(0); //MA10及MA20差異
Amp = (High - Low) / Close * 100;
MA_Diff1 = absvalue(Average(Close, Length1) - Average(Close, Length2)) / Minlist(Average(Close, Length1), Average(Close, Length2)) * 100;
MA_Diff2 = absvalue(Average(Close, Length1) - Average(Close, Length3)) / Minlist(Average(Close, Length1), Average(Close, Length3)) * 100;
MA_Diff3 = absvalue(Average(Close, Length2) - Average(Close, Length3)) / Minlist(Average(Close, Length2), Average(Close, Length3)) * 100;
if Amp > AmpThreshold then Num = 0;
if Amp[1] <= AmpThreshold then Num = 1;
if Amp <= AmpThreshold then begin
Num = Num[1]+1;
end;
condition1 = Num[1] >= 15;
condition2 = MA_Diff1 <= MA_Diff_Threshold and MA_Diff2 <= MA_Diff_Threshold and MA_Diff3 <= MA_Diff_Threshold;
condition3 = Close > Close[1] * 1.03 and Volume > Average(Volume, VolLength) * (1 + VolumeThreshold) and Close > Maxlist(Average(Close, Length1), Average(Close, Length2), Average(Close, Length3));
if Position = 0 and condition1 and condition2 and condition3 then setposition(1, MARKET);
variables:
ts(0), //移動停利
sl(0), //停損點
_entryprice(0); //多單進場價格
ts = Average(Close, 5);
if Position[1] = 0 and Position = 1 then begin
_entryprice = O;
sl = Minlist(Average(Close, Length1), Average(Close, Length2), Average(Close, Length3)) * 0.97;
end;
if Position = 1 and c > _entryprice then begin
if c < ts then setposition(0, MARKET);
end;
if Position = 1 then setposition(0, sl);
寫完感覺邏輯沒錯,但回測跑出來進出場點都不太對,不曉得是哪裡出了問題,還請各位大大協助解答,謝謝。


6 評論