Download MetaTrader 5

iMaOnArray and iVolume

To add comments, please log in or register
AhmedMorra
51
AhmedMorra  

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 &&......){
  OrderSend(NULL,OP_BUY,.....);
  }
whroeder1
15934
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]?
AhmedMorra
51
AhmedMorra  
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 ?

whroeder1
15934
whroeder1  
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 ?

  1. for( int i=0;i<21;i++)
            vol[i]=iVolume(NULL,0,i);
  2. Obviously you need additional values to compute a EMA(21,2).
AhmedMorra
51
AhmedMorra  
whroeder1:
  1. 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);
whroeder1
15934
whroeder1  
There are no mind readers here
if(volc > volp && volc > _iVolc && volp > _iVolp &&......){
  OrderSend(NULL,OP_BUY,.....);
  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.
AhmedMorra
51
AhmedMorra  
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]){
  OrderSend(NULL,OP_BUY,.01,Ask,3,Low[1],Ask+(Ask-Low[1]),NULL);
  }
  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];
  }
   
   
   
  }
whroeder1
15934
whroeder1  
AhmedMorra: I am Sorry, here is the whole code for the ea
  1. I suggested you check your return code, you ignored it. We're not going to debug your code for you.
  2. I suggested you print your variables, you ignored it. We're not going to debug your code for you.
To add comments, please log in or register