how could my indicator know the actual server time or if it's a trade day or not?

 

I am working with a indicator need exact information about GMT Time ,Terminal Time and local Time.

and this Indictor neet to work 7 days a week.

About TimeCurrent() the help file write this:

{

The same server time is used to specify the time of bars in the chart. The last known server time is the time of the last change in the price of any of the symbols opened in the Market Watch window. If there is only EURUSD in the Market Watch window, the TimeCurrent() function will return the last price change of EURUSD. Since the Market Watch window, as a rule, displays a considerable number of symbols, the function basically returns the current server time. However, since prices do not change at the weekend, the value returned by the function will be very much different from the actual server time.

}

1. So my indictor need to know the actual server time  searched all the help file I got not solution to this problem.


2. I could solve this problem by a code like this

if (isTradeDay())
{
int TimeOffset=TimeLocal()-TimeCurrent();

//writeFile TimeOffset to TimeOffset.txt

}
else
{
//read TimeOffset.txt
}

bool isTradeDay()
{
// I need help on this function.
}

Any one got a good idea about get actual server time or how to write the isTradeDay function?

 
TimeCurrent()

servertime stops ticking when market closes so it will be at XX:59 all weekend until the first tick arrives.

if you need the time only for EURUSD filter,

datetime time;

OnTick()
 {
  time=TimeCurrent();
 }

this way time only gets updated when a tick arrives for EURUSD, so not for other symbols.

however i am not sure what you are trying to accomplish.

 

What I am tring to got is the time zone of the therminal.

by Function like TimeGMT() , TimeGMTOffset() and TimeLocal() we can get time zone of the local time.

and in the trading day (from monday to sunday) wen can use TimeCurrent() to count the time zone of the terminal.

but if the OnTick() stop the calculation will be wrong. So TimeCurrent is not trustable on this case.

at least not on Saturday and Sunday.I want a way to get the terminal time zone 7 days a week.

FFCal.mq4  writen by  Derk Wehler is facing the same question.

his solution is set a extern int OffsetHours in line 204.

see the example in attachment.

Files:
fxcal.mq4  52 kb
 
Marco vd Heijden:

servertime stops ticking when market closes so it will be at XX:59 all weekend until the first tick arrives.

if you need the time only for EURUSD filter,

this way time only gets updated when a tick arrives for EURUSD, so not for other symbols.

however i am not sure what you are trying to accomplish.

 Solve it eventually your comment ring a bell  in my mind.

thanks

this is my code

bool isTradeDay=false,tradeDayIsChecked=false;
datetime timeCur,timeIni;
int timeOffSetHour;

string name;

int OnInit()
  {
   timeIni=TimeCurrent();
   timeOffSetHour=read_TimeOffSetHour();
   Print(timeOffSetHour);
   
   EventSetMillisecondTimer(5000);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool check_TradeDay()
  {
   timeCur=TimeCurrent();
   if(timeCur!=timeIni)
     {
      isTradeDay=true;
      write_TimeOffSetHour();
     }
   else isTradeDay=false;
   tradeDayIsChecked=true;
   return(isTradeDay);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void write_TimeOffSetHour()
  {
   timeOffSetHour=(TimeCurrent()-TimeGMT())/3600;
   name="timeOffSetHour.txt";
   int handle=FileOpen(name,FILE_READ|FILE_WRITE|FILE_TXT,",");
   FileWrite(handle,timeOffSetHour);
   FileClose(handle);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int read_TimeOffSetHour()
  {
   name="timeOffSetHour.txt";
   int handle=FileOpen(name,FILE_READ|FILE_WRITE|FILE_TXT,",");
   int returnValue=(int)FileReadString(handle);
   Print("returnValue",returnValue);
   FileClose(handle);
   return(returnValue);
  }
 
Ma Yuliang:

 Solve it eventually your comment ring a bell  in my mind.

thanks

this is my code:

timeOffSetHour=(TimeCurrent()-TimeGMT())/3600;

You have to round timeOffSetHour as TimeCurrent() might have a lag due to you connection and TimeGMT() is taken from your pc and what if this time isn't absolutely correct as well?

The automated typecast of mt4 seems to take always the integer part and is not mathematically rounding the number.

simplest way (not tried, not checked!):

timeOffSetHour=(int)(TimeCurrent()-TimeGMT()+1800)/3600;
 
calli:

You have to round timeOffSetHour as TimeCurrent() might have a lag due to you connection and TimeGMT() is taken from your pc and what if this time isn't absolutely correct as well?

The automated typecast of mt4 seems to take always the integer part and is not mathematically rounding the number.

simplest way (not tried, not checked!):

I can't get the meaning of your code until I had a error in my code. Thanks a lot ,I add 1800 in it and the error gone.
Reason: