Strategy Tester Error 145 on SAR detection WTF

 
Phy!!!!! what's up with this,
The EA is a year old and undergoing some optimization. As a result I was running some of my old exit criteria and when I hit a SAR and try to close order I get the ERROR 145. No problem with this the while loop takes care of the requote

BUT NO

This is the strategy tester. How can there be a lock out do to freeze level or stoplevel this is a simple market order

phy wrote >>

https://docs.mql4.com/trading/errors

Metaquotes gives the dealers nasty little tools to prevent you from setting orders where you want,
apparently they can also lock in a previous order when price gets close enough to it that it "might" be executed.

See also MarketInfo() MODE_STOPLEVEL and MODE_FREEZELEVEL

You are probably running into the "freeze level" setting at your friendly Dealer.

"Modifying has been denied since the order is too close to market and locked for possible soon execution.
The data can be refreshed after more than 15 seconds using the RefreshRates function, and a retry can be made."

The current order is a profitable type OP_BUY. the status of order at time of close is


16:20:05 2010.02.23 06:08 EURUSD,H4: DEBUG_PROGRAM: SAR Reversal _HEADFAKE 1.3589
16:20:05 2010.02.23 06:08 EURUSD,H4: OrderClose error 145
16:20:05 2010.02.23 06:08 stdlib EURUSD,H4: loaded successfully
16:20:05 2010.02.23 06:08 EURUSD,H4: DEBUG_PROGRAM: bid ask price type 1.3589 1.3592 1.3589 0
16:20:05 2010.02.23 06:08 EURUSD,H4: ERROR: Terminal(): Take Profit Error: 145 Description: modification denied because order too close to market


The order type is 0 OP_BUY

so we use bid as 1.3589, which is the close price as

while (closingProfit) {
RefreshRates();
switch (orderType) {
case OP_BUY:
closePrice = Bid;
break;
case OP_SELL:
closePrice = Ask;
break;
}
if (OrderClose(ticket, _lots, NormalizeDouble(closePrice,Digits), maxSlippage, _arrow)) {
o
o
o


Is this a corner case bug in the strategy tester
 
You should verify that this is not a bug in your code:

Add code to print MarketInfo(symbol, MODE_FREEZELEVEL) and current price when this error occurs. Make sure the attempt to delete/close/modify order is not within freezelevel - depending on the type of order, it should comply with the limitations: https://book.mql4.com/appendix/limits.
 
In addition to freezelevel there is stoplevel. I found during test that I can not change/close an order if market is that close to one of the stops. I check for the max of both.
 
WHRoeder:
I found during test that I can not change/close an order if market is that close to one of the stops.

All requirements and limitations are detailed here -> https://book.mql4.com/appendix/limits.

 
I am aware of the freezelevel and the stoplevel

But why would this make a difference when we are talking about a market order close

Simple,

Closer examination of the date in question shows a corner case where the Dynamic stop loss (Market Order) happens to coincide with the Order Stop Loss at 1.3588.

Thanks for the unfreeze of the brain
John
 
johnmcglaughlin:
But why would this make a difference when we are talking about a market order close

The link I previously posted specifically states that u can not close market orders if current price is within freezelevel:

Market orders can not be closed if the StopLoss and TakeProfit values violate the FreezLevel parameter requirements.

I agree that the above quote is not very clear on this matter (probably a bad translation from Russian)... So here is another link that says the same: https://docs.mql4.com/constants/marketinfo. I'll quote the relevant part:

MODE_FREEZELEVEL33Order freeze level in points. If the execution price lies within the range defined by the freeze level, the order cannot be modified, cancelled or closed.


Note that if the order in question has no SL/TP then the limitation is irrelevant. So this is NOT a bug.