How do I go through an enumeration consistently?
int TF(int i) { switch(i) { case 1: return(PERIOD_M1); case 2: return(PERIOD_M5); case 3: return(PERIOD_M15); case 4: return(PERIOD_M30); case 5: return(PERIOD_H1); case 6: return(PERIOD_H4); case 7: return(PERIOD_D1); case 8: return(PERIOD_W1); case 9: return(PERIOD_MN1); } }
This is not possible because the period value is not incremented by one, you have to organise your own enumeration index, like this
- www.mql5.com
There are probably two functions that need to be entered: 1 - returns the number of elements in the enumeration, 2 - returns the element by number...
If only it were that simple. The values are not evenly distributed. Let's say PERIOD_H1 is 60 and the next period PERIOD_H2 is 120.
The point is that enumeration is a predefined thing and all its values can be viewed,
That's why respected sergey1294 advised you to describe the table of conversion into a serial call,
where if value increases by 1, the next enum value in the list will be called.
ENUM_TIMEFRAMES GetPeriodEnumerator(uchar i); Now let's estimate how many enumerations there are and how many Enumerator functions there should be (one for each enumeration).
In general, there is one solution. For each enumeration, write a special Enumerator function. For example, for Timeframes: Now let's estimate how many enumerations there are in total and then how many Enumerator functions there should be (one for each enumeration).
ENUM_TIMEFRAMES GetPeriodEnumerator(uchar i) { switch(i) { case 0 return(PERIOD_M1); case 1 return(PERIOD_M2); case 2 return(PERIOD_M3); case 3 return(PERIOD_M4); case 4 return(PERIOD_M5); case 5 return(PERIOD_M6); case 6 return(PERIOD_M10); case 7 return(PERIOD_M12); case 8 return(PERIOD_M15); case 9 return(PERIOD_M20); case 10 return(PERIOD_M30); case 11 return(PERIOD_H1); case 12 return(PERIOD_H2); case 13 return(PERIOD_H3); case 14 return(PERIOD_H4); case 15 return(PERIOD_H6); case 16 return(PERIOD_H8); case 17 return(PERIOD_H12); case 18 return(PERIOD_D1); case 19 return(PERIOD_W1); case 20 return(PERIOD_MN1); } return(-1); }
There are a total of 21 timeframes in MT5. The final variant will look like this
- www.mql5.com
In general, there are two options for enumeration
First using a function, I forgot to put a colon in my last post
ENUM_TIMEFRAMES GetPeriodEnumerator(uchar i) { switch(i) { case 0: return(PERIOD_M1); case 1: return(PERIOD_M2); case 2: return(PERIOD_M3); case 3: return(PERIOD_M4); case 4: return(PERIOD_M5); case 5: return(PERIOD_M6); case 6: return(PERIOD_M10); case 7: return(PERIOD_M12); case 8: return(PERIOD_M15); case 9: return(PERIOD_M20); case 10: return(PERIOD_M30); case 11: return(PERIOD_H1); case 12: return(PERIOD_H2); case 13: return(PERIOD_H3); case 14: return(PERIOD_H4); case 15: return(PERIOD_H6); case 16: return(PERIOD_H8); case 17: return(PERIOD_H12); case 18: return(PERIOD_D1); case 19: return(PERIOD_W1); case 20: return(PERIOD_MN1); } return(-1); }The second way is using an array
ENUM_TIMEFRAMES GetPeriodEnumerator[21]= { PERIOD_M1, PERIOD_M2, PERIOD_M3, PERIOD_M4, PERIOD_M5, PERIOD_M6, PERIOD_M10, PERIOD_M12, PERIOD_M15, PERIOD_M20, PERIOD_M30, PERIOD_H1, PERIOD_H2, PERIOD_H3, PERIOD_H4, PERIOD_H6, PERIOD_H8, PERIOD_H12, PERIOD_D1, PERIOD_W1, PERIOD_MN1 };
Let's say we have an enumeration. How can we get all possible values of this enumeration one by one, e.g. in a loop?
ENUM_TIMEFRAMES tf1;I.e. tf1++ must sequentially return PERIOD_M1, PERIOD_M2, PERIOD_M5... I think this cannot be done with the language tools.