{MyRealMp=InitMyRealMp;} If(Date<>Date[1])
{HighAfterlongEntry=High; LowAfterShortEntry=Low; MyRealMp=0; }Else
{HighAfterlongEntry=Max(HighAfterlongEntry,High); LowAfterShortEntry=Min(LowAfterShortEntry,Low);} if (Time {TmpPrice=Max(HighAfterLongEntry-(TrailingGrid-OffSet)*MinPoint,Low); TmpLots=Abs(MyRealMp*EveryLots); Sell(TmpLots,TmpPrice); MyRealMp=0; LowAfterShortEntry=Low; }else If(MyRealMp<0 And High-LowAfterShortEntry>=TrailingGrid*MinPoint And (High-Low=TrailingGrid*MinPoint And Close>Open))) {TmpPrice=Min(LowAfterShortEntry+(TrailingGrid+OffSet)*MinPoint,High); TmpLots=Abs(MyRealMp*EveryLots); BuyToCover(TmpLots,TmpPrice); MyRealMp=0; HighAfterLongEntry=0;} If(MyRealMp==0 And High-LowAfterShortEntry>=FirstGrid*MinPoint)//第一笔多单开仓 {TmpPrice=Min(LowAfterShortEntry+(FirstGrid+OffSet)*MinPoint,High); TmpLots=EveryLots; Buy(TmpLots,TmpPrice); MyRealMp=1; HighAfterLongEntry=High; }Else If(MyRealMp>0 And MyRealMp {TmpPrice=Min(LowAfterShortEntry+(FirstGrid+MyRealMp*AddGrid+OffSet)*MinPoint,High); TmpLots=EveryLots; Buy(TmpLots,TmpPrice); MyRealMp=MyRealMp+1; }else If(MyRealMp==0 And HighAfterLongEntry-Low>=FirstGrid*MinPoint)//第一笔空单开仓 {TmpPrice=Max(HighAfterLongEntry-(FirstGrid-OffSet)*MinPoint,Low); TmpLots=EveryLots; SellShort(TmpLots,TmpPrice); MyRealMp=-1; LowAfterShortEntry=Low; }else If(MyRealMp<0 And -1*MyRealMp {TmpPrice=Max(HighAfterLongEntry-(FirstGrid-Abs(MyRealMp*AddGrid)-OffSet)*MinPoint,Low); TmpLots=EveryLots; SellShort(TmpLots,TmpPrice); MyRealMp=MyRealMp-1;} }else If(Time>=ExitOnCloseMins/100) {If(MyRealMp>0) {TmpLots=Abs(MyRealMp*EveryLots); TmpPrice=Close; Sell(0,TmpPrice); MyRealMp=0;} If(MyRealMp<0) {TmpLots=Abs(MyRealMp*EveryLots); TmpPrice=Close; BuyToCover(0,TmpPrice); MyRealMp=0;}} SetGlobalVar(0,MyRealMp); SetGlobalVar(1,HighAfterLongEntry); SetGlobalVar(2,LowAfterShortEntry); Commentary(\ Commentary(\ End 完整的包括止损,移动止赢交易策略实例 金字塔[其他期货软件] 使用说明: 代码工作在图表自动交易模式下 当出现开仓后,开仓价格相比,最大损失超过2%止损 当出现盈利后,与最大盈利价格相比,回落到60%幅度后止赢离场 MA1:=MA(CLOSE,5); MA2:=MA(CLOSE,30); variable:maxprofit=0;//有仓位时最大获利幅度 //开仓 IF CROSS(MA1,MA2) THEN BEGIN BUY(1,1); maxprofit:=0; END //平仓 SELL(CROSS(MA2,MA1),0); //判断当前持仓状态下的最大盈利 win:=0; win2:=0; if holding > 0 and enterbars > 0 then begin win:=(c-enterprice)/enterprice*100; //记录最大盈利 if win > maxprofit then maxprofit:=win; win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度 end if holding < 0 and enterbars > 0 then begin win:=(enterprice-c)/enterprice*100; //记录最大盈利 if win > maxprofit then maxprofit:=win; win2:=(maxprofit-win)/maxprofit*100; //最大盈利后的回调幅度 end //出现浮动亏损比如2%平仓 止损:SELL(win < -2,0); //出现最高盈利后,回落到盈利的60%平仓出场 止赢:SELL(win2 >= 60 and openprofit > 0, 0); 移动止损模版[其他期货软件] 使用说明: 该模版用于历史评测,不用于实盘交易。 该模版的亮点在于模块化和扩展性 理解模版精华后,各种思路可在模版里随便添加、删除、扩展等 //该模版用于历史评测,不用于实盘交易。 //该模版的亮点在于模块化和扩展性 //理解模版精华后,各种思路可在模版里随便添加、删除、扩展等 variable:zs=c,hl=c;//声明全局变量zs、hl ma5:=ma(c,5); ma20:=ma(c,20); atr:=ma(h-l,20);//市场平均波动幅度 buycond:=cross(ma5,ma20);//平空开多条件 sellcond:=cross(ma20,ma5);//平多开空条件 if holding>0 then begin 多止损:zs; if l if holding<0 then begin 空止损:zs; if h>zs then sellshort(1,1,limitr,max(o,zs)+mindiff); else if buycond then sellshort(1,1,limitr,c); end if holding=0 and buycond then begin//多头开仓 buy(1,1,limitr,c); zs:=c-2*atr; hl:=c;//hl开仓后的最有利价位,刚买入时,最有利价位为开仓价 end if holding=0 and sellcond then begin//空头开仓 buyshort(1,1,limitr,c); zs:=c+2*atr; hl:=c; end if holding>0 and enterbars>0 and h>hl then begin//最高价抬升,止损位相应地抬升 hl:=h; zs:=hl-2*atr; end if holding<0 and enterbars>0 and l zs:=l+2*atr; end 金字塔R-Breaker交易系统源码[金字塔模型] runmode:0; input:notbef(090000); input:notaft(145500); input:f1(0.35); input:f2(0.07); input:f3(0.25); input:myreverse(1); input:rangemin(0.2); input:xdiv(3); variable:ssetup=0; variable:bsetup=0; variable:senter=0; variable:benter=0; variable:bbreak=0; variable:sbreak=0; variable:ltoday=0; variable:hitoday=999999; variable:startnow=0; variable:div=0; variable:rfilter=false; i_reverse:=myreverse*(callstock(stklabel,vtopen,6,0)/100); i_rangemin:=rangemin*(callstock(stklabel,vtopen,6,0)/100); if barpos=1 then begin startnow:=0; div:=max(xdiv,1); end