老师好,我想在我原有的策略基础上添加一个移动止损的策略。只有在建仓后利润达到N个点或N%的利润后,自动触发移动止损。止损设置为总利润的百分之几(比如回撤总利润的20%、25%,保证80%、75%的利润)如果按利润百分比不好实现就设置为回撤多少个点)。辛苦老师,感谢!感谢!
以下是我的策略代码,如果代码有错误请老师一并指正。谢谢!
input:ss(1,1,100,1),N1(5,1,100,1),N2(10,1,200,1); //准备需要的中间变量 MA1:MA(CLOSE,N1); MA2:MA(CLOSE,N2); week_o:="$OPEN#week"; day_o:="$OPEN#DAY"; //多头建仓条件 ; Long:=close>week_o AND close>day_o AND MA1>MA2 ; if Long then begin sellshort(holding<0,holding,thisclose); buy(holding=0,SS,thisclose); end //多头平仓条件 //符合以下条件时,平全部多单; LongX:= MA1<MA2 AND Holding>0; if LongX then begin sell(SS,0,Limitr,c); END //建立空头建仓条件 //符合以下条件时,如果手里有多单,平掉全部多单;最新价格下ss手空单; Short:=close<week_o AND close<day_o AND MA1<MA2 ; if Short then begin SELL(holding>0, holding,thisclose); BUYSHORT(holding=0,ss,thisclose) ; end //空头平仓条件 //符合以下条件时,平全部空单; ShortX:=MA1>MA2 AND Holding<0; if ShortX then begin SELLSHORT(ss,0,Limitr,c); END
|