How near can I set pending order from current price?

 
How near can I set pending order from current price?

Is there something at symbol properties I can look at for this?

 
SunfireHow near can I set pending order from current price? Is there something at symbol properties I can look at for this?


See if this function can help you:

//+--------------------------------------------------------------------------------------------------------------------+
//| This function checks the minimum distance in points from current closing price for placing stop orders             |
//+--------------------------------------------------------------------------------------------------------------------+
bool CheckStopsLevel(double Price, ENUM_ORDER_TYPE Type)
  {
   //--- Determines last price for current symbol
   double BID = SymbolInfoDouble(Symbol(), SYMBOL_BID);
   double ASK = SymbolInfoDouble(Symbol(), SYMBOL_ASK);

   //--- Get the SYMBOL_TRADE_STOPS_LEVEL level
   ulong StopsLevel = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_STOPS_LEVEL);

   //--- Result of checking 
   bool Check = true;

   //--- Check the order type
   switch(Type)
     {
      //--- BuyStop pending order
      case  ORDER_TYPE_BUY_STOP:
        {
         //--- Check the distance from the current price to the activation price
         Check = ((Price - ASK) > StopsLevel * Point());
         if(!Check)
           {ERRMSG = "The distance from the current price to the order opening price is invalid.";}
        }
      break;
      //--- SellStop pending order
      case  ORDER_TYPE_SELL_STOP:
        {
         //--- Check the distance from the current price to the activation price
         Check = ((BID - Price) > StopsLevel * Point());
         if(!Check)
           {ERRMSG = "The distance from the current price to the order opening price is invalid.";}
        }
      break;
     }

   //--- Verification succeeded
   return(Check);
  }
//+--------------------------------------------------------------------------------------------------------------------+
//| This function checks the distance from opening price to activation price                                           |
//+--------------------------------------------------------------------------------------------------------------------+
bool CheckFreezeLevel(ulong TICKET)
  {
   //--- Determines last price for current symbol
   double BID = SymbolInfoDouble(Symbol(), SYMBOL_BID);
   double ASK = SymbolInfoDouble(Symbol(), SYMBOL_ASK);

   //--- Get the SYMBOL_TRADE_FREEZE_LEVEL level
   ulong FreezeLevel = SymbolInfoInteger(Symbol(), SYMBOL_TRADE_FREEZE_LEVEL);

   //--- Select order for working
   if(!OrderSelect(TICKET))
     {
      //--- Failed to select order
      ERRMSG = StringFormat("Error selecting order to work, ticket ", TICKET);
      return(false);
     }

   //--- Get the order data
   double Price = OrderGetDouble(ORDER_PRICE_OPEN);
   ENUM_ORDER_TYPE Type = (ENUM_ORDER_TYPE) OrderGetInteger(ORDER_TYPE);

   //--- Result of checking 
   bool Check = true;

   //--- Check the order type
   switch(Type)
     {
      //--- BuyStop pending order
      case  ORDER_TYPE_BUY_STOP:
        {
         //--- Check the distance from the opening price to the activation price
         Check = ((Price - ASK) > FreezeLevel * Point());
         if(!Check)
           {ERRMSG = StringFormat("Order %s #%d cannot be modified: Ask-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points ", EnumToString(Type), TICKET, int(((Price - ASK) / Point())), FreezeLevel);}
        }
      break;
      //--- SellStop pending order
      case  ORDER_TYPE_SELL_STOP:
        {
         //--- Check the distance from the opening price to the activation price
         Check = ((BID - Price) > FreezeLevel * Point());
         if(!Check)
           {ERRMSG = StringFormat("Order %s #%d cannot be modified: Bid-Open=%d points < SYMBOL_TRADE_FREEZE_LEVEL=%d points ", EnumToString(Type), TICKET, int(((BID - Price) / Point())), FreezeLevel);}
        }
      break;
     }

   //--- Verification succeeded
   return(Check);
  }
 
Sunfire: How near can I set pending order from current price? Is there something at symbol properties I can look at for this?

You have to verify that your stops and/or pending orders abide by the Stops Level and Freeze Level conditions set by your broker's contract specifications.

Forum on trading, automated trading systems and testing trading strategies

ERROR: Modification failed due to order or position being close to market

William Roeder, 2020.09.23 13:57

You can't move stops (or pending prices) closer to the market than the minimum: MODE_STOPLEVEL * _Point or SymbolInfoInteger(SYMBOL_TRADE_STOPS_LEVEL).
          Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial

On some ECN type brokers the value might be zero (broker doesn't know.) Use a minimum of two (2) PIPs.

 
And make sure your broker has Stop/Freeze level at 0 points. If not. Say bye bye to broker.
Reason: