newbie question - volume indicator

 

Hi there. I like to have the moving average of the volume. I have write this lines of codes but it always get me the moving average of closing price. What is my coding problem? I have copied here the OnInit and OnCalculate  functions only. I have write and compiled the whole indicator correctly. I have even test it on volume indicator and set parameter of my own indicator to "first indicator in the list" but nothing changed.


double         test01Buffer[];

int SmoothHandle,RSIHandle;



int OnInit()

  {



   SetIndexBuffer(0,test01Buffer,INDICATOR_DATA);

   SmoothHandle = iMA(NULL, 0, period, 0, MODE_EMA, VOLUME_REAL);

 

return(INIT_SUCCEEDED);

  }



int OnCalculate (const int rates_total,      // the size of the price[] array

                 const int prev_calculated,  // bars calculated in the previous call

                 const int begin,            // where notional data start from

                 const double& price[]       // data array for calculation

                 )

  {

   int toCount=(int)MathMin(rates_total,rates_total-prev_calculated+1);

  CopyBuffer(SmoothHandle,0,0,toCount,test01Buffer);

  return(rates_total);

  }




 

Why do you try it yourself?

E.g. here in this article: https://www.mql5.com/en/articles/5703 you find a small discussion of several Volume indicators.

And if you search (top right) for volume and click on CodeBase you'll find 80 Pages each with 10 suggestion..

I am quite sure there is what you are trying...

A New Approach to Interpreting Classic and Hidden Divergence. Part II
A New Approach to Interpreting Classic and Hidden Divergence. Part II
  • www.mql5.com
In the first article, we considered a non-standard approach to the interpretation of divergence. We analyzed graphical constructions associated with it and briefly touched on the divergence itself, on divergence recognition quality and its classification. Moreover, the article did not cover filtering of deals traded based on the pattern...
 
thank you dear Carl. I will check this link and find out how I can solve this problem. But anyway is there any problem in my lines of code that it doesn't work? 
 
I found out. iMA function only works with ENUM_APPLIED_PRICE. To make a moving average of volume we should create a handle of volume with iVolumes and then use it with iMA to create the moving average of it.