how to loop multiple quantities once in mt4?

#1
For some reason I cannot loop over multiple quantities in a single loop.


for example the code line

Code: Select all

for(int i=limit;i>=0;i--)a[i]=Volume[i];


works fine but if I try for two variables

Code: Select all

for(int i=limit;i>=0;i--)a[i]=Volume[i], b[i]=Volume[i];
or

Code: Select all

for(int i=limit;i>=0;i--)a[i]=Volume[i]; b[i]=Volume[i];


it gives a error on looping b. How to solve this issue?


Regards
Know Thy Setup. Know Thyself.


Re: how to loop multiple quantities once in mt4?

#2
you have to use the proper syntax , mql is similar to c/c++ syntax this means for your case that when ever you have multiple statements to be executed you must use brackets "{" <--start block and "}" < ----end of block, in order to be clear where each statement belongs to.
change this :

Code: Select all

for(int i=limit;i>=0;i--)a[i]=Volume[i]; b[i]=Volume[i];
to this

Code: Select all

for(int i=limit;i>=0;i--){
                             a[i]=Volume[i]; 
                             b[i]=Volume[i];
                          }
            
and it will work.
it is a good idea to develop safe habits if you are into programming
one of them is : always write one statement in one line
and a second one : always use brackets even if it is just one line ex:

Code: Select all

for(int i=limit;i>=0;i--){a[i]=Volume[i];}
or even better

Code: Select all

for(int i=limit;i>=0;i--){
               a[i]=Volume[i];
             }
   

Who is online

Users browsing this forum: hannele and 3 guests