TimeCurrent() and iTime() bug/problem - page 2

 
RaptorUK:
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.

Yes, this is what I mean.
 
It's an indicator, why do you care what TimeCurrent is. Do your for indicator counted loop and draw on the bars. Don't look at TimeCurrent, don't look at Bid.
 
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.
 

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.

 
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.
 
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.
Now we understand the why. (Why didn't you explain yourself on the OP?) Exactly like my code
      nextAutoUpdate = timeSrv + HR2400;
      if(Srvr_To_UTC_Auto) if(
         IsDllsAllowed()){                            // Complained @ init
         int      srvrToUTC         = LocalTimeToUTC() - TimeCurrent();
         double   nearestHalfHour   = MathRound(srvrToUTC / 1800.);
         Srvr_To_UTC_Hours          = nearestHalfHour / 2.; // Update external
      }

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.

 
Paul_B:
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.

 
cyclops993:

<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 it's a little hard to give specific help and often the best assumption that can be made is that of an error in the code . . . perhaps you should just take over and answer all and any questions and requests for help. That would solve all your issues, then you wouldn't have to have a dig at those who are just trying to help . . .
 
RaptorUK:
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.