MQL4 - automated forex trading   /  

Forum

getting the true server time

Back to topics list To post a new topic, please log in or register

avatar
5
theimperialone 2006.06.17 14:54 
hi there,

I have a little problem.

my indicator uses the call curtime() to get the server time and also uses LocalTime() to get my time.
 
TimeDifference = CurTime() - LocalTime();

My intention is to use these together to work out the start of the day from my perspective.

Now it works perfectly when the markets are open but when they are closed it does not because CurTime() returns the time of the last tick.

Now I can see two possible solutions to this:

1. is there another call i can make to get the real time of the server? For example. ...

 
TimeDifference = GenuineServerTime() - LocalTime();

2. can i test to see if the market is open. If it is then use curtime and store off the difference in a GLobal varibale for later reuse if the market is not open:

if (MarketIsOpen())
{
  
  TimeDifference = CurTime() - LocalTime();
  GlobalVariableSet("TimeDifference",TimeDifference ) 
}
else
{
  TimeDifference = GlobalVariableGet("TimeDifference");
}


Can anyone help me fill in the missing links for either option for me or come up with another suggestion.

thanks
TheImperial1
Object Approach in MQL

Object Approach in MQL

This article will be interesting first of all for programmers both beginners and professionals working in MQL environment. Also it would be useful if this article were read by MQL environment developers and ideologists, because questions that are analyzed here may become projects for future implementation of MetaTrader and MQL.


avatar
Moderator
2824
Tatyana 2006.06.28 16:00 
You can try to use the MODE_TRADEALLOWED identifier from the MarketInfo() function.

avatar
45
hyperdimension 2012.01.17 17:45 
Tatyana:
You can try to use the MODE_TRADEALLOWED identifier from the MarketInfo() function.
MODE_TRADEALLOWED is basically useless, as it's always 1 even during the weekend.

avatar
4328
WHRoeder 2012.01.17 18:25 
theimperialone:

Now it works perfectly when the markets are open but when they are closed it does not because CurTime() returns the time of the last tick.
  1. CurTime is deprecated, use TimeCurrent()
  2. If the market is close, there are no ticks, so start isn't called and you're EA doesn't care.

avatar
4224
RaptorUK 2012.01.17 18:28 
WHRoeder:
  1. CurTime is deprecated, use TimeCurrent()
That's what can happen when someone dredges up a 5 1/2 year old thread ;-)
Back to topics list  

To add comments, please log in or register