"Array out of Range" in Volume Indicator

 

Sir,

I created this Volume Indicator but I am getting error "Array out of Range".

I have some wronged this Source code. Please check this 👇

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_buffers 3
#property indicator_color1 clrBlack
#property indicator_color2 clrGreen
#property indicator_color3 clrRed
#property indicator_width2 3
#property indicator_width3 3

double volumes_buffer[];
double volumes_up[];
double volumes_down[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, volumes_buffer,INDICATOR_DATA);
   SetIndexBuffer(1, volumes_up,INDICATOR_DATA);
   SetIndexBuffer(2, volumes_down,INDICATOR_DATA);

//---- drawing settings
   SetIndexStyle(0, 12,0);
   SetIndexStyle(1, 2,0);
   SetIndexStyle(2, 2,0);

//---- sets default precision format for indicators visualization

//IndicatorDigits(0);
   IndicatorSetInteger(INDICATOR_DIGITS,0);

//---- name for DataWindow and indicator subwindow label

//IndicatorShortName("My Volumes");
   IndicatorSetString(INDICATOR_SHORTNAME,"My Volumes");

//SetIndexLabel(0, "Volumes");
   PlotIndexSetString(0,PLOT_LABEL,"Volumes");

//SetIndexLabel(1, NULL);
   PlotIndexSetString(1,PLOT_LABEL,NULL);

//SetIndexLabel(2, NULL);
   PlotIndexSetString(2,PLOT_LABEL,NULL);


//---- sets drawing line empty value

//SetIndexEmptyValue(1, 0.0);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0.0);

//SetIndexEmptyValue(2, 0.0);
   PlotIndexSetDouble(2,PLOT_EMPTY_VALUE,0.0);

//---- initialization done

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
//---

   int limit =0;
   int counted_bars = IndicatorCounted(prev_calculated);

   

   CalculateVolume(counted_bars,volume,limit);


//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------//



// Converted MQL4 TO MQL5
void SetIndexStyle(int index,
                   int type,
                   int style= 0,
                   int width=0,
                   color clr=clrNONE)
  {
   if(width>-1)
      PlotIndexSetInteger(index,PLOT_LINE_WIDTH,width);
   if(clr!=clrNONE)
      PlotIndexSetInteger(index,PLOT_LINE_COLOR,clr);
   switch(type)
     {
      case 0:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_LINE);
      case 1:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_SECTION);
      case 2:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_HISTOGRAM);
      case 3:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_ARROW);
      case 4:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_ZIGZAG);
      case 12:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_NONE);

      default:
         PlotIndexSetInteger(index,PLOT_DRAW_TYPE,DRAW_LINE);
     }
   switch(style)
     {
      case 0:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_SOLID);
      case 1:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DASH);
      case 2:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DOT);
      case 3:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DASHDOT);
      case 4:
         PlotIndexSetInteger(index,PLOT_LINE_STYLE,STYLE_DASHDOTDOT);

      default:
         return;
     }
  }
//+------------------------------------------------------------------+


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int IndicatorCounted(int prev_calculated)
  {
   if(prev_calculated>0)
     {
      return(prev_calculated-1);
     }

   if(prev_calculated==0)
     {
      return(0);
     }

   return(0);
  }


//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CalculateVolume(int counted_bars,const long &volume[],int limit)
  {
  //---- check for possible errors
   if(counted_bars < 0)
      return(-1);

//---- the last counted bar will be recounted
   if(counted_bars > 0)
      counted_bars--;

   limit = Bars(Symbol(),PERIOD_CURRENT) - counted_bars;
   
   for(int i=0; i<limit; i++)
     {
      double my_volume = (double)volume[i];

      if(my_volume > (double)volume[i+1])
        {
         volumes_buffer[i] = my_volume;
         volumes_up[i] = my_volume;
         volumes_down[i] = 0.0;
        }
      else
        {
         volumes_buffer[i] = my_volume;
         volumes_up[i] = 0.0;
         volumes_down[i] = my_volume;
        }
     }
     
     return 1;
  }
Files:
 
   limit = Bars(Symbol(),PERIOD_CURRENT) - counted_bars;
   ⋮
      if(my_volume > (double)volume[i+1])

I plus 1 equals limit, which does not exist.

Do lookbacks correctly #9 — #14 & #19. (2016)
 
William Roeder #:

I plus 1 equals limit, which does not exist.

Do lookbacks correctly #9 — #14 & #19. (2016)

Sorry Sir,

I don't understand this Source code because I am getting error...

Please simply this code....