Modification denied because order too close to market (145)
-
Hello,
Closing trade #**** error: Modification denied because order too close to market (145)
I am being constantly plagued with the above error during back testing.
I have a simple EA that places an order with a Stop Loss of 20 Pips (200 points) and no Take Profit.
The order is closed when the current candle closes.
The error appears to be occurring when the candle Close and Stop Loss are very close/the same.
The problem appears to coincide with a move from FXCM to GKFX.
I would welcome any suggestions. Once the error occurs it goes into a loop.
Regards
Paul -
Well, this error comes frm the broker and I believe that it's description tells the reason. Where are some limits and when you are too close, modification can't happen. The EA will try to do it for few times anyway and it should quit trying after a while. If someone thinks that it's better to just skip this error or don't even try to do the modification, I can program it like this.
-
Hello,
When back-testing I found that the EA would loop indefinitely.
To get around the problem I made use of the Pips away from stop-loss block.
The EA no longer attempts to close a trade on Candle Close if the Closing Price is 10 points or closer to the initial Stop Loss.
I am not sure how "modification" is defined, but if the modification is Closing a trade, perhaps the error could be skipped, but I am no expert in this area.
-
This error is not included in the loops that I am thinking about. Can you give me an EA that produces this error?
-
I also ran into this error but would not be able to reproduce it at this point. My solution implemented now is to track the highest BID (for buys) and the lowest ASK (for sells) in variables filled in per tick. I then check for when the current bid/ask (depending) is more than nn pips away from the high-bid/low-ask current price after a turn. Again, this is on a per-tick basis. It takes a few blocks of logic but it works no matter how close the price is to the preferred stop-loss or take-profit position.
Also, there is no additional repeated action needed in the logic. In other words, I do not have to have the program keep moving the stop-loss/take-profit points through requests to the broker.
Plus, I would prefer to hide my exit points from the broker in any case.
-
When you keep data in variables, also keep in mind that when you restart the EA it will be gone.
If stops are hard, then the broker is responsible to work with them correctly. I think that it's better this way. Otherwise... you know, errors happen out of nothing.
-
Great point!
I agree that you need protection in case of a system failure (computer stops, network drops, etc.) so I open each trade with a fixed stop-loss in place.
-
For MT4 you can use Virtual stops by the way. Somewhere in the projects setting you can enable these. They are horizontal lines, but the EA keeps track on them and closes trades when needed. Of course, the EA must work for this to happen. But also you can set Emergency stops along with the Virtual stops, which are hard stops placed somewhere beyond the Virtual stops, just in case something goes wrong.
-
__Well, this error comes frm the broker and I believe that it's description tells the reason. Where are some limits and when you are too close, modification can't happen. The EA will try to do it for few times anyway and it should quit trying after a while. If someone thinks that it's better to just skip this error or don't even try to do the modification, I can program it like this.[/quote:1bjrozop]
Hello,
I would like to resurrect this post as I am experiencing constant problems with back-testing.
-
If a suspected 145 error is encountered during a back-test in Optimization mode, regardless of whether Virtual Stops are used or not, the test goes into an infinite loop if any EA uses Stops. The back-test has to be manually stopped and an 'Optimization stopped due to a fatal error in the EA' Message is created in the Journal.
-
A back-test using the same Inputs outside of Optimization mode will produce a 145 error when Virtual Stops are not used.
-
A back-test using the same Inputs outside of Optimization mode will not necessarily produce a 145 error when Virtual Stops are used. This means that a a test performed with the same Inputs using Virtual Stops can behave differently depending upon whether inside or outside of Optimization mode!
-
With the limited amount of back-testing I have been able to do, results can be significantly different when Virtual Stops are used as opposed to 'Normal' Stops (this would need further testing).
Please note the above error is rare in the sense that it can take thousands of simulated trades before encountering. However, because I back-test over 4 year worth of data I always encounter the error during Optimization mode. Unfortunately, this error is rendering fxDreema unusable for back-testing. The inconsistency of results when using Virtual Stops inside/outside of Optimization mode is also worrying.
I think the above is a strong case to "skip this error or don't even try to do the modification" as I assume this is what would happen in real trading anyway (though I am no expert in this area).
-
-
Well, in real life if modification is denied because order is too close to market, the market will eventually move and the trade will be again free to be modified. Also in case of such errors the EA should try 10 times to do the job and then quit trying.
It's different in the tester, because the tester cannot be in an endless loop waiting for the next tick to come and try again. I must check the code to see how I did it in this case, but obviously it stays in that endless loop for some reason. My question is - is the pending order really that close to the current price?
-
Hello,
I added a 'Pips away from stop-loss' loop to the condition that would close a Sell &/or open a Buy and vice-versa. A Trailing Stop is also active. I then experimented with using an Input of 1 to 30 for the 'Pips away' loop.
I am pleased to report the following:
-
No suspected 145 errors were encountered during back-testing in Optimization mode, regardless of whether Virtual Stops were used or not. Optimization completed successfully for all 'Pips away' Inputs tested.
-
No 145 errors were encountered during back-testing outside of Optimization mode whether Virtual Stops were used or not for all 'Pips away' Inputs tested.
-
Back-tests performed with the same Testing Inputs using Virtual Stops now behave the same whether inside or outside of Optimization mode.
-
Back-test results with Virtual Stops and 'Normal' Stops are now identical.
I assume the above confirms the 145 error was genuine and it stresses the importance of making sure an EA includes a proper work-around for this error to produce 'accurate' back tests results.
-
-
So, now there are no problems

-
__So, now there are no problems
[/quote:6iy2b95s]Yes making use of 'Pips Away' in my EA has stopped the 145 errors and all the strange results I was getting when Optimizing. I now have a much better understanding of this error and the importance of making sure an EA manages the error properly. Because 145 errors can drastically effect back-testing, I would prefer that this error was managed by fxDreema directly, assuming that would be more efficient than my work-around.
-
I will try to produce this error somehow. I really tried to mute all errors, which is something that someone would say that is wrong. But maybe something is missing...
Note that when optimizing, virtual stops are not working, because... https://www.mql5.com/en/articles/1512. The EA should work with normal stops instead (is everything is fine)
-
I was thinking about pending orders the whole time.... I'm used to call the running orders trades and pending orders - orders.
So I have hard times making an EA that produces this error. But I remember that I was thinking that it's good for some errors to appear and even break the Tester. Normally errors mean that something is not correct and needs to be fixed. The Tester is somehow ideal version and if you have errors in the Tester, then thibgs will be worse Live.
Again, I muted many possible errors by make the EAs to do something else or do nothing. For example, if you tell the EA to open a trade with lot size that is outside limits, it will scream an error and that's all. So what I did is to calculate the possible lot size and take it. The problem here is that this calculated lot size is different from the requested, but I assume that everyone will prefer wrong lot size instead of dealing with error messages.
My problem with this 145 error is that I can't produce it

-
__My problem with this 145 error is that I can't produce it :)[/quote:1v1n0xcg]
Hello,
I find it strange that you cannot produce the 145 error as I practically encounter it all the time without the 'Pips Away' loop. But not to worry, my work-around in certainly working with my current EA that I'm working on. If I become stuck again I'll can always get back to you (support has been great). Maybe it is better to keep the 145 error and program the EA accordingly, so there are no surprises in a Live environment.
-
Well, note that you are actually working on the desktop version, which is old. I sometimes do fixes and no one understands, but for the latest months I was only updating the web version