TimeTradeServer analogue for MT4 - page 3

 
fxsaber:

I can call in and have a look. If there's anything relevant, go ahead.

Well, call it in and take a look. And it's on the case itself.

 
Vitaly Muzichenko:

The code is clear, I got used to Saber's style a long time ago, his codes are minimalist and readable.

He wrote this function at my request, for which I thank him.

Then what does this code have to do with this very branch we're writing in now?

 
Dmitry Fedoseev:

What does this code have to do with the branch we are writing now?

Forum on trading, automated trading systems and strategy testing

TimeTradeServer analogue for MT4

Ihor Herasko, 2019.12.02 19:03

Turn the thought around a bit, please. Started on Saturday. We have TimeCurrent() - Friday 23:59:59. What's next?


 
Vitaly Muzichenko:

и?

 
fxsaber:

Between server and computer time zones.

Where do we get the server's time zone from? That's basically what this whole thread is about. That's exactly what we need to find out.

 
Ihor Herasko:

How do we get the time zone of the server? That's basically what this whole thread is about. That's exactly what we need to know.

Vitaly gave a link to this function. I don't remember what the idea is based on. But I must have checked it when I was writing. Give it a try.

 
That function doesn't work, it can't work properly, unless it's on some special DC.
 
Dmitry Fedoseev:
That function doesn't work, it can't work properly unless it's on some special DC.

It would be good to have playback data.

 
Dmitry Fedoseev:
It doesn't work, it can't work properly unless on some special brokerage company.

It works, tested on 3 different ones. Checked in mt5

It may not be what TC needs, but it may take something from it

#property strict


#define  HOUR 3600
#define  DAY (24 * HOUR)
#define  WEEK 7

void OnTick() {
  Comment(TimeServer() +"\n"+
          TimeServerGMT() +"\n"+
          TimeServerGMTOffset());  
}

//--
MqlDateTime Tm;   

datetime GetBarTime(datetime time, bool NextBar = false,string Symb = NULL, ENUM_TIMEFRAMES TimeFrame = PERIOD_M15) {
 if(Symb == NULL) Symb = _Symbol;
  return(iTime(Symb, TimeFrame, iBarShift(Symb, TimeFrame, time) - (NextBar ? 1 : 0)));
 }
//--
datetime GetTimeDayOfWeek(int Shift = 0, ENUM_DAY_OF_WEEK Day = SUNDAY ) {
 const datetime Res = TimeCurrent() / DAY * DAY;
 TimeToStruct(Res,Tm);
  return(Res - (((WEEK + (Tm.day_of_week - Day)) % WEEK) + Shift * WEEK) * DAY);
 }
// Работает для FOREX-символов, когда M1-история доступна за ближайшую неделю
int TimeServerGMTOffset(void) {
 static string _sym=NULL;
 static int _arr=0;
 if(_sym==NULL) {
  datetime Arr[];
  for(int i=0;i<SymbolsTotal(false);i++) {
   if(StringFind(SymbolName(i,false),"EURUSD",0)>-1) {
    _sym=SymbolName(i,false);
    CopyTime(_sym,PERIOD_M15,1,500,Arr);
    if(SymbolInfoInteger(_sym,SYMBOL_SELECT)==0) SymbolSelect(_sym,true);
    _arr=ArraySize(Arr);
    break;
   }
  }
  if(_sym==NULL) Alert("Not Symbol EURUSD");
 }
 if(_arr<500) {_sym=NULL; return(0);}
 const datetime Sunday = GetTimeDayOfWeek();
  return(((int)MathRound((double)MathMin(Sunday-DAY-GetBarTime(Sunday,false,_sym),Sunday+DAY-GetBarTime(Sunday,true,_sym))/HOUR)-0)*HOUR);
 }
// Работает для FOREX-символов, когда M1-история доступна за ближайшую неделю
datetime TimeServer(void) {
  return(TimeCurrent());
 }
// Серверное время
datetime TimeServerGMT() {
  return(TimeCurrent() + TimeServerGMTOffset()+TimeGMTOffset());
 }
 
Vitaly Muzichenko:

It works, tested on 3 different ones. Checked in mt5

It may not be what the TS needs, but it may take something from it.

It works - I mean it buzzes, but a fridge shouldn't buzz, it should freeze. It's not working properly and you don't have to go far to see that.

Reason: