failed cancel order due to Invalid stops? (solved)

 

Hi everyone,

I hope you are fine. I am having a hard time with the following error. I get an error cancelling an already placed pending order due to invalid stops....

 2016.05.12 06:00:00   failed cancel order #226 sell stop 1.20 EURUSD at 1.14209 sl: 1.14462 tp: 1.13653 [Invalid stops]

Why am I getting an error cancelling a pending order? If the order is not placed, how can any of the stops be of any relevance?

I would appreciate any tips.

Many thanks.

 

Solved it with this check function, before any order modification.


/**
* Checks if an order can be modified from its existing type, open price, sl and tp.
*
* @param    int      type  order type
* @param    double   open  order open price
* @param    double   sl    stoploss price
* @param    double   tp    take profit price

* @return bool
*/
bool ModificationValid(int type, double open, double sl, double tp)
{
   // Read spread and stoplevel
   double stoplevel = getStopLevelInPrice();
   double spread    = (Ask - Bid);
   double mktprice  = 0;
   
   // Find out which price should be used
   if(type == OP_BUY || type == OP_BUYLIMIT || type == OP_BUYSTOP) mktprice = Bid;
   if(type == OP_SELL || type == OP_SELLLIMIT || type == OP_SELLSTOP) mktprice = Ask;
  
   // Get minimum difference
   double mindif = MathMin(MathAbs(mktprice - sl),MathMin(MathAbs(mktprice - tp),MathAbs(mktprice - open)));
  
   // Find out if valid
   if(mindif > stoplevel+1*Point)
      return(true);
  
   // Invalid
   return(false);
}

double getStopLevelInPrice()
{
   double s=MathMax(MarketInfo(Symbol(),MODE_FREEZELEVEL),MarketInfo(Symbol(),MODE_STOPLEVEL));
   return(s*Point);
}

 
Arturo Lopez Perez #:

Solved it with this check function, before any order modification.


/**
* Checks if an order can be modified from its existing type, open price, sl and tp.
*
* @param    int      type  order type
* @param    double   open  order open price
* @param    double   sl    stoploss price
* @param    double   tp    take profit price

* @return bool
*/
bool ModificationValid(int type, double open, double sl, double tp)
{
   // Read spread and stoplevel
   double stoplevel = getStopLevelInPrice();
   double spread    = (Ask - Bid);
   double mktprice  = 0;
   
   // Find out which price should be used
   if(type == OP_BUY || type == OP_BUYLIMIT || type == OP_BUYSTOP) mktprice = Bid;
   if(type == OP_SELL || type == OP_SELLLIMIT || type == OP_SELLSTOP) mktprice = Ask;
  
   // Get minimum difference
   double mindif = MathMin(MathAbs(mktprice - sl),MathMin(MathAbs(mktprice - tp),MathAbs(mktprice - open)));
  
   // Find out if valid
   if(mindif > stoplevel+1*Point)
      return(true);
  
   // Invalid
   return(false);
}

double getStopLevelInPrice()
{
   double s=MathMax(MarketInfo(Symbol(),MODE_FREEZELEVEL),MarketInfo(Symbol(),MODE_STOPLEVEL));
   return(s*Point);
}

For the same issue it's not working.
 
  1. Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2.    double s=MathMax(MarketInfo(Symbol(),MODE_FREEZELEVEL),MarketInfo(Symbol(),MODE_STOPLEVEL));

    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 (the broker doesn't know). Use a minimum of two (2) PIPs.

    The checks a trading robot must pass before publication in the Market - MQL5 Articles (2016)

 
William Roeder #:
  1. Please edit your post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. 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 (the broker doesn't know). Use a minimum of two (2) PIPs.

    The checks a trading robot must pass before publication in the Market - MQL5 Articles (2016)

Same Issue Here.
I don't understand that
How Can I get an error while deleting the pending order?

 
Kailash Bai Mina #: How Can I get an error while deleting the pending order?

The market was too close to the open price. The order was about to open.

There is no need to create pending orders in code.
  1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
  2. Don't worry about it unless you're scalping M1 or trading news.
  3. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
 
William Roeder #:

The market was too close to the open price. The order was about to open.

There is no need to create pending orders in code.
  1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
  2. Don't worry about it unless you're scalping M1 or trading news.
  3. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
We really can't close pending little before it was closed.
I didn't knew that.


I was working on a order.
It has 11000 lines code.

I don't think i can replace all the logic and open market order in such a big chunk of code(at least not untill he increases the budget to idk 500-1000$)

Is it possible that i create my own custom pending orders like instead of opening stop/limit order, i will store all the data in a array or struct maybe and i will open a market order when price reaches there?

Is it feasible?
 
Kailash Bai Mina #:
We really can't close pending little before it was closed.
I didn't knew that.


I was working on a order.
It has 11000 lines code.

I don't think i can replace all the logic and open market order in such a big chunk of code(at least not untill he increases the budget to idk 500-1000$)

Is it possible that i create my own custom pending orders like instead of opening stop/limit order, i will store all the data in a array or struct maybe and i will open a market order when price reaches there?

Is it feasible?

Don't waste your time. William's opinion about pending orders is just an opinion. Mine is there is no problem and some advantages to use pending orders (they are at the server side for execution).

You just need to deal with the settings of your broker. You can also consider to use a broker which doesn't put limit on working with orders (pending or not).

 

Hi! I´m getting invalid stops error when cancelling a pending sell order" in validation proces.  Once the market is far from sell order (price=1.211850 Order=1.20930 ,diff = 265 points) I didn´t understood why this is happening.

Its is a pending order with expiration time and the EA is eventualy trading news:

trade.SellStop(lots,entry,_Symbol,sl,tp,ORDER_TIME_SPECIFIED,expiration,"selStop sc");
Validation proces :
test on EURUSD,H1 (hedging)

2021.06.15 05:00:10 failed cancel order #245 sell stop 2.35 EURUSD at 1.20930 sl: 1.21086 tp: 1.20710 [Invalid stops] 2021.06.15 05:00:10 failed cancel order #245 sell stop 2.35 EURUSD at 1.20930 sl: 1.21086 tp: 1.20710 [Invalid stops] 2021.06.15 17:00:10 failed cancel order #251 sell stop 2.35 EURUSD at 1.20930 sl: 1.21086 tp: 1.20710 [Invalid stops] 2021.06.15 17:00:10 failed cancel order #251 sell stop 2.35 EURUSD at 1.20930 sl: 1.21086 tp: 1.20710 [Invalid stops] strategy tester report 75 total trades

Journal:

>   CTrade::OrderSend: sell stop 1.92 EURUSD at 1.20931 sl: 1.21087 tp: 1.20711 [done]
....

2021.06.15 05:00:00   DEBUG: EURUSD: bid=1.211850 ask=1.211860 FreezeLevel:0  StopLevel:0  MAX: 0