Hi all,
Inside my OnTick function I need to define a boolean ONLY after opening a trade and then redefine it later after a partial exit is triggered (on a later tick) - I then check this variable once there are open positions to determine if the first partial exit has happened or not, however this causes issues when compiling because the variable is not defined outside of if statement (because I cannot redfine it as an empty variable every tick because I need the value from the previous tick to carry forward)
Has anyone had a similar problem? I hope I have made my issue clear
Thank you in advance!
Why don't you put the variable outside the OnTick function?
Hi all,
Inside my OnTick function I need to define a boolean ONLY after opening a trade and then redefine it later after a partial exit is triggered (on a later tick) - I then check this variable once there are open positions to determine if the first partial exit has happened or not, however this causes issues when compiling because the variable is not defined outside of if statement (because I cannot redfine it as an empty variable every tick because I need the value from the previous tick to carry forward)
Has anyone had a similar problem? I hope I have made my issue clear
Thank you in advance!
you have not given enough description of what you want, however, why dont you use static variable to remember the value from 1 tick to the next? or define it as global var. or use 2 not 1 variable, the static to remember the old value and a temp var in real time calculations, which update the static one, only when you want. But post code or a further description of what you have and what you want it to do.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
Inside my OnTick function I need to define a boolean ONLY after opening a trade and then redefine it later after a partial exit is triggered (on a later tick) - I then check this variable once there are open positions to determine if the first partial exit has happened or not, however this causes issues when compiling because the variable is not defined outside of if statement (because I cannot redfine it as an empty variable every tick because I need the value from the previous tick to carry forward)
Has anyone had a similar problem? I hope I have made my issue clear
Thank you in advance!