Im coding a Volume horizonal Line & have some problem. Help please!

 

Hi all pro coders,

Im learning coding mql4.

Im coding a volume horizonal line that will pick up last 100 highest volume bars from the recent 300 volume bars, averaging them & then draw a horizonal line at current volume Bar on a tick VOLUME indicator.

But I got some problem & dont know why it appears nothing & How to code it o apply on a volume indicator? No Errors found!

Please help me! show me my mistakes

Thanks the Forum & all pro coders , I ve learnt alot :)

regard,


#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrRed
#property indicator_width1 1
#property indicator_style1  STYLE_SOLID
//--- indicator buffers

double         Vol_300bars[300];
double         VolExtr_line[];
double av;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   
   SetIndexBuffer(0,VolExtr_line);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexLabel(0,"Volumeline");

//---
   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 =rates_total -  prev_calculated;  
if(limit > 0)                        
    { //--------------- 
      for (int i= 1; i<=300; i++)
      { 
         Vol_300bars[i-1]=NormalizeDouble(Volume[i],0);
      }
      ArraySort(Vol_300bars,WHOLE_ARRAY,0,MODE_DESCEND);
      //--------------
      av=0;
      for (int u =0; u<=99; u++)
      {
      av = av+Vol_300bars[u];
      }
      av=av/100;
      
      //------------
      VolExtr_line[0]=av;
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
 
aphong:

Hi all pro coders,

Im learning coding mql4.

Im coding a volume horizonal line that will pick up last 100 highest volume bars from the recent 300 volume bars, averaging them & then draw a horizonal line at Bar No.0 on a tick VOLUME indicator.

But I got some problem & dont know why it appears nothing & How to code it o apply on a volume indicator? No Errors found!

Please help me! show me my mistakes

Thanks the Forum & all pro coders , I ve learnt alot :)

regard,

Im no expert but I would expect to see VolExtr_line[i] here:

VolExtr_line[1]=av;
 

The problem is minimum and maximum are the same value.

      av=0;
      for (int u =0; u<=99; u++)
      {
      av = av+Vol_300bars[u];
      }
      av=av/100;
      
      //------------
      VolExtr_line[3]=av+av/2;
      VolExtr_line[2]=av-av/2;
      VolExtr_line[1]=VolExtr_line[0]=av;
      ObjectCreate("vol_extr",OBJ_HLINE,ChartWindowFind(),0,0);
      ObjectSet("vol_extr",OBJPROP_PRICE1,av);
      ObjectSet("vol_extr",OBJPROP_COLOR,clrRed);
 
Ernst Van Der Merwe:

The problem is minimum and maximum are the same value.    

Thank you so much!

great! It works, Sorry But I still dont get the logic why we have to add these lines instead of just put ...VolExtr_line[0]=av ? Could you please give me some more explaination :)

VolExtr_line[3]=av+av/2;
VolExtr_line[2]=av-av/2;
VolExtr_line[1]=av;
 
aphong:

Thank you so much!

great! It works, Sorry But I still dont get the logic why we have to add these lines instead of just put ...VolExtr_line[0]=av ? Could you please give me some more explaination :)

You're welcome.

VolExtr_line[3]=av+av/2;   //Sets the window maximum
VolExtr_line[2]=av-av/2;   //Sets the window minimum
VolExtr_line[1]=av;        
 
Ernst Van Der Merwe:

You're welcome.

Thanks Ernst!

Have a good day! & Green Pips :)

Reason: