Cannot Alter Properties of Custom Indicator

 

I am trying to display two versions of a custom indicator (with differing lookback periods),  on the same chart, but when I try to change the indicator width or line style in the indicator properties box, it just disapears off of the chart after pressing "OK".

What do I need to enable to allow the properties box to change colours/line style/line width?

Code is below just in case:

#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue     
#property indicator_color2 Red
extern int MA_Period=50;
int Limit;
int Bar;
int i;
int j;
int It;
int Count;
double HoP[]; // High of period
double LoP[]; // Low of period
double SoH; // Sum of highs
double SoL; // Sum of lows
double Top_Band[];
double Bottom_Band[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,Top_Band);
   SetIndexBuffer(1,Bottom_Band);
   SetIndexStyle(0,0,2,1);
   SetIndexStyle(1,0,2,1);
   SetIndexLabel(0,"Top Band");
   SetIndexLabel(1,"Bottom Band");
   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[])
  {
   ArrayResize(HoP,MA_Period);
   ArrayResize(LoP,MA_Period);
   Limit=Bars-MA_Period;
   int Counted_Bars=IndicatorCounted();
   i=Bars-Counted_Bars-1;  
   if(i>Limit)
      i=Limit;
   Bar=i;    
      
   while(i==Limit)
      {
      for(j=Limit; j<Bars; j++)
         {
         HoP[Count] = High[j];
         LoP[Count] = Low[j];
         SoH    = SoH + HoP[Count];
         SoL    = SoL + LoP[Count]; 
         Count++;
         }
      
      Top_Band[i]    = SoH / MA_Period;
      Bottom_Band[i] = SoL / MA_Period;
      
      SoH = SoH - HoP[MA_Period-1];
      SoL = SoL - LoP[MA_Period-1];
      
      i--;
      }
      
      Count=0; 
      
      while(i<Limit && i>0)
         {
         ArrayCopy(HoP,HoP,1,0,MA_Period-1); // Taken
         ArrayCopy(LoP,LoP,1,0,MA_Period-1);
         HoP[Count] = High[i];      // Added
         LoP[Count] = Low[i];
         SoH        = SoH + HoP[Count];   // Added
         SoL        = SoL + LoP[Count];
         
         Top_Band[i]    = SoH / MA_Period;
         Bottom_Band[i] = SoL / MA_Period;
         
         SoH = SoH - HoP[MA_Period-1]; // Taken
         SoL = SoL - LoP[MA_Period-1];
         
         i--;
         } 
   
   return(rates_total);
  }
 

Declare the properties globally and not in OnInit().

#property indicator_buffers 2
#property indicator_color1 Blue     
#property indicator_style1 STYLE_DOT
#property indicator_width1 1   
#property indicator_color2 Red
#property indicator_style1 STYLE_DOT
#property indicator_width2 1    
extern int MA_Period=50;
int Limit;
int Bar;
int i;
int j;
int It;
int Count;
double HoP[]; // High of period
double LoP[]; // Low of period
double SoH; // Sum of highs
double SoL; // Sum of lows
double Top_Band[];
double Bottom_Band[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   SetIndexBuffer(0,Top_Band);
   SetIndexBuffer(1,Bottom_Band);
   //SetIndexStyle(0,0,2,1);
   //SetIndexStyle(1,0,2,1);
   SetIndexLabel(0,"Top Band");
   SetIndexLabel(1,"Bottom Band");
   return(INIT_SUCCEEDED);
  }
 
Ernst Van Der Merwe:

Declare the properties globally and not in OnInit().

Thank you.

Reason: