?
需要再明確下你的平倉條件。每盈利10點止盈1手,則盈利20點止盈1手、盈利30點再止盈1手?若價格未盈利20點,又回落到盈利10點的的時候不止盈,直接DIFF下到0軸再全平?
?
?
?來源:程序化久久網( m.weiqiv.net.cn )
?
?
以下案例僅供參考。
variable:price=0;?? //定義全局變量price
?
diff:=ema(close,12)-ema(close,26);
con1:cross(diff,0);
con2:cross(0,diff);
?
if con1 then begin????????????????? //diff上穿0軸時,平空單,開5手多單
?? sellshort(holding<0,holding,market);
?? buy(holding=0,5,market);
?? price:=enterprice;
?? end
?
if con2 then begin????????????????? //diff下穿0軸時,平多單,開5手空單
?? sell(holding>0,holding,market);
?? buyshort(holding=0,5,market);
?? price:=enterprice;
?? end
??
if holding>0 and c-price>=10*mindiff? then? begin?? //多單盈利每10點,平1手
?? sell(1,1,market);
?? price:=c;
?? end
??
if holding<0 and price-c>=10*mindiff then? begin? //空單盈利每10點,平1手
?? sellshort(1,1,market);
?? price:=c;
?? end