How do I carry variables from one tick to the next?

 

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!

 
spinner461:

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?

 
spinner461:

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.

Reason: