Indicator issue history drawing

 

Hi,

I coded a custom indicator, it works fine until new candle opens, after that indicator stops history drawing

what's wrong with it???

thanks

#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_label1 "Slow"
#property indicator_color1 Gold
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1

double EMA_Value[],HH[],LL[],HLC3[];
int    Len,Limit,i,y;
input int EMA_Value_Period = 96;                         //Slow EMA Period
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   Len=Bars-EMA_Value_Period;
   IndicatorBuffers(4);
//--- indicator buffers mapping
   SetIndexBuffer(0,EMA_Value); 
   SetIndexBuffer(1,HLC3);
   SetIndexBuffer(2,HH);
   SetIndexBuffer(3,LL);
   
   IndicatorDigits(Digits);
   
   ArrayResize(EMA_Value,Len);
   ArrayResize(HH,Len);
   ArrayResize(LL,Len);
   ArrayResize(HLC3,Len);
   
   ZeroMemory(EMA_Value);
   ZeroMemory(HH);
   ZeroMemory(LL);
   ZeroMemory(HLC3);
   
//---
   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[])
  {
//--- first calculation or number of bars was changed
   if(prev_calculated==0)
      ArrayInitialize(EMA_Value,0);

   Limit=Bars-IndicatorCounted();
   for(i=0;i<Limit;i++)
     {
         
     
         HH[i] = iHigh(Symbol(),PERIOD_CURRENT,iHighest(NULL,0,MODE_HIGH,(EMA_Value_Period-1),i));        //---InpMAPeriod's high calculation

         LL[i] = iLow(Symbol(),PERIOD_CURRENT,iLowest(NULL,0,MODE_LOW,(EMA_Value_Period-1),i));           //---InpMAPeriod's low calculation
         
                                                                        
         HLC3[i]=(HH[i]+LL[i]+Close[i])/3;                                                                //---InpMAPeriod's hlc3 calculation  
     }
   
//---Calculation
   EMA_Value[0]=HLC3[0];
   for(i=1; i<Len; i++)
      EMA_Value[i] = ExponentialMA(i,EMA_Value_Period,EMA_Value[i-1],HLC3);

       
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                        EMA Calculation                           |
//+------------------------------------------------------------------+
double ExponentialMA(const int position,const int period,const double prev_value,const double &price[])
  {
//---
   double result=0.0;
//--- calculate value
   if(period>0)
     {
      double pr=2.0/(period+1.0);
      result=price[position]*pr+prev_value*(1-pr);
     }
//---
   return(result);
  }

 

Did you look in the Experts log??

I expect that you are getting an array out of range error.

Probably here

         HH[i] = iHigh(Symbol(),PERIOD_CURRENT,iHighest(NULL,0,MODE_HIGH,(EMA_Value_Period-1),i));        //---InpMAPeriod's high calculation

         LL[i] = iLow(Symbol(),PERIOD_CURRENT,iLowest(NULL,0,MODE_LOW,(EMA_Value_Period-1),i));           //---InpMAPeriod's low calculation
 
Keith Watford:

Did you look in the Experts log??

I expect that you are getting an array out of range error.

Probably here

there isn't any error in the EA log :(

I need a loop???

 
Ashomid7:

there isn't any error in the EA log :(

I need a loop???

Are you sure that there is no error reported in the Experts log?

Why are you asking if you need a loop what does that have to do with my reply?

 
Keith Watford:

Are you sure that there is no error reported in the Experts log?

Why are you asking if you need a loop what does that have to do with my reply?

I was asking, do you think that I need loop!

but loop doesn't work

Reason: