# iMaOnArray and iVolume

51

i am making an ea that send orders if the volume is above the 21 moving average of the volume

buy when i put my conditions for the order and test nothing happen , 0 trades taken

what is wrong with my code?

```double vol[21];
for( int i=0;i<21;i++)
vol[i]=iVolume(NULL,0,i);
ArraySetAsSeries(vol, true );
double _iVolc = iMAOnArray(vol,21, 1,  0, MODE_EMA, 1);
double _iVolp = iMAOnArray(vol,21, 1,  0, MODE_EMA, 2);
double volc = iVolume(NULL,0,1);
double volp = iVolume(NULL,0,2);

if(volc > volp && volc > _iVolc && volp > _iVolp &&......){
}```
15934

1. Set your array as series, before populating it.
2. How can you compute a EMA(21, 2) when you only have 18 values [20..2]?
51

whroeder1:
1. Set your array as series, before populating it.
2. How can you compute a EMA(21, 2) when you only have 18 values [20..2]?

sorry, i am new to mql4 and programming , what do you mean by populating it?

and the other part should i make it more? like 30 and only calculate 21 ema ?

15934

 AhmedMorra: sorry, i am new to mql4 and programming , what do you mean by populating it?and the other part should i make it more? like 30 and only calculate 21 ema ? ```for( int i=0;i<21;i++)         vol[i]=iVolume(NULL,0,i);``` Obviously you need additional values to compute a EMA(21,2).
51

whroeder1:
 Obviously you need additional values to compute a EMA(21,2).

I made the changes you said but still no order taken i increased the array size to double the amount of moving average and still no trades taken

```double vol[42];
ArraySetAsSeries(vol, true );
for( int i=0;i<42;i++){
vol[i]=iVolume(NULL,0,i);
}
double _iVolc = iMAOnArray(vol,42,21,0,MODE_EMA,1);
double _iVolp = iMAOnArray(vol,42,21,0,MODE_EMA,2);
double volc = iVolume(NULL,0,1);
double volp = iVolume(NULL,0,2);```
15934

There are no mind readers here
```if(volc > volp && volc > _iVolc && volp > _iVolp &&......){
1. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
2. Use the debugger or print out your variables, including _LastError and find out why.
51

whroeder1:
There are no mind readers here
1. Check your return codes and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
2. Use the debugger or print out your variables, including _LastError and find out why.

I am Sorry, here is the whole code for the ea

```datetime Time0 = 0;
void OnTick()
{
//---
if (Time0 != Time[0])
{

double vol[42];
ArraySetAsSeries(vol, true );
for( int i=0;i<42;i++){
vol[i]=iVolume(NULL,0,i);
}
double _iVolc = iMAOnArray(vol,42,21,0,MODE_EMA,1);
double _iVolp = iMAOnArray(vol,42,21,0,MODE_EMA,2);
double volc = iVolume(NULL,0,1);
double volp = iVolume(NULL,0,2);

if(volc > volp && volc > _iVolc && volp > _iVolp && Close[1] > Open[1]){
}
if(volc > volp && volc > _iVolc && volp > _iVolp &&  Close[1] < Open[1]){
OrderSend(NULL,OP_SELL,.01,Bid,3,Low[1],Bid-(High[1]-Bid),NULL);
}

Time0 = Time[0];
}

}```
15934

 AhmedMorra: I am Sorry, here is the whole code for the ea I suggested you check your return code, you ignored it. We're not going to debug your code for you. I suggested you print your variables, you ignored it. We're not going to debug your code for you.