If you calculate the stops correctly in the first place you won't invalid stops errors. https://book.mql4.com/appendix/limits
I wanted my AddStopProfit() below to keep attempting to adjust the stop till it becomes valid. But it doesn't seem to do that. I suspect it is because a new tick comes in before the for() loop is able to make enough adjustments.
When you get an error 130 this is what you should do . . .
"The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed."
. . . from here: Trading errors
So wait for 5 seconds, make one new attempt, then fix your code.
When you get an error 130 this is what you should do . . .
"The attempt can be repeated only if the error occurred due to the price obsolescense. After 5-second (or more) delay, it is necessary to refresh data using the RefreshRates function and make a retry. If the error does not disappear, all attempts to trade must be stopped, the program logic must be changed."
. . . from here: Trading errors
So wait for 5 seconds, make one new attempt, then fix your code.
Thanks. I did exactly what you and SDC said; I fixed my code. Now my EA seems to always manage to set stops.
Thanks. I did exactly what you and SDC said; I fixed my code. Now my EA seems to always manage to set stops.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I wanted my AddStopProfit() below to keep attempting to adjust the stop till it becomes valid. But it doesn't seem to do that. I suspect it is because a new tick comes in before the for() loop is able to make enough adjustments.
I would be grateful for any ideas about what is going wrong.