metatrader4 - This code is getting "Error 0 in StopLoss modify of ticket #3: no error" What could cause that?

I added a check to my trailing stop logic to set it to the MODE_STOPLEVEL if I set it too close. It

I added a check to my trailing stop logic to set it to the MODE_STOPLEVEL if I set it too close. It's giving me the error zero in the title above, but it's actually setting the trailing stop correctly and trailing the position when it moves. Do you see anything in this code that would be a problem?

  for (i = OrdersTotal(); i>=0; i-- )
     if ( OrderSelect(i,SELECT_BY_POS) == true )
        if ( OrderSymbol() == _Symbol )
           if ( Trailing_Stop > 0 ) // if a trailing stop is specified by the user
              {
              if ( OrderType() == OP_BUY )
                 {
                 This_TS = NormalizeDouble(MathMin(Bid-(Trailing_Stop*Pips_Factor),MarketInfo(Symbol(),MODE_STOPLEVEL)),Digits); // calculated TS must not pass STOPLEVEL; use the min for a buy
                 if ( OrderStopLoss() < This_TS ) // if the calculated TS is closer to the price then the current one
                    {
                    retval = OrderModify(OrderTicket(),OrderOpenPrice(),This_TS,OrderTakeProfit(),0,Blue);
                    if ( retval && Write_To_Log == 2 ) WriteToLog(StringConcatenate("Order StopLoss modified successfully to ",OrderStopLoss()));
                    else { err = GetLastError(); Print("Error ",err, " in StopLoss modify of ticket #", OrderTicket(), ": ",ErrorDescription(err)); }
                    //if ( Valid_SL(stoploss,OP_BUY) != stoploss ) WriteToLog("********* Research Valid_SL BUY order modification warning: "+Valid_SL(stoploss,OP_BUY)+"<>"+stoploss);
                    }
                 }
              if ( OrderType() == OP_SELL )
                 {
                 This_TS = NormalizeDouble(MathMax(Ask+(Trailing_Stop*Pips_Factor),MarketInfo(Symbol(),MODE_STOPLEVEL)),Digits); // calculated TS must not pass STOPLEVEL; use the max for a sell
                 if ( OrderStopLoss() > This_TS ) // if the calculated TS is closer to the price then the current one
                    {
                    retval = OrderModify(OrderTicket(),OrderOpenPrice(),This_TS,OrderTakeProfit(),0,Blue);
                    if ( retval && Write_To_Log == 2 ) WriteToLog(StringConcatenate("Order StopLoss modified successfully to ",OrderStopLoss()));
                    else { err = GetLastError(); Print("Error ",err, " in StopLoss modify of ticket #", OrderTicket(), ": ",ErrorDescription(err)); }
                    //if ( Valid_SL(stoploss,OP_SELL) != stoploss ) WriteToLog("********* Research Valid_SL SELL order modification warning: "+Valid_SL(stoploss,OP_SELL)+"<>"+stoploss);
                    }
                 }
              }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744906566a4600292.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信