William Roeder: We can get the MQL4 equivalent minute values as follows: PeriodSeconds(TF)/60
Thanks. Yes, that works and looks much neater than my code. I guess it is probably doing something similar, but much easier to use the built in function.
Here is one way. It might not be the best but it gets the job done.
string period_as_string="";
if (_Period==PERIOD_M1){period_as_string="M1";}
if (_Period==PERIOD_M2){period_as_string="M2";}
if (_Period==PERIOD_M3){period_as_string="M3";}
if (_Period==PERIOD_M4){period_as_string="M4";}
if (_Period==PERIOD_M5){period_as_string="M5";}
if (_Period==PERIOD_M6){period_as_string="M6";}
if (_Period==PERIOD_M10){period_as_string="M10";}
if (_Period==PERIOD_M12){period_as_string="M12";}
if (_Period==PERIOD_M15){period_as_string="M15";}
if (_Period==PERIOD_M20){period_as_string="M20";}
if (_Period==PERIOD_M30){period_as_string="M30";}
if (_Period==PERIOD_H1){period_as_string="H1";}
if (_Period==PERIOD_H2){period_as_string="H2";}
if (_Period==PERIOD_H3){period_as_string="H3";}
if (_Period==PERIOD_H4){period_as_string="H4";}
if (_Period==PERIOD_H6){period_as_string="H6";}
if (_Period==PERIOD_H8){period_as_string="H8";}
if (_Period==PERIOD_H12){period_as_string="H12";}
if (_Period==PERIOD_D1){period_as_string="D1";}
if (_Period==PERIOD_W1){period_as_string="W1";}
if (_Period==PERIOD_MN1){period_as_string="MN1";}
There is no point to use the numeric values. Your code doesn't make sense even with MT4.
You probably need PeriodSeconds() function.
1. If there was no point to having the ENUM_TIMEFRAMES match the number of minutes represented in the bars on the chart then why would the developers have thought to do so in the first place.
2. Why not simply explain the reasoning behind the new method? If there is any. Why be rude?
3. I've personally used the fact that the numbers match the number of minutes per bar for multiple projects in MT4 and I wanted to convert them to MT5 so the change made that more difficult.
4. It's great that the developers had the foresight to make a function like Period Seconds but that just adds calculations to something that was simple. On a small scale it wouldn't make a noticeable difference but when back testing on a large scale it would add a significant amount of time to completion.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Never hard code constants. Write self-documenting code.
Not compiled, not tested, just typed.
Not compiled, not tested, just typed.It looks like the bit shift is 14 not 15.
We can get the MQL4 equivalent minute values as follows:
We can get the MQL4 equivalent minute values as follows: PeriodSeconds(TF)/60
Here is one way. It might not be the best but it gets the job done.
There is no point to use the numeric values. Your code doesn't make sense even with MT4.
You probably need PeriodSeconds() function.
1. If there was no point to having the ENUM_TIMEFRAMES match the number of minutes represented in the bars on the chart then why would the developers have thought to do so in the first place.
2. Why not simply explain the reasoning behind the new method? If there is any. Why be rude?
3. I've personally used the fact that the numbers match the number of minutes per bar for multiple projects in MT4 and I wanted to convert them to MT5 so the change made that more difficult.
4. It's great that the developers had the foresight to make a function like Period Seconds but that just adds calculations to something that was simple. On a small scale it wouldn't make a noticeable difference but when back testing on a large scale it would add a significant amount of time to completion.
parse the ENUM variables to integer type. It will take care of any future changes to assigned constant values.
That is all it requires.
It looks like the bit shift is 14 not 15.
We can get the MQL4 equivalent minute values as follows:
Thanks @Jian Chen for the pointer!! I converted it to python to use in my work. And here is the reverse in python:
And a test script:
Giving: