In OnDeinit() write your condition - whether or not you need to overwrite your global variables.
In general, I ask again: "What is the algorithm of action?". At the moment it's a heap-mala. Understand that unless you understand what you need, you will not be able to implement it. Draw a flowchart - it will help.
I understand what you need, I wrote above - to save values of variables in case of connection failure or server restart, etc. in case there are open orders. It's just that I'm not a professional programmer, maybe that's why it's hard to understand me... I managed to take data from OnInit() through the cycle of orders availability. I think everything works now: in OnTick() I memorise, and when loading from OnInit(), if there are open positions, the variables are assigned glob.perm values. even in OnDeinit() I did not have to write anything.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
In OnDeinit() write your condition - whether or not you need to overwrite your global variables.
In general, I ask again: "What is the algorithm of action?". At the moment it's a heap-mala. Understand that unless you understand what you need, you will not be able to implement it. Draw a flowchart - it will help.