Variable Variables

 

How do you make a variable variable in mql4

ie.

int count=0;

count++;

double calc = high*var{count};

Where var variable would be var1
 
bonechair:

How do you make a variable variable in mql4

ie.

Do you mean an array ?
 

No a variable like

int r1, r2, r3

but I want to add the number to the variable later like

r{count}

 
bonechair:

No a variable like

int r1, r2, r3

but I want to add the number to the variable later like

r{count}

I see, no you can't . . . use an array.
 
Use an array
int r1, r2, r3
int r[4]; r[1] = r1; r[2] = r2; r[3] = r3;
int n=2;
Print("r[",n,"]=",r[n]);
Or use a function
int r1, r2, r3
int n=2;
Print("r[",n,"]=", SelectI(n, r1, r2, r3);
////
int SelectI(int n, int v1, int v2=0, int v3=0, int v4=0, int v5=0, int v6=0, int v7=0, int v8=0, int v9=0, int v10=0,
               int v11=0, int v12=0, int v13=0, int v14=0, int v15=0, int v16=0, int v17=0, int v18=0, int v19=0){
   switch(n){
   case 1: return(v1);
   case 2: return(v2);
   :
}  }
 

I cant use an array, its extern int and it cant be an array.

I can go long way and use switch then with your function thanks.

 

suggestion...

maybe you can use an object and read the value of that object

if you change the objectvalue inside your EA it might be possible to change ..... var{count}??

 
bonechair: I cant use an array, its extern int and it cant be an array.
Wrong. Just copy the externals to a global array during init()
 
I did try that but said some error to me so I ended up using switch but I would have loved a simpler solution.
 
You likely tried arr[] = { R1, R2, R3 } which does NOT compile. that form can ONLY be used with constants. See my previous post