.

## how to loop multiple quantities once in mt4?

Moderators: mntiwana, mrtools

### 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];
}
``````
1. ### Similar Topics

1. #### MM EA or script for TP multiple orders

0 Replies 520 Views

by amgm2609, Sat Oct 14, 2017 11:26 pm in Coding Help

0 Replies
520 Views
2. #### How to Run Multiple Instances of MetaTrader on the Same Computer

4 Replies 872 Views

by bilbao, Mon Apr 24, 2017 3:14 am in Forex Education

4 Replies
872 Views

### Who is online

Users browsing this forum: modanetfx and 5 guests