My indicator is not updated when I change parameter

 

Hi Everyone,

I wrote this indicator to calculate number of up bar and down bar within a certain window which I called "lookback".
To my surprise, when I change lookback value, this indicator is not changed (still show the old value)

But if I delete this indicator on chart and re-attach to chart, it work with correct value.

I don't know what's going on and quite worry about my other code.

Could you help me to fix it?

Thanks so much.

HHC

 

PS. If I don't use the window input but type the number in as below, the indicator update anytime I change value 

for(int j1=i; j1<=i+lookback; j1++) 

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "Label1"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

//--- input parameters
input int      lookback=20;

//--- indicator buffers
double         Label1Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);
      string short_name;
   short_name="bar up down- lookback "+IntegerToString(lookback);
   IndicatorShortName(short_name);
//---
   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-1;
   if(limit<=0) limit=2;
   
for(int i=1;i<=limit && i<rates_total  ;i++)
{  int n_up=0 ;
   int n_down=0;
   
   for(int j1=i; j1<=i+lookback; j1++)
   {  if(iClose(NULL,0,j1)>iOpen(NULL,0,j1))
      {  n_up=n_up+1;
      }
      else 
      if(iClose(NULL,0,j1)<iOpen(NULL,0,j1))
      {  n_down=n_down+1;
      }
   }
   
   Label1Buffer[i]=n_up;


}
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+