How to get today date ? , even backtest history still know today date.

 

l have tried many code , but still can't find way to get today date.

Example Today = 10-Sep-2017

When l doing backtest on = 1-Jan-2015

How to get today date?


Thank you.

Best regards.

 

An indi, EA or script in mt4 you can get today's date by Time[0] - which is the time-stamp of the most recent bar. During a weekend it is the timestamp of the last bar from Friday!

In the tester Time[0] is the actual time-stamp of the last bar of the pointer of the tester.

Or do you want to know how to compose the date formate a string: 1-Jan-2017?

Use TimeDay(), TimeMonth() (you have to convert:1="Jan",2=..) , TimeYear().

 
Carl Schreiber:

An indi, EA or script in mt4 you can get today's date by Time[0] - which is the time-stamp of the most recent bar. During a weekend it is the timestamp of the last bar from Friday!

In the tester Time[0] is the actual time-stamp of the last bar of the pointer of the tester.

Or do you want to know how to compose the date formate a string: 1-Jan-2017?

Use TimeDay(), TimeMonth() (you have to convert:1="Jan",2=..) , TimeYear().


That method got time from last candle on backtest , not get today date.

but thanks , l want to get real today date ,like check from broker.

Regards

 
Siwakon Poonsawat: That method got time from last candle on backtest , not get today date. but thanks , l want to get real today date ,like check from broker. Regards

Your questions is confusing and unclear!

During testing in the Strategy TesterTimeLocal() is always equal to TimeCurrent() simulated server time.

TimeCurrent - Date and Time - MQL4 Reference
TimeCurrent - Date and Time - MQL4 Reference
  • docs.mql4.com
TimeCurrent - Date and Time - MQL4 Reference
 

Can't be done, except using DLL/Windows call.

During testing in the Strategy Tester, TimeGMT() is always equal to TimeCurrent() simulated server time.
          TimeGMT - Date and Time - MQL4 Reference
During testing in the Strategy Tester, TimeLocal() is always equal to TimeCurrent() simulated server time.
          TimeLocal - Date and Time - MQL4 Reference
 


Not work. 


Tested TimeCurrent() and  Time[0] no way to get real today date.

 
whroeder1:

Can't be done.


it can be done)

 
Taras Slobodyanik:

it can be done)


Excuse me how to do that?

Thank you.

 

Siwakon Poonsawat:

  1. Not work. Tested TimeCurrent() and  Time[0] no way to get real today date.
  2. Excuse me how to do that?
  1. As already stated TimeCurrent() and Time[0] returns Broker Time, not Local time and also during testing in the Strategy TesterTimeLocal() is always equal to TimeCurrent() simulated server time.
  2. However, you can use Win32 API functions ( eg. GetSystemTime() ) to get the real current local time, circumventing the limitations of the Strategy Tester.
    EDIT: See the following related posts:
Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
  • docs.mql4.com
Operation of Programs in the Strategy Tester - MQL4 programs - MQL4 Reference
 
You can get current local time without DLL. But since you're asking about broker time - this is not possible.
 
Stanislav Korotky: You can get current local time without DLL. But since you're asking about broker time - this is not possible.

OP wants to get local time while using the Strategy Tester, hence why the Win32 API suggestion.

Obviously, when not using the Strategy Tester, but on a Live chart, you don't need to use the Win32 API.

Reason: