Cant plot full contents of buffer.

 

So am trying to make an indicator that gives the ratio between each candles volume and its body size(close-open).

But i just cant seem to be able to print a plot for all available bars in history. It always stops  plotting at index 35(the 36thbar).As new candles come in it works fine it plots a new value as soon the 

new candle closes.

I am kindly requesting for assistance from anyone please.

//+------------------------------------------------------------------+
//|                                                  Volumentum.mq5 |
//+------------------------------------------------------------------+
#property copyright "Just Me 2021"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_color1  Green
#property indicator_style1  0
#property indicator_width1  4
#property indicator_minimum 0.0
//--- indicator buffers
double ExtVolMomentumBuffer[];
double curr_disp=0;
//Initialization.
void OnInit()
  {
//--- buffers
   ArraySetAsSeries(ExtVolMomentumBuffer,true);
   SetIndexBuffer(0,ExtVolMomentumBuffer,INDICATOR_DATA);
//--- name for DataWindow and indicator subwindow label
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,0);
   IndicatorSetString(INDICATOR_SHORTNAME,"Volumentum");
//--- indicator digits
   IndicatorSetInteger(INDICATOR_DIGITS,0);
  }
//+------------------------------------------------------------------+
//|  Volumes                                                         |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   ArraySetAsSeries(open,true);
   ArraySetAsSeries(close,true);
   ArraySetAsSeries(tick_volume,true);
   ArraySetAsSeries(open,true);
   if(rates_total<2)
      return(0);
   Alert("Bars are" + Bars(_Symbol,PERIOD_CURRENT));
//Calculate for all available bars.
   for(int i=0; i<Bars(_Symbol,PERIOD_CURRENT); i++)
      CalculateVolumentum(i,tick_volume,open,close);
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|   For calculating ratio                                          |
//+------------------------------------------------------------------+
void CalculateVolumentum(int i,const long& volume[],const double &open[],const double &close[])
  {
   ExtVolMomentumBuffer[0]=0;
   curr_disp=(fabs(open[i]-close[i])/_Point);  //This is the size of the body wick.
//--- calculate indicator
   ExtVolMomentumBuffer[i]=(volume[i]/curr_disp); //Populate buffer to be plotted.
   Alert("" + i); //Just to see how many candles have been calculated so far.
  }
//+------------------------------------------------------------------+
Files:
 

You should always think about economical recalculation of values! DO NOT count the ENTIRE history at every tick!

Algorithm example:


//--- main loop
   int limit=prev_calculated-1;
   if(prev_calculated==0)
      limit=0;
   for(int i=limit; i<rates_total; i++)
     {
      CalculateVolumentum(i,tick_volume,open,close);
     }
 
Vladimir Karputov:

You should always think about economical recalculation of values! DO NOT count the ENTIRE history at every tick!

Algorithm example:


Thank you so much for the help.

I think i need some help understanding exactly what prev_calculated is, like what is the initial value

And yeah I implemented the way you suggested though i didnt really see the logic difference and again same problem, can only see output for like the last few bars, GJ is showing the most bars but only 125 also.

Ive attached a picture to show how it looks exactly. The indicator is in its own indicator window.

Files:
 
Freedom FX:

Thank you so much for the help.

I think i need some help understanding exactly what prev_calculated is, like what is the initial value

And yeah I implemented the way you suggested though i didnt really see the logic difference and again same problem, can only see output for like the last few bars, GJ is showing the most bars but only 125 also.

Ive attached a picture to show how it looks exactly. The indicator is in its own indicator window.

What is prev_calculated - You must read the help and articles.  There is a search in the upper right corner of the site - start learning.
Reason: