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).

Reason: