自动止损、止盈、盈利后移动止损、分批出场的工具
自动止损、止盈、盈利后移动止损、分批出场,一个还可以的辅助性工具
extern string 自动止损参数="默认打开";extern bool AutoStoploss=True;extern double stoploss= 22;extern string 自动止盈参数="默认打开";extern bool AutoTakeProfit=True;extern double takeprofit=30;extern string 盈利后移动止损="默认打开";extern bool AutoTrailingStop=true;extern double TrailingStop = 15;extern string 分次离场参数="按比例分步撤退";extern bool Gradually = False; extern int GraduallyNum = 3; double OriginalLot;//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start(){for(int cnt=0;cnt<OrdersTotal();cnt++) {if (OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)){ if(OrderSymbol()==Symbol()) { double stp=OrderStopLoss(); double tpt=OrderTakeProfit(); double OpenPrice = OrderOpenPrice(); if (OriginalLot == 0) { OriginalLot=OrderLots(); } if(OrderType()==OP_BUY) { CraduallyBuy (); if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0&&OrderMagicNumber()<=0) OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,Ask+Point*takeprofit,0,Green); else { if (AutoStoploss && stp==0) { OrderModify(OrderTicket(),OrderOpenPrice(),Ask-Point*stoploss,OrderTakeProfit(),0,Green); } if (AutoTakeProfit && tpt==0) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+Point*takeprofit,0,Green); } if (AutoTrailingStop && ((Bid - OpenPrice) > Point*TrailingStop)&&OrderMagicNumber()<=0) { if((Bid-stp)>TrailingStop*Point ) OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green); } } } if(OrderType()==OP_SELL) { CraduallySell (); if (AutoStoploss && AutoTakeProfit && stp==0 && tpt==0) OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,Bid-Point*takeprofit,0,Green); else { if (AutoStoploss && stp==0) { OrderModify(OrderTicket(),OrderOpenPrice(),Bid+Point*stoploss,OrderTakeProfit(),0,Green); } if (AutoTakeProfit && tpt==0) { OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-Point*takeprofit,0,Green); } if(AutoTrailingStop && ((OpenPrice-Ask) > Point*TrailingStop )) { if((stp-Ask)>TrailingStop*Point) OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Green); } } } } }else{ OriginalLot=0;} } } void CraduallyBuy () { double OpenPrice = OrderOpenPrice(); double lot=OrderLots(); for (int yi=1;yi<=GraduallyNum;yi++) { if (NormalizeDouble((Bid - OpenPrice)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0)) { if (lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2)) { OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Bid,3,CLR_NONE); } } } } void CraduallySell () { double OpenPrice = OrderOpenPrice(); double lot=OrderLots(); for (int yi=1;yi<=GraduallyNum;yi++) { if (NormalizeDouble((OpenPrice - Ask)/Point,0) == NormalizeDouble(TrailingStop/GraduallyNum*yi,0)) { if (lot != NormalizeDouble(OriginalLot*(1-yi/GraduallyNum),2)) { OrderClose(OrderTicket(),NormalizeDouble(OriginalLot/GraduallyNum,2),Ask,3,CLR_NONE); } } } }
●点击查看《EA安装及运行教程》.
●玩转策略正确流程:①复盘回测,判定策略质量→②加载虚拟盘检验,检测策略的原理可行性→③加载美分实盘试验,测试EA风险值→④实盘运行,注意风控!
.友情提醒:外汇EA网提供的资源,都不包含技术服务,请大家谅解!部分资源来源于用户上传和网络,如有侵权请邮件联系站长!外汇EA网资源售价只是赞助,收取费用仅维持本站的日常运营所需!外汇EA网不保证所提供下载的资源的准确性、安全性和完整性,策略资源仅供下载学习之用,如用于商业或者非法用途,与本站无关,一切后果请用户自负!
· 版权信息:本站所有资源仅供学习与参考,请勿用于商业用途,如有侵犯您的版权,请及时联系官网客服,我们将尽快处理。
· 免责声明:投资有风险,本网站所包含之所有信息均不构成任何投资的建议或意见,网站内容仅供参考。不适合所有投资者,客户需根据自身情况选择,网站访问者不应依赖本网站信息并将其视爲作爲或不作爲之依据。 对于任何个人依据本网站或网站的信息采取的作爲或不作爲所导致的结果,我们将毋须承担任何责任。
iMQL5自动外汇EA交易与EA指标 » 自动止损、止盈、盈利后移动止损、分批出场的工具