Failed to display anything

 

Hi Guys, need some help please.

So I'm trying to build this indicator to show me(a histogram) the ratio between volume of a candle and its body size(Length of candle without the wicks).

So how it works(the way it should anyways) is it takes the difference(absolute value) between the open and close of the former candle, and then divides the volume of that candle with that value.

And what it should do is print(in a separate window) a histogram of this value with a different color depending on whether it is more or less than the former ratio. 

I cant see why it wont display this though.

Any help is appreciated,

//+------------------------------------------------------------------+
//|                                                  Volumentum.mq5 |
//+------------------------------------------------------------------+
#property copyright "Just Me 2021"
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   1
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_color1  Green,Red
#property indicator_style1  0
#property indicator_width1  1
#property indicator_minimum 0.0
//--- input data
input ENUM_APPLIED_VOLUME InpVolumeType=VOLUME_TICK; // Volumes
//--- indicator buffers
double ExtVolMomentumBuffer[];
double ExtColorsBuffer[];
//Initialization.
void OnInit()
  {
//--- buffers
   SetIndexBuffer(0,ExtVolMomentumBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtColorsBuffer,INDICATOR_COLOR_INDEX);
//--- name for DataWindow and indicator subwindow label
   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[])
  {
   if(rates_total<2)
      return(0);
//--- starting work
   int pos=prev_calculated-1;
//--- correct position
   if(pos<1)
     {
      ExtVolMomentumBuffer[0]=0;
      pos=1;
     }
//--- main cycle
   if(InpVolumeType==VOLUME_TICK)
      CalculateVolumentum(pos,rates_total,tick_volume,open,close);
   else
      CalculateVolumentum(pos,rates_total,volume,open,close);
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|   For calculating ratio                                          |
//+------------------------------------------------------------------+
void CalculateVolumentum(const int pos,const int rates_total,const long& volume[],const double &open[],const double &close[])
  {
   ExtVolMomentumBuffer[0]=(double)volume[0];
   ExtColorsBuffer[0]=0.0;
//---
   for(int i=pos; i<rates_total && !IsStopped(); i++)
     {
      double curr_disp=(fabs(open[i]-close[i])/_Point);
      double prev_disp=(fabs(open[i-1]-close[i-1])/_Point);
      double curr_volumeDispRatio=(double)(volume[i]/curr_disp);
      double prev_volumeDispRatio=(double)(volume[i-1]/prev_disp);
      //--- calculate indicator
      ExtVolMomentumBuffer[i]=(volume[i]);
      if(curr_volumeDispRatio>prev_volumeDispRatio)
         ExtColorsBuffer[i]=0.0;
      else
         ExtColorsBuffer[i]=1.0;
     }
//---
  }
//+------------------------------------------------------------------+
 
bustabrunoo: I cant see why it wont display this though.

You are indexing i=[0 … Bars-1] (as non-series). You haven't set your arrays and buffers to match.

In MT5, you must set the direction.

To define the indexing direction in the time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[] arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
          Event Handling / OnCalculate - Reference on algorithmic/automated trading language for MetaTrader 5
 
William Roeder:

You are indexing i=[0 … Bars-1] (as non-series). You haven't set your arrays and buffers to match.

In MT5, you must set the direction.

Thanks for the reply,

I tried that and also changed the direction so that it plots from ratestotal-1 to the former candle and it works sorta!

Whats happening is now its plotting the first 30 values(from the left ie ratestotal) and the last(rightmost) 32 values but it plots none of the values in between the two extremes.

Reason: