TimeTradeServer analogue for MT4 - page 5

 
fxsaber:

How do you reproduce from a drawing?

I think the figure shows it very eloquently:

  1. There is EURUSD.
  2. There is a one-minute history.
  3. There is a server time and GMT time.
  4. You have indicated the TC name.
  5. The difference between them should be 2 but in fact it is 0.
What else do I need? Please let me know and I will do it.
 
fxsaber:

Make such a change and it will plough on. The definition of summer and winter has not been done, someone will do it.

Firstly, it's not 'minus 2' but 'plus 2'. Then for my case it fits.

Second, for a server that has a 4 hour offset from GMT, would you suggest putting 4 instead of 2? Then I don't need function, I just use initially known number and get correct answer. )))

 
Ihor Herasko:

What else do you need? Tell me, I will provide.

The code and name of the trading server that you can connect to by opening a demo through the terminal.

 
Ihor Herasko:

First of all, it's not "minus 2", but "plus 2". Then for my case it fits.

Secondly, for a server which is offset 4 hours from GMT, would you advise to put 4 instead of 2? Then I don't need function, I just use initially known number and get correct answer. )))

You attributed a statement to me that I didn't make and then said it was wrong. You also tried to make a joke about it.

 
Dmitry Fedoseev:

As the OrderSend() function comes across an error "market is closed" (there is some such thing), we stop all trading attempts and wait for the price to change, which will mean that the market has opened.

The idea could certainly help, I would like to know when the market is closed without unnecessary errors. We need to think about it.

 
Maxim Kuznetsov:
We should not look for the last (23:59) minute on the EURUSD, but for the night on gold. Gold trades strictly amsterdam, currencies according to server time. From here find the GMT offset of the server

I'll tell you a terrible secret, not every day can end at 11:59 p.m. :-) And we may not know in advance what time it will end. For example, on pre-holiday days and Fridays.

 
fxsaber:

Make such a change and it will plough on. Didn't do summer and winter definition, someone will do it.

It won't work, on systems where they don't fucking update the system as installed :-) For example there is still the time change from winter to summer in RF. I've encountered such systems...

 
fxsaber:

The code and name of the trading server to which you can connect by opening a demo via the terminal.

Code:https://www.mql5.com/ru/forum/327616/page3#comment_14093858

Login: 12752745

Server: yk2mkat

Server: Alpari-Demo

TimeTradeServer аналог для МТ4
TimeTradeServer аналог для МТ4
  • 2019.12.02
  • www.mql5.com
Интересует решение этой функции под МТ4 TimeTradeServer...
 
fxsaber:

You attributed a statement to me which I did not make and then said it was wrong. And then you tried to make a joke about it.

Weren't you the one who wrote it?

There's no joke about the joke. In the code you submitted, 0 is changed to 2. Exactly as much as I get a discrepancy between the real time and the server's calculated time. That's why I was surprised at this approach: look at the needed discrepancy and put the needed offset instead of 0. There is nothing to laugh at here.

TimeTradeServer аналог для МТ4
TimeTradeServer аналог для МТ4
  • 2019.12.03
  • www.mql5.com
Интересует решение этой функции под МТ4 TimeTradeServer...
 
Ihor Herasko:

Code:https://www.mql5.com/ru/forum/327616/page3#comment_14093858

Login: 12752745

account: yk2mkat

Server: Alpari-Demo

Ihor Herasko:

Weren't you the one who wrote?

About the joke - no joke. In the code you submitted, 0 has been changed to 2. I got the difference between real and estimated server time. That's why I was surprised at this approach: look at the needed discrepancy and put the needed offset instead of 0. There's nothing to laugh about.

The check code

#property strict

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

datetime GetBarTime( const datetime time, const bool NextBar = false, string Symb = NULL, const ENUM_TIMEFRAMES TimeFrame = PERIOD_M1 )
{
  if (Symb == NULL)
    Symb = _Symbol;
    
  return(iTime(Symb, TimeFrame, iBarShift(Symb, TimeFrame, time) - (NextBar ? 1 : 0)));
}

datetime GetTimeDayOfWeek( const int Shift = 0, const ENUM_DAY_OF_WEEK Day = SUNDAY )
{
  const datetime Res = TimeCurrent() / DAY * DAY;
  
  return(Res - (((WEEK + (TimeDayOfWeek(Res) - Day)) % WEEK) + Shift * WEEK) * DAY);
}

// https://www.mql5.com/ru/forum/327616/page4#comment_14098877
// Аналог по серверному времени - https://www.mql5.com/ru/docs/dateandtime/timegmtoffset
// Работает для FOREX-символов, когда M1-история доступна за ближайшую неделю
int TimeServerGMTOffset( const bool SummerTime = false )
{
  const datetime Sunday = GetTimeDayOfWeek();
  
  return(((int)MathRound((double)MathMin(Sunday - DAY - GetBarTime(Sunday), Sunday + DAY - GetBarTime(Sunday, true)) / HOUR) - SummerTime - 2) * HOUR);
}

// Аналог по серверному времени - https://www.mql5.com/ru/docs/dateandtime/timegmt
// Работает для FOREX-символов, когда M1-история доступна за ближайшую неделю
datetime TimeServerGMT( void )
{
  return(TimeCurrent() + TimeServerGMTOffset());
}

#define  PRINT(A) Print(#A + " = " + (string)(A))

// https://www.mql5.com/ru/forum/170953/page8#comment_6940794
void OnStart()
{  
  PRINT(TimeGMT());
  PRINT(TimeServerGMT());  
}


Result on a machine with the same GMT as at Alpari.

2019.12.03 19:28:09.048 Test5-3 EURUSD,M1: TimeServerGMT() = 2019.12.03 17:28:12
2019.12.03 19:28:09.048 Test5-3 EURUSD,M1: TimeGMT() = 2019.12.03 17:28:09


Checked

AccountServer() = AMPGlobalUSA-Demo

It is correct.

Reason: