诚信为本
量力而为
当前位置:峰汇在线 > MQL语言 > MQL4函数模块 > 正文

外汇EA编程中移动止损功能的实现

该函数在订单盈利后执行移动止损功能。

input int TrailingStop=50;
input int TrailingStep=0;
input int Magic=123456;
bool cg = false;
void MoveTrailingStop()
{
   int cnt,total=OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {
      cg = OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderType()<=OP_SELL&&OrderSymbol()==Symbol()&&((OrderMagicNumber()==Magic)))
      {
         if(OrderType()==OP_BUY&&NormalizeDouble((Ask-OrderOpenPrice()),Digits)>TrailingStop*Point)
         {
            if(TrailingStop>0&&Ask>NormalizeDouble(OrderOpenPrice(),Digits))  
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-Point*(TrailingStop+TrailingStep),Digits))||(OrderStopLoss()==0))
               {
                  cg = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Point*TrailingStop,Digits),OrderTakeProfit(),0,Blue);
               }
            }
         }
         if(OrderType()==OP_SELL&&NormalizeDouble((OrderOpenPrice()-Bid),Digits)>TrailingStop*Point)
         {
            if(TrailingStop>0&&Bid<NormalizeDouble(OrderOpenPrice(),Digits))  
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+Point*(TrailingStop+TrailingStep),Digits)))||(OrderStopLoss()==0))
               {
                  cg = OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+Point*TrailingStop,Digits),OrderTakeProfit(),0,Red);
               }
            }
         }
      }
   }
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 外汇EA编程中移动止损功能的实现
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏