I did not analyse your code, but reading the following may help you identify the problem yourself ... Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
The following may also help ...
Forum on trading, automated trading systems and testing trading strategies
Vladimir Karputov, 2021.11.24 16:04
Opening and modifying positions:

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi guys, I'm new to coding in MQL4 and I was looking for some help.
I'm following a course on coding your first MT4 robot and the EA is now fully coded. I've back tested the EA on around 520 trades and for the most part it works fine. I am not going to use the EA nor is it exactly profitable, however I am getting a error code "OrderModify error 130" on around 5 trades throughout the whole 10 year back test and I want to understand why. The EA uses Bollinger bands with various Standard Deviations together with RSI values to determine the Direction, Entry, SL and TP. However, the TP is dynamic in the sense it updates when the Bollinger Band it is calculated from does. It also checks if the TP value is different from the active TP by more than 1pip and only updates to the new one if it is. I've looked into the journal to locate an effected trade and then rerun the back test in visual mode to de bug this issue, and I think I know the cause.
It seems to be happening when the TP tries to update when it is too close to current market price, and therefore throws up an error. After a search on this and many other forums, I understand there is a minimum stop loss level and I've figured my TP is trying to update while in this zone. (Please check my screenshots and inform me if you think otherwise).
I've run a check to see what the minimum stop loss level is for my broker and it returns a value of "0", so I assume incorporating this value into my code would be useless?
What I can't find information on, is firstly what value to use when your broker doesn't specify one (so my TP/SL stays out of this zone), and secondly, how I would incorporate this into my EA? I would appreciate if someone could take the time to explain to me what, where and why I need to incorporate into my code to avoid this issue for future reference and for my own personal development.
Any advice would be greatly appreciated!
(I have commented out the lot size for back testing purposes and replaced it with a set value of 0.01. I have also commented out the print statements that clog up my journal)