Chartperiod() or period() value greater than 1 hour quite divergent from minute values. Incl. request table enhancement (mql5 documentation)
The enumerations have nothing to do with minutes. (only on MT4)
If you want minutes use PeriodSeconds(e)/60
Dear William,
Thanks for the answer. I saw that workaround later too.
However, my question and my suggestion pointed to something else.
My Question:
What is the explanation (the logic) after the red values in the upper table above?
Chartpriod() gives for a M15 chart the value 15.
Chartpriod() gives for a H1 chart the value 16385.
Not very understandable.
And in addition, the promised is “the function returns one of the ENUM_TIMEFRAMES values”. But that is not what the function does. In stead, it returns a “partly messy bunch” of numbers depending on (promised again) the timeframe of the chart, right?
So, my question stays: does anyone know what those values are supposed to represent. Maybe we can do something with that knowledge.
By the way ... why is this (weird?!?) fact not documented in the MQL5 documentation (see my request here below)?
My request:
So, assuming I'm right, I don’t understand the documentation on this point.
There is stated “the function does return ENUM_TIMEFRAMES values”, referring to the Chart Timeframes table. But the returned values (see upper table above in column 2, those with the red values in it) are not included in the Chart Timeframes table as the returned values.
The request is: to bring this under the attention of the MQL5 developers so that correction of the documentation may take place.
If there is another way, I can do that my self, let me know?

- www.mql5.com
What is the explanation (the logic) after the red values in the upper table above?
Chartpriod() gives for a M15 chart the value 15.
Chartpriod() gives for a H1 chart the value 16385.
It returns the enumeration not an int. On the M15 it returns PERIOD_M15. The value of an enumeration is irrevalent.
Dear Williaw,
No, wrong. It returns an int.
Chartperiod() returns 15 on a M15 Chart (and NOT the enumeration RERIOD_M15):
Chartperiod() - returns 16385 on a H1 Chart:
Based on:
//SCRIPT
//+------------------------------------------------------------------+
void OnStart()
{
Comment("Chartperiod () : ",ChartPeriod());
}
Still Irrelevant? I don't think so. No enummeration. Nor the right values. Irrellevant?
Dear Williaw,
No, wrong. It returns an int.
Chartperiod() returns 15 on a M15 Chart (and NOT the enumeration RERIOD_M15):
Chartperiod() - returns 16385 on a H1 Chart:
Based on:
//SCRIPT
//+------------------------------------------------------------------+
void OnStart()
{
Comment("Chartperiod () : ",ChartPeriod());
}
Still Irrelevant? I don't think so. No enummeration. Nor the right values. Irrellevant?
You are wrong.
ChartPeriod
Returns the timeframe period of specified chart.
ENUM_TIMEFRAMES ChartPeriod( |
Parameters
chart_id=0
[in] Chart ID. 0 means the current chart.
Return Value
The function returns one of the ENUM_TIMEFRAMES values. If chart does not exist, it returns 0.
If you want to use the enum in a comment or print use.
EnumToString
Converting an enumeration value of any type to a text form.
string EnumToString( |
Parameters
value
[in] Any type enumeration value.
Return Value
A string with a text representation of the enumeration. To get the error message call the GetLastError() function.
string as_string(ENUM_TIMEFRAMES aePeriod){ if(aePeriod == PERIOD_CURRENT) aePeriod = ENUM_TIMEFRAMES(_Period); string period_xxx = EnumToString(aePeriod); // PERIOD_XXX return StringSubstr(period_xxx, 7); // XXX } string as_string(ENUM_APPLIED_PRICE aePrice, int anLength=0){ string price_XXX = EnumToString(aePrice); // PRICE_XXX return StringSubstr(price_XXX, 6, anLength); // XXX } string as_string(ENUM_MA_METHOD aeMethod, int anLength=0){ string mode_XXX = EnumToString(aeMethod); // MODE_XXX return StringSubstr(mode_XXX, 5, anLength); // XXX }Again, the specific value is irrevalent.
Dear William,
Thanks for the elaborate answer.
It looks a bit complicated to get a useful part out of the ENUM-type functions.
Something that should be simple, but its far from that.
I will study and try out the examples and will come up with a response.The underlying type of the enumeration type is integer. I was initially confused think that an enumeration was a list of string values similar to an array, however an enumeration is actually a special type, of specific integer values, which will only allow the integers listed in the enum type declaration.
Either they are declared by default:
enum listOfStuff{a, b, c, d, e,};
where a would be automatically assigned = 0 and automatically incremented (b=1, c=2, d=3, e=4)
or they are specifically declared:
enum listofOtherStuff{
a=12, b=15, c=9, d=111, e=42,
};
or you have a mix of both:
enum lastListofStuff{
a=12, b, c, d=20,e,
};
where a=12, b=13, c=14, d=20, e=21
Therefore, when making call to ChartPeriod(), the function returns one of the ENUM_TIMEFRAMES values of type enum, which will have an underlying integer type.
I don't think it's irrelevant, obviously the ENUM_TIMEFRAMES declaration writer went to the trouble to specifically declare PERIOD_H1 = 16385, PERIOD_1W = 32769, etc. I think the question remains relevant, why?

- www.mql5.com
Learn to accept what is and stop dreaming of what might be better. To solve the problem is the better approach than arguing how the world should be.
Write your suggestions for improvements in the threads of the announcements of the recent builds like: https://www.mql5.com/en/forum/434550.

- 2022.10.14
- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
It is now impossible to simply give 1440 (minutes) to an extern variable in mql5 when I mean 1 day (D1).
For (H1 -MN1) I have to make a kind of translationtable to convert to minute values.
--------
Further... a documentation issue.
The last sentence here above refers to the ENUM_TIMEFRAMES values. But in the ENUM_TIMEFRAMES table those promised values (from 2 (2 minutes) to 49153 ( 1 month) are NOT found.
The table looks like:
Where are the values????
I would expect a table like this:
My request is to enhance this table on this point so that the values of ENUM_TIMEFRAMES are present indeed and not only the ID and the Description.