Problem with iMAOnArray

 

When I place the following code onto the chart why does it usually take 5 minutes to load onto the chart. I know im doing something wrong with buffers and iMAOnArray but cant see what?

#property indicator_buffers 1      

//---- buffers
double VolAVG[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0,VolAVG);      
   SetIndexStyle(0,DRAW_NONE);

   return(0);
} 
  
//+------------------------------------------------------------------
// Start Event Handler                               
//+------------------------------------------------------------------

int start()
{  
   int counted_bars = IndicatorCounted(); 
   if(counted_bars>0) counted_bars+=1;   
   int limit=Bars-counted_bars;          
   if(counted_bars==0) limit-=1; 
                            
    
        for(int i = limit; i >= 1; i--) 
   { 
      //--------------
      // Averaging Volume 
      //--------------
      VolAVG[i] = (double)iVolume(_Symbol,_Period,i);    
                                  
      double AVGVol1 = iMAOnArray(VolAVG,0,5,0,MODE_SMA,i); 
      double AVGVol2 = iMAOnArray(VolAVG,0,5,0,MODE_SMA,i+1);
           
      bool declvol = (AVGVol1 < AVGVol2);      
   }    
    
         
   return(0);
}
 
Stephen Reynolds: When I place the following code onto the chart why does it usually take 5 minutes to load onto the chart. I know im doing something wrong with buffers and iMAOnArray but cant see what?
  1. Nothing wrong there but you shouldn't expect to see anything. Volume should be in the range 100-30,000 depending on your TF. Non-JPY charts have prices in the range 0.9-15. Your line is nine feet above the top of the chart. Try:
    #property indicator_separate_window

  2. int start(){
    Start using the new Event Handling Functions Event Handling Functions - Functions - Language Basics - MQL4 Reference

  3.    int counted_bars = IndicatorCounted(); 
       if(counted_bars>0) counted_bars+=1;   
       int limit=Bars-counted_bars;          
       if(counted_bars==0) limit-=1; 
    See How to do your lookbacks correctly.