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);
}
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);
}
-
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 -
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 TutorialOn 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)
-
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 -
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 TutorialOn 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?
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.- 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.)
- Don't worry about it unless you're scalping M1 or trading news.
- 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.
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.- 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.)
- Don't worry about it unless you're scalping M1 or trading news.
- 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.
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
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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....
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.