iVolumes average value

 

Hello, 

How could I return the average value of x periods from volume indicator?

I tried to use the code below, but it is not working properly also.


input ENUM_TIMEFRAMES VOL_TF=PERIOD_M30;
input ENUM_APPLIED_VOLUME VOL_TYPE=VOLUME_REAL;


double vol_filter()
   {
    double volumes = iVolumes(_Symbol,VOL_TF,VOL_TYPE);
    double vol_buffer[],vol_res;
      if(CopyBuffer( volumes ,0,0,1, vol_buffer )>0)
         {
          vol_res=vol_buffer[0];
          return(vol_res);
         }
      return(0);

   }
  
 
Guilherme Mendonca: How could I return the average value of x periods from volume indicator?
  1. iVolumes returns an int (handle) not a double.

  2. Where do you get multiple values from CopyBuffer and where do you average them?
 
whroeder1:
  1. iVolumes returns an int (handle) not a double.

  2. Where do you get multiple values from CopyBuffer and where do you average them?


Thank you for your answer.

I'm really dont know. I tried to used some code that I was used to get iATR value, but did not worked to iVolumes.

Even when I try just to get a unique value from one TimeFrame of iVolumes, it returns a wrong value.

Do you have any sugestion of a code which returns the average of volumes value?

 
Guilherme Mendonca:


...

Do you have any sugestion of a code which returns the average of volumes value?

Do you know you don't need any code for that ?

MetaTrader Trading Platform Screenshots

EURUSD, H1, 2017.08.29

Alpari International Limited, MetaTrader 5, Demo

Volumes averaged by MA indicator. Not coding needed.

EURUSD, H1, 2017.08.29, Alpari International Limited, MetaTrader 5, Demo

Place Volumes indicator on chart, then drag MA indicator in the sub-window and chose Apply to "First indicator's data".
 
Alain Verleyen:

Do you know you don't need any code for that ?

Place Volumes indicator on chart, then drag MA indicator in the sub-window and chose Apply to "First indicator's data".

Hello Alain, 


I know how to do this on chart, but I would like to use this information on my EA to complement as a filter.

I tried this code, but always return 0.


int vol_filter()
   {
    int volumes = iVolumes(_Symbol,PERIOD_M30,VOLUME_REAL);
    double vol_buffer[];
    int result;
    result = CopyBuffer( volumes ,0,0,1, vol_buffer );
    if (result <0)
      return (0);
    else return (result);    
         
         
   }
 
Reason: