I am trying to migrate some of my work to MT5 (from MT4) and struggling with the 'Period Constant'.
I want to pass the current chart information to a routine and return a string containing M1 or M5 or H1 etc to match against other data.
I tried the above and got 0 when I used PERIOD_Current and 16385 when I used PERIOD_H1 - I was expecting 60 when running H1 chart).
Any help appreciated.
No 'int'. No 'double'. No 'ulong'. Only ENUM_TIMEFRAMES enumeration.
Also use Period () - to get the current period as ENUM_TIMEFRAMES enumeration.
- www.mql5.com
No 'int'. No 'double'. No 'ulong'. Only ENUM_TIMEFRAMES enumeration.
Also use Period () - to get the current period as ENUM_TIMEFRAMES enumeration.
Many thanks for swift response. I am really struggling to identify my current chart
(I guess I don't really understand the meaning relevance of ENUM_TIMEFRAMES
and thought them more of a predefined constant)
string strperiod = "start"; if (PERIOD_CURRENT == PERIOD_H1 ) strperiod = strperiod + "\nif (PERIOD_CURRENT == PERIOD_H1 ) is true"; if (PERIOD_CURRENT == Period() ) strperiod = strperiod + "\nif (PERIOD_CURRENT == Period() is true"; if (PERIOD_CURRENT == _Period ) strperiod = strperiod + "\nif (PERIOD_CURRENT == _Period is true"; if (_Period == 60 ) strperiod = strperiod + "\nif (_Period == 60 ) "; if (PERIOD_CURRENT != PERIOD_H1 ) strperiod = strperiod + "\nif (PERIOD_CURRENT != PERIOD_H1 ) is NOT true"; MessageBox(strperiod);
only the last expression provides a response when I run on an H1 Chart
2020.03.27 12:01:32.423 Message if (PERIOD_CURRENT != PERIOD_H1 ) is NOT true taken from EXPERTS window at bottom of Page
How do I identify the Current Chart ? (I want to read values from a File and will be different file for different Charts)
- www.mql5.com
Many thanks for swift response. I am really struggling to identify my current chart
(I guess I don't really understand the meaning relevance of ENUM_TIMEFRAMES
and thought them more of a predefined constant)
only the last expression provides a response when I run on an H1 Chart
2020.03.27 12:01:32.423 Message if (PERIOD_CURRENT != PERIOD_H1 ) is NOT true taken from EXPERTS window at bottom of Page
How do I identify the Current Chart ? (I want to read values from a File and will be different file for different Charts)
Seem to have found the answer by process of elimination
2020.03.27 12:47:37.422 Message if (_Period ==
PERIOD_H1 )
2020.03.27 12:47:37.422 Message if (
Period() == PERIOD_H1 )
2020.03.27 12:47:37.422 Message if
(PERIOD_CURRENT != PERIOD_H1 ) is NOT true
Many thanks as always
string strperiod = "start"; if (PERIOD_CURRENT == PERIOD_H1 ) strperiod = strperiod + "\nif (PERIOD_CURRENT == PERIOD_H1 )"; if (PERIOD_CURRENT == Period() ) strperiod = strperiod + "\nif (PERIOD_CURRENT == Period() )"; if (PERIOD_CURRENT == _Period ) strperiod = strperiod + "\nif (PERIOD_CURRENT == _Period )"; if (_Period == 60 ) strperiod = strperiod + "\nif (_Period == 60 )"; if (_Period == PERIOD_H1 ) strperiod = strperiod + "\nif (_Period == PERIOD_H1 )"; if ( Period() == 60 ) strperiod = strperiod + "\nif ( Period() == 60 )"; if ( Period() == PERIOD_H1 ) strperiod = strperiod + "\nif ( Period() == PERIOD_H1 )"; if (PERIOD_CURRENT != PERIOD_H1 ) strperiod = strperiod + "\nif (PERIOD_CURRENT != PERIOD_H1 ) is NOT true"; MessageBox(strperiod);
string as_string(ENUM_TIMEFRAMES period){ if(period == PERIOD_CURRENT) period = (ENUM_TIMEFRAMES) _Period; string period_xxx = EnumToString(period); // PERIOD_XXX return StringSubstr(period_xxx, 7); // XXX }
Many thanks.
Just what I had been looking for.
& thanks again
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am trying to migrate some of my work to MT5 (from MT4) and struggling with the 'Period Constant'.
I want to pass the current chart information to a routine and return a string containing M1 or M5 or H1 etc to match against other data.
I tried the above and got 0 when I used PERIOD_Current and 16385 when I used PERIOD_H1 - I was expecting 60 when running H1 chart).
Any help appreciated.