MT5 indicator based on another indicator using iCustom() or iMA()

 

Hello everyone! Please bear with me, I searched everywhere and tried to fix this for many days now. Still no luck.

When adding handles to other indicators from within custom indicator by calling either iMA(), iCustom or Trend.mqh class, the indicator often shows junk arrows when changing timeframes. How to avoid that?

 

Apparently, although I already emptied the buffers inside OnInit()

int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ext_bullish_buffer,INDICATOR_DATA);
   SetIndexBuffer(1,ext_bullish_colors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,ext_bearish_buffer,INDICATOR_DATA);
   SetIndexBuffer(3,ext_bearish_colors,INDICATOR_COLOR_INDEX);
        
   ArrayInitialize (ext_bullish_buffer,EMPTY_VALUE);
   ArrayInitialize (ext_bearish_buffer,EMPTY_VALUE);

//---
   return(INIT_SUCCEEDED);
  }

I also have to empty each cell inside the main loop too.
This solved the issue.

   for (int bar=bars_to_calculate; bar>=0 && !IsStopped(); bar--)
   {
      ext_bullish_buffer[bar] = EMPTY_VALUE;
      ext_bearish_buffer[bar] = EMPTY_VALUE;
        
      if (isBullish(bar))
         ext_bullish_buffer[bar] = low[bar];
      if (isBearish(bar))
         ext_bearish_buffer[bar] = high[bar];
   }

Reason: