Strange problem, OnDeinit not run in indicator

 

Hi

I have a strange problem, that is OnDeinit not run when i delete my indicator from chart.

The following code is a example of my indicator :


#property strict
#property indicator_chart_window

int OnInit()
{


   return(INIT_SUCCEEDED);
}


void OnDeinit(const int reason){
   
   Comment("Exiting...");
   ObjectsDeleteAll();

}


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 C;
     double Candle; 

     for(C=1; C < Bars ; C++){

        Candle = Low[C+1];

        ObjectCreate("11" + IntegerToString(C) , OBJ_TEXT, 0, Time[C], Low[C] );
        ObjectSetText("11" + IntegerToString(C), "Test", 10, "Arial", clrWhite);
   
     }


   return(rates_total);
  }


Strange part is when i remove this line , OnDeinit  run Properly:

Candle = Low[C+1];


What's problem?





 
When the value of C is Bars - 1, Low [C + 1] is the same as Low [Bars]. At this time, execution of the program stops due to "array out of range" error.
 
Naguisa Unada:
When the value of C is Bars - 1, Low [C + 1] is the same as Low [Bars]. At this time, execution of the program stops due to "array out of range" error.

Many many thanks Naguisa Unada.

Big help for me :)