The code is right... but let me do a question... how can you say that is not working if you are using a future date?
because I had set a return INIT_FAILED and threw it into OnINIT
datetime date = TimeCurrent(); MqlDateTime m_time; TimeToStruct(date,m_time); if(m_time.year >=2020) if(m_time.mon >= 2) if(m_time.day >= 14) { Comment("It failed :("); return INIT_FAILED; }
because I had set a return INIT_FAILED and threw it into OnINIT
I'm not sure that during OnInit the function TimeCurrent() returns a valid time... it return the last valid server time.
You can try to put it into OnTick, using an old date and then try to backtest in a period in which that date is contained.
I'm not sure that during OnInit the function TimeCurrent() returns a valid time... it return the last valid server time.
You can try to put it into OnTick, using an old date and then try to backtest in a period in which that date is contained.
It does I had to run
Comment((string)Timecurrent());
It does I had to run
Comment((string)Timecurrent());
if(m_time.year >=2020) if(m_time.mon >= 2) if(m_time.day >= 14)
This code means that:
the year need to be >= 2020 (it is)
the month need to be >= 2 (it's not)
the day need to be >= 14 (it's not)
This script works, so there is something wrong with the date you are sending to your code.
Creating a separate function allows you to test the function easily, by the way.
Unit test all the things.
#property strict void OnStart() { IsValentinesDay(D'2020.02.14 00:00:00'); } bool IsValentinesDay(const datetime dateTime) { MqlDateTime dt; TimeToStruct(dateTime,dt); PrintFormat("%d.%d.%d", dt.year, dt.mon, dt.day); if ( dt.year == 2020 ) { if ( dt.mon == 2 ) { if ( dt.day == 14 ) { Print("Is Valentine's Day"); return true; } } } return false; }
Good day in Mql4 I can type as follows
now how do I write the above in MQL5.
I tried
But its not working
void OnStart() { MqlDateTime m_time; TimeToStruct(TimeCurrent(),m_time); if(m_time.mon==1 && m_time.day==10) printf("*** today"); }
To replace with the right month, day & event ; year isn't relevant ...

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good day in Mql4 I can type as follows
now how do I write the above in MQL5.
I tried
But its not working