You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I think the issue is that the first time start() is called for an Indicator may not be as a result of a new tick . . . in that case TimeCurrent() will report the incorrect time. I haven't verified this . . .
In this case I would simply ignore the first tick . . . and continue normally from tick 2 onwards.
Paul_B:
I'm plotting certain times on a chart which match to GMT, so it matters a great deal when trying to get the offset between MT4 server time and GMT.
<g> I don't think you're up to speed with the culture of this forum yet. The sequence of responses from moderators and other long-term users of the forum is always "You are doing something wrong" followed by "Why would you want to do that?" when it turns out that you're not doing something wrong.
If I were you, I'd just exit out of calls to start() if IsConnected() is false. Or you could maintain a tick count in a static variable and ignore tick #1, but that would unnecessarily delay startup under normal circumstances.
I'll second RaptorUK's suggestion, for an indicator Ignore the first tick and update all bars on the second.
It's also not completely unexpected. Since Indicator's can not sleep, if a EA loads an indicator in it's init via iCustom, the call can't return a buffer value until the indicator runs its init AND start.
Thanks for the input cyclops993, I have it working currently but what I have doesn't seem like an ideal solution or particularly robust. I'll explore IsConnected() a little further.
I don't think you've got much of a choice. MT4 generates a dummy call to start() in order to make indicators populate on offline charts, and because it more generally wants indicators to (re-)appear on charts as soon as MT4 is loaded, without waiting for a connection to be established.
If you want to increase the certainty that there's a properly established connection and a valid TimeCurrent(), then you can also look for AccountNumber() != 0 and AccountBalance() > 0. Or you could just wait for the second tick, at the cost of multi-second delays on symbols with thin liquidity.
Thanks guys, I'll program the indicator to wait until the second tick is received.
Incidentally, just explored the IsConnected() possibility, but I was still getting the "wrong" TimeCurrent() even when IsConnected() reported as true.
<g> I don't think you're up to speed with the culture of this forum yet. The sequence of responses from moderators and other long-term users of the forum is always "You are doing something wrong" followed by "Why would you want to do that?" when it turns out that you're not doing something wrong.
If I were you, I'd just exit out of calls to start() if IsConnected() is false. Or you could maintain a tick count in a static variable and ignore tick #1, but that would unnecessarily delay startup under normal circumstances.
If a user doesn't provide test code to demonstrate the issue [...]
There was nothing wrong with or missing from the OP. It was clear that Paul_B was assuming, perfectly reasonably from the MT4 documentation, that start() is only called in response to new ticks. (Why he wanted to check TimeCurrent() doesn't make a difference, and isn't actually any of our business.)
Your response was basically a nice version of RTFM, despite the fact that the manual is clearly lacking in this area [which I'll stress is unusual; the quality of the MT4 documentation is pretty good]. Angevoyageur's response was to describe this as a fuss, which seems to be part of a pattern of pathologically sensitive responses to any criticism of MT4 of any kind, however mild. WHRoeder then chipped in with "you don't want to do that", followed by copying and pasting some code which was clearly irrelevant because Paul_B clearly already knew how to calculate a GMT offset.