Chartperiod() or period() value greater than 1 hour quite divergent from minute values. Incl. request table enhancement (mql5 documentation)

 
Can someone explain the logic/rationale behind the chosen values for the period  (H1 - MN1) in MQL5 (red values in table below)?

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.

table

--------


Further... a documentation issue.

Documentation

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:

Chart Timeframes

Where are the values????

I would expect a table like this:

(Chart) Timeframes

 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.

 

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?

Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
All predefined timeframes of charts have unique identifiers. The PERIOD_CURRENT identifier means the current period of a chart, at which a mql5-program is running.
 
Marine: 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.

It returns the enumeration not an int. On the M15 it returns PERIOD_M15. The value of an enumeration is irrevalent.

 

Dear Williaw,

irr

No, wrong. It returns an int.

Chartperiod() returns 15 on a M15 Chart (and NOT the enumeration RERIOD_M15):

M15 chart

Chartperiod() - returns 16385 on a H1 Chart:

H1 Chart


Based on:

//SCRIPT
//+------------------------------------------------------------------+
void OnStart()
  {
   Comment("Chartperiod () : ",ChartPeriod());
  }


Still Irrelevant? I don't think so. No enummeration. Nor the right values. Irrellevant?

 
Marine:

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(
   long  chart_id=0      // Chart ID
   );

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(
   any_enum  value      // any type enumeration value
   );

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.

 
Or write a specific enumeration to string 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.
 
Marine: It looks a bit complicated to get a useful part out of the ENUM-type functions.

Why do you think you need to get things out? Just include and call the function.

 

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?


Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
Documentation on MQL5: Constants, Enumerations and Structures / Chart Constants / Chart Timeframes
  • www.mql5.com
Chart Timeframes - Chart Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
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.

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.

New MetaTrader 5 platform build 3490: Mobile Web Terminal version and new matrix methods in MQL5 - MetaTrader 5 Platform Update - The New Web Terminal with Full Support for Mobile version of the web platform, MML5 and M
New MetaTrader 5 platform build 3490: Mobile Web Terminal version and new matrix methods in MQL5 - MetaTrader 5 Platform Update - The New Web Terminal with Full Support for Mobile version of the web platform, MML5 and M
  • 2022.10.14
  • www.mql5.com
In addition, we have implemented multiple fixes and improvements in all platform components. All new features, fixes and performance improvements are described in detail below. The new web terminal provides full-featured support for mobile devices
Reason: