Volume moving average

 

I need help to write a code that calculate the moving average of volumes.

I know how to apply an MA to volumes on a chart, but I would like to do it also in an EA.


If someone has got a code sample that performs that task...


thanks in advance

 
No one knows ?
 
FFLY:


I tried the following code, but it doesn't work, I get a compilation error :


'mavol' - function returns no result



...

double volma= mavol(10);
...


//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void mavol(int periode)
//--------------------------------------------------------------------
{
double buffer[100];
int i,limit=ArraySize(buffer);
ArraySetAsSeries(buffer,true);

for(i=0; i<limit; i++)
buffer[i]=Volume[i];

double ma=iMAOnArray(buffer,limit,periode,0,MODE_SMA,0);
return (ma);
}

 
FFLY wrote >>

I tried the following code, but it doesn't work, I get a compilation error :

'mavol' - function returns no result

...

double volma= mavol(10);
...

//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void mavol(int periode)
//--------------------------------------------------------------------
{
double buffer[100];
int i,limit=ArraySize(buffer);
ArraySetAsSeries(buffer,true);

for(i=0; i<limit; i++)
buffer[i]=Volume[i];

double ma=iMAOnArray(buffer,limit,periode,0,MODE_SMA,0);
return (ma);
}

This appears to work (got a series of double values in the right order of magnitude), but I did not confirm the resulting values:


double Vol[100]; // limit must be <= array size
ArrayInitialize(Vol,0);
int cnt=ArrayCopy(Vol,Volume);
int limit=60;
double vma=iMAOnArray(Vol,limit,limit,0,0,0);

 

Create a Volume_MA indicator, i posted one on the other topic, then use the iCustom() function to call values from the Volume MA indicator. Simple.


extern int VMA_Period=13;
extern int VMA_Method=0;
extern int VMA_Shift=0;

VMA=iCustom(Symbol(),0,"Volume_MA",VMA_Period,VMA_Method,VMA_Shift,MODE_MAIN,0);


should call values from the indicator Volume_MA. dunno if thats what you're after but it seems like the easiest way to get values from a custom indicator into an EA.

Files:
volume_ma.mq4  4 kb
Reason: