Thanks for the help.
int ENUMSize=5;
void LinesArray(string ENUMDataInput, int ENUMSizeInput)
{
int LinesArray[];
ArrayResize(LinesArray,ENUMSizeInput,ENUMSizeInput);
for (int i=1; i <= ENUMSizeInput; ++i) {
LinesArray[i-1] = StrToInteger( EnumToString(ENUMDataInput(i)) ) ;
}
}
//--- LinesArray should be contains values 20,34,50,100,200
Try reading this thread.
You may decide you want to change your approach, and if not there are some examples in there too.
HTH
Have a read of this thread.
You may decide you want to change your approach, and if not there are some examples in there too.
HTH
Thank you for very fast reply
Hope this approach solve my problem - https://www.mql5.com/en/forum/83666/page4#comment_2855538
enum XXX {x1 = -10, x2 = 0, x3 = 11};
template<typename E>
int EnumToArray(E dummy, int &values[], const int start = INT_MIN, const int stop = INT_MAX)
{
string t = typename(E) + "::";
int length = StringLen(t);
ArrayResize(values, 0);
int count = 0;
for(int i = start; i < stop && !IsStopped(); i++)
{
E e = (E)i;
if(StringCompare(StringSubstr(EnumToString(e), 0, length), t) != 0)
{
ArrayResize(values, count + 1);
values[count++] = i;
}
}
return count;
}
int OnInit()
{
Print("ENUM elements:");
XXX a;
int result[];
int n = EnumToArray(a, result, -100, 100);
Print("Count=", n);
for(int i = 0; i < n; i++)
{
Print(i, " ", EnumToString((XXX)result[i]), "=", result[i]);
}
return 0;
}
//Output ENUM elements:
//Count=3
//0 x1=-10
//1 x2=0
//2 x3=11
//It's important to specify reasonable values for parameters start and stop , because the cycle from minimal to maximal integer value (which is used by default when the parameters are skipped) executes tooooo slow taking into account that string functions are used inside.
What about this way:
double arr[];
..
int OnInit() {
...
ArrayResize(arr,SizeXXX);
...
}
If you change the elements of XXX you are already there to change SizeXXX as well.
Carl Schreiber: What about this way:
enum XXX {x1 = -10, x2 = 0, x3 = 11, SizeXXX=3}; If you change the elements of XXX you are already there to change SizeXXX as well. | This is my approach as well, except:
|
//--- LinesArray should be contains values 20,34,50,100,200
#define MALines_LAST _200
const int MALinesPeriods[] = {20, 34, 50, 100, 200};
int MALines_to_period(MALines e){ return MALinesPeriods[e]; }
MALines period_to_MALines(int p){
for(MALines e = MALines_FIRST; e < MALines_LAST; ++e)
if(p == MALinesPeriods[e]) return e;
}
Note, you should use self-documentating variable names (_50 says nothing.)
The enum constants must be unique, you can't have two _50's. MAperiod_34 would be better.
Leading underscore is for system defined things (e.g. _Symbol) Don't use leading underscores.
finally, why don't use just make the value equal to the name? Then you don't need the conversion functions.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Thanks for the help.
int ENUMSize=5;
void LinesArray(string ENUMDataInput, int ENUMSizeInput)
{
int LinesArray[];
ArrayResize(LinesArray,ENUMSizeInput,ENUMSizeInput);
for (int i=1; i <= ENUMSizeInput; ++i) {
LinesArray[i-1] = StrToInteger( EnumToString(ENUMDataInput(i)) ) ;
}
}
//--- LinesArray should be contains values 20,34,50,100,200