Indicators: Donchian Channel for beginners by William210

 

Donchian Channel for beginners by William210:

Donchian Channel for traders or young developers by William210

Donchian Channel for beginners by William210

Author: Gerard Willia G J B M Dinh Sy

 

Good morning.

I made a slight optimization in oncalculate by surrounding the main loop with a condition.


   /* Only if we have a new bar */
  if( prev_calculated < rates_total) {
    /* Main loop */
    for( int i = i_Start; i < rates_total && !IsStopped(); i++) {
      g_BuffDonchianUP[i] = high[ ArrayMaximum( high,  i + 1 - g_DonPeriod, g_DonPeriod)];
      g_BuffDonchianDW[i] = low[ ArrayMinimum(  low,   i + 1 - g_DonPeriod, g_DonPeriod)];
      g_BuffDonchianMD[i] = ( g_BuffDonchianUP[i] + g_BuffDonchianDW[i]) / 2.0;
    }
  }

The code passes every tick in oncalculate, which does not necessarily mean that there is necessarily a new bar.

With this condition added, it is indeed a new bar which triggers the calculation and not the tick