failed cancel order due to Invalid stops? (solved)

To add comments, please log in or register
Arturo Lopez Perez
Arturo Lopez Perez  

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.

Arturo Lopez Perez
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)
   // Invalid

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

To add comments, please log in or register