But I still think that using OnTimer() isn’t a good idea much in this case.
And there is another problem in the code. Imagine that you start your EA within 3 hours before ending market at Friday. The EA will never close like a gentleman
the solution is to check connection, to make sure terminal is connected to server, then set the timer in OnInit() ?
Also another side question : other event handler functions are not triggered when OnInit is running, right ?
example:
if on the first line in OnInit, I set the millisecond timer ( say to 1 millisecond ), then the timer event function is run with the OnInit ? (probably not, I think)
or when OnInit is running, new tick triggers OnTick handler ?
Good point about Friday. actually was gonna auto-disable EA for the first 12 and last 12 hours of trading week. kinda freaky moments.
but if not using OnTimer, then what ?
I can avoid using a TimeCurrent in Ontimer, but still need the timer event to calculate the passed time.
since i’m not gonna be using OnTick handler. (gonna check for new bar formation on timer event)
Or to not use TimeCurrent(), depends of your needs.
Also another side question : other event handler functions are not triggered when OnInit is running, right ?
No.
example:
if on the first line in OnInit, I set the millisecond timer ( say to 1 millisecond ), then the timer event function is run with the OnInit ? (probably not, I think)
or when OnInit is running, new tick triggers OnTick handler ?
First OnTimer call will be after OnInit() end.
But I agree with Petr, unless you have very good reasons it’s not a good idea to use OnTimer for that. And if you still want to do it, you have pay attention to each details when implementing it (for example, OnInit() is called on each EA settings changed).