once is to initialise the variable once on the first reading of algo
I get a slight variation in my results if I use ONCE crossflag=0 at the top versus if I use crossflag=0 on its own. But why should there be a difference? If crossflag=0 at the top of the code, shouldn’t be enough to reset it every time the code runs?
JSParticipant
Senior
“Once Crossflag=0” will only processed once…
“Crossflag=0” will be processed every time…
But isn’t each piece of code only processed once? Why would the top line of crossflag=0 be processed more often?
Mike, the code will be executed from top at each close of a bar. For example, if you receive new bars each one minute (this depends on your Chart setting of the instrument), then each one minute the code executes.
In the example below, this is each 5 minutes.
JSParticipant
Senior
And the “once” statement, in your code, will only be executed once…(only the first time)
Okay, thanks. I think I understand it better now. I can see the benefit of ONCE if I need the instruction to stay static for a number of bars while other variables calculate.
Thanks again for explaining 🙂