indicator buffers are always zero (mql5)

 

hi this indicator does not work correctly and indicator buffers are always zero
what is the problem?


#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

#property indicator_label1  "Lower Shadow"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrGold
#property indicator_width1 2

#property indicator_label2  "Upper Shadow"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed
#property indicator_width2 2





input double UpShadowPercent=51;
input double DownShadowPercent=51;
input bool Alarm=true;
input bool Notification=true;

datetime newCandleTime=0;
double Lower_Buffer[];
double Upper_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, Lower_Buffer);
   PlotIndexSetInteger(0,PLOT_ARROW,161);
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,5);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   SetIndexBuffer(1, Upper_Buffer);
   PlotIndexSetInteger(1,PLOT_ARROW,161);
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,5);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
 
   
//---
   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,i;  
   
      if(prev_calculated==0)
     {
      limit=500;
      
      
      for(i=limit; i>=2; i--)
    
        {
   
         
             double WL[58];
             double CandleLen=iHigh(Symbol(),PERIOD_W1,1)-iLow(Symbol(),PERIOD_W1,1);
             for( int r=0; r<58; r++ )
             {
               
               if(r==25)  
                 WL[r]=iHigh(Symbol(),PERIOD_W1,1);
               if(r<25)   
                 WL[r]=iHigh(Symbol(),PERIOD_W1,1)+(CandleLen/8)*MathAbs(r-25);
               if(r>25)   
                 WL[r]=iHigh(Symbol(),PERIOD_W1,1)-(CandleLen/8)*MathAbs(r-25);   
               
             }
        
           bool BullSignal=false;
           bool BearSignal=false;
           double Len=iHigh(Symbol(),PERIOD_CURRENT,i)-iLow(Symbol(),PERIOD_CURRENT,i);  
           double UpShadow=iHigh(Symbol(),PERIOD_CURRENT,i)-MathMax(iOpen(Symbol(),PERIOD_CURRENT,i),iClose(Symbol(),PERIOD_CURRENT,i));
           double DownShadow=MathMin(iOpen(Symbol(),PERIOD_CURRENT,i),iClose(Symbol(),PERIOD_CURRENT,i))-iLow(Symbol(),PERIOD_CURRENT,i);    
           if( UpShadow>DownShadow && (UpShadow/Len)*100>UpShadowPercent )      
             BearSignal=true;
           if( UpShadow<DownShadow && (DownShadow/Len)*100>DownShadowPercent )  
             BullSignal=true;
    
            
            for( int k=0; k<58; k++ )
            {
              if(BullSignal && WL[k]<=iHigh(Symbol(),PERIOD_CURRENT,i) && WL[k]>=iLow(Symbol(),PERIOD_CURRENT,i) )
                {Lower_Buffer[i]= iLow(Symbol(),PERIOD_CURRENT,i);}
              if(BearSignal && WL[k]<=iHigh(Symbol(),PERIOD_CURRENT,i) && WL[k]>=iLow(Symbol(),PERIOD_CURRENT,i) )
                {Upper_Buffer[i]= iHigh(Symbol(),PERIOD_CURRENT,i);}   
            }
                   
                  
        }
   
     }
 return(rates_total);
  }
 
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum #6 (2017)

  2. What does your code do, after the first run, when prev_calculated is nonzero?
              How to do your lookbacks correctly #9#14 & #19 (2016)
 
William Roeder #:
  1. Don't double post! You already had this thread open.
              General rules and best pratices of the Forum. - General - MQL5 programming forum #6 (2017)

  2. What does your code do, after the first run, when prev_calculated is nonzero?
              How to do your lookbacks correctly #9#14 & #19 (2016)
1) i deleted one of the posts
2) nothing. just one time it should draw some arrows on specific candles
 

You forgot to use ArraySetAsSeries in OnInit


#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"


#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2

#property indicator_label1  "Lower Shadow"
#property indicator_type1 DRAW_ARROW
#property indicator_color1 clrGold
#property indicator_width1 2

#property indicator_label2  "Upper Shadow"
#property indicator_type2 DRAW_ARROW
#property indicator_color2 clrRed
#property indicator_width2 2





input double UpShadowPercent=51;
input double DownShadowPercent=51;
input bool Alarm=true;
input bool Notification=true;

datetime newCandleTime=0;
double Lower_Buffer[];
double Upper_Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0, Lower_Buffer);
   PlotIndexSetInteger(0,PLOT_ARROW,161);
   PlotIndexSetInteger(0,PLOT_ARROW_SHIFT,5);
   PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0);
   SetIndexBuffer(1, Upper_Buffer);
   PlotIndexSetInteger(1,PLOT_ARROW,161);
   PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,5);
   PlotIndexSetDouble(1,PLOT_EMPTY_VALUE,0);
   
   ArraySetAsSeries(Lower_Buffer, true);
   ArraySetAsSeries(Upper_Buffer, true);
   
   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,i;  
   
      if(prev_calculated==0)
     {
      limit=500;
      
      
      for(i=limit; i>=2; i--)
    
        {
   
         
             double WL[58];
             double CandleLen=iHigh(Symbol(),PERIOD_W1,1)-iLow(Symbol(),PERIOD_W1,1);
             for( int r=0; r<58; r++ )
             {
               
               if(r==25)  
                 WL[r]=iHigh(Symbol(),PERIOD_W1,1);
               if(r<25)   
                 WL[r]=iHigh(Symbol(),PERIOD_W1,1)+(CandleLen/8)*MathAbs(r-25);
               if(r>25)   
                 WL[r]=iHigh(Symbol(),PERIOD_W1,1)-(CandleLen/8)*MathAbs(r-25);   
               
             }
        
           bool BullSignal=false;
           bool BearSignal=false;
           double Len=iHigh(Symbol(),PERIOD_CURRENT,i)-iLow(Symbol(),PERIOD_CURRENT,i);  
           double UpShadow=iHigh(Symbol(),PERIOD_CURRENT,i)-MathMax(iOpen(Symbol(),PERIOD_CURRENT,i),iClose(Symbol(),PERIOD_CURRENT,i));
           double DownShadow=MathMin(iOpen(Symbol(),PERIOD_CURRENT,i),iClose(Symbol(),PERIOD_CURRENT,i))-iLow(Symbol(),PERIOD_CURRENT,i);    
           if( UpShadow>DownShadow && (UpShadow/Len)*100>UpShadowPercent )      
             BearSignal=true;
           if( UpShadow<DownShadow && (DownShadow/Len)*100>DownShadowPercent )  
             BullSignal=true;
    
            
            for( int k=0; k<58; k++ )
            {
              if(BullSignal && WL[k]<=iHigh(Symbol(),PERIOD_CURRENT,i) && WL[k]>=iLow(Symbol(),PERIOD_CURRENT,i) )
                {Lower_Buffer[i]= iLow(Symbol(),PERIOD_CURRENT,i);}
              if(BearSignal && WL[k]<=iHigh(Symbol(),PERIOD_CURRENT,i) && WL[k]>=iLow(Symbol(),PERIOD_CURRENT,i) )
                {Upper_Buffer[i]= iHigh(Symbol(),PERIOD_CURRENT,i);}   
            }
                   
                  
        }
   
     }
 return(rates_total);
  }
 
vesam moosavi:

hi this indicator does not work correctly and indicator buffers are always zero
what is the problem?


Initialize the buffer arrays with empty value
Reason: