Duplicate Indicators oninit

 

I wrote a custom indicator which attaches 5 other indicators to the chart - Yes, just like a template. 

Unfortunately, each time I change the periods of the MA and re-open MT5, the Moving Averages duplicate. Here is a pic of what I mean 

Here the MA where I changed the period is duplicated and shows the default period of custom indicator (A total of 2 MAs).

I tried deleting the indicator on deinit() but shockingly the problem still persists.

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[])
  {

   ma1 = iCustom(_Symbol,PERIOD_CURRENT,"::Indicators\\ma_1");
   ma2 = iCustom(_Symbol,PERIOD_CURRENT,"::Indicators\\ma_2");


   int ma_exists =  ChartIndicatorGet(0,0,"ma1");
   int ma_2_exists = ChartIndicatorGet(0,0,"ma2");


   if(ma_exists<0)
     {
      ChartIndicatorAdd(0,0,ma1);
     }
   if(ma_2_exists<0)
     {
      ChartIndicatorAdd(0,0,ma2);
     }
 

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

void OnDeinit(const int reason)
  {
   ChartIndicatorDelete(0,0,"ma1");
   ChartIndicatorDelete(0,0,"ma2");
  }

Please what do you think I am doing wrong? 

 

I have also called the iCustom function on init().

Searched the forum ad didn't find any query similar to this :(

 
Chioma Obunadike:

I wrote a custom indicator which attaches 5 other indicators to the chart - Yes, just like a template. 

Unfortunately, each time I change the periods of the MA and re-open MT5, the Moving Averages duplicate. Here is a pic of what I mean 

Here the MA where I changed the period is duplicated and shows the default period of custom indicator (A total of 2 MAs).

I tried deleting the indicator on deinit() but shockingly the problem still persists.

Please what do you think I am doing wrong? 

It is much more complicated to track your indicators on chart than the little code you have shown... Please do some research on the topic, the forum should give you details on such

 
Dominik Christian Egert #:

It is much more complicated to track your indicators on chart than the little code you have shown... Please do some research on the topic, the forum should give you details on such

this is actually all I use in writing the indicator.

 
Chioma Obunadike #:

I have also called the iCustom function on init().

Searched the forum ad didn't find any query similar to this :(

It has been discussed several times. But for sure, it's hard to find things on this site sometimes.