最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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);
                    }
                 }
              }

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论