MT5: PositionModify() Fails with Error 4756 While Trying to Move SL to Breakeven on Hedge Trade

 

Hi all,

I'm trying to build a hedge-based EA where:

  • A manual trade is opened (BUY/SELL)

  • If the trade goes into 2-point loss, a hedge trade is opened in the opposite direction

  • Once the hedge trade gains 3+ points, I try to move the hedge trade’s SL to breakeven

  • I am using trade.PositionModify(...) to move SL = entry + stoplevel padding

I am repeatedly getting:

❌ SL-to-BE retry failed. Error: 4756

Even after waiting for a 3+ point move in favor, and retrying the modification on every tick, the error persists — until TP is hit and the trade closes.


Here is the core SL-to-BE logic I’m using:

if (!hedgeSLMovedToBE)

{

   double slCandidate = (hedgeDir == POSITION_TYPE_BUY)

                        ? NormalizeDouble(hedgeEntry + stops, digits)

                        : NormalizeDouble(hedgeEntry - stops, digits);


   double gap = MathAbs(currentPrice - slCandidate);


   if (gap >= stops + (_Point * 1))  // extra 1 pip padding

   {

      if (trade.PositionModify(_Symbol, slCandidate, tp))

         hedgeSLMovedToBE = true;

      else

         Print("❌ SL-to-BE retry failed. Error: ", GetLastError());

   }

}

My Questions:

  1. Why does MT5 still reject the SL modification even when I wait for +3 point movement?

  2. Is the SYMBOL_TRADE_STOPS_LEVEL applied against current price or entry price?

  3. Is there a better/official method to move SL to BE for running positions without triggering Error 4756?

Thanks in advance!



 

Placing SL and TP has its own restrictions defined by your broker. The below code has all the necessary checks:

bool CheckStopLoss_Takeprofit(ENUM_ORDER_TYPE type,double SL,double TP)
  {
//--- get the SYMBOL_TRADE_STOPS_LEVEL level
   int stops_level=(int)SymbolInfoInteger(_Symbol,SYMBOL_TRADE_STOPS_LEVEL);
   if(stops_level!=0)
     {
      PrintFormat("SYMBOL_TRADE_STOPS_LEVEL=%d: StopLoss and TakeProfit must"+
                  " not be nearer than %d points from the closing price",stops_level,stops_level);
     }
//---
   bool SL_check=false,TP_check=false;
//--- check only two order types
   switch(type)
     {
      //--- Buy operation
      case  ORDER_TYPE_BUY:
        {
         //--- check the StopLoss
         SL_check=(Bid-SL>stops_level*_Point);
         if(!SL_check)
            PrintFormat("For order %s StopLoss=%.5f must be less than %.5f"+
                        " (Bid=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d points)",
                        EnumToString(type),SL,Bid-stops_level*_Point,Bid,stops_level);
         //--- check the TakeProfit
         TP_check=(TP-Bid>stops_level*_Point);
         if(!TP_check)
            PrintFormat("For order %s TakeProfit=%.5f must be greater than %.5f"+
                        " (Bid=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d points)",
                        EnumToString(type),TP,Bid+stops_level*_Point,Bid,stops_level);
         //--- return the result of checking
         return(SL_check&&TP_check);
        }
      //--- Sell operation
      case  ORDER_TYPE_SELL:
        {
         //--- check the StopLoss
         SL_check=(SL-Ask>stops_level*_Point);
         if(!SL_check)
            PrintFormat("For order %s StopLoss=%.5f must be greater than %.5f "+
                        " (Ask=%.5f + SYMBOL_TRADE_STOPS_LEVEL=%d points)",
                        EnumToString(type),SL,Ask+stops_level*_Point,Ask,stops_level);
         //--- check the TakeProfit
         TP_check=(Ask-TP>stops_level*_Point);
         if(!TP_check)
            PrintFormat("For order %s TakeProfit=%.5f must be less than %.5f "+
                        " (Ask=%.5f - SYMBOL_TRADE_STOPS_LEVEL=%d points)",
                        EnumToString(type),TP,Ask-stops_level*_Point,Ask,stops_level);
         //--- return the result of checking
         return(TP_check&&SL_check);
        }
      break;
     }
//--- a slightly different function is required for pending orders
   return false;
  }
 
نريد مساعده

 
This error code is about the Invalid SL. You may have to check the Stop Level of the pair from your broker. I normally choose to trade with zero stop level.