DiDi Index indicator

 

Hi guys,

Am trying to understand why I get ZeroDivideError for the indicator at the end of the calculation loop. 


Last 20 candles SlowMa is 0....

This is code of the indicator:

 

int init()
{
   SetIndexBuffer(0, CurtaBuffer, INDICATOR_DATA);
   SetIndexBuffer(1, MediaBuffer, INDICATOR_DATA);
   SetIndexBuffer(2, LongaBuffer, INDICATOR_DATA);
   ArraySetAsSeries(CurtaBuffer,true);
    ArraySetAsSeries(MediaBuffer,true);
     ArraySetAsSeries(LongaBuffer,true);
   return(0);
}

int start()
{
   if(Bars<=Longa) return(0);

	CalculateDidiIndex();

   return(0);
  }
//+------------------------------------------------------------------+
void CalculateDidiIndex()
{
   for(int i = 0; i <= Bars-1; i++)
   {
      CurtaBuffer[i] = iMA(_Symbol, 0, Curta, 0, CurtaMethod, CurtaAppliedPrice, i);
      MediaBuffer[i] = iMA(_Symbol, 0, Media, 0, MediaMethod, MediaAppliedPrice, i);
      LongaBuffer[i] = iMA(_Symbol, 0, Longa, 0, LongaMethod, LongaAppliedPrice, i);
      
     
      CurtaBuffer[i] /= MediaBuffer[i];
      
      LongaBuffer[i] /= MediaBuffer[i];
      MediaBuffer[i] = 1;
      
      PrintFormat("FastMa= %g , MedMa= %g ,SlowMa= %g , i= %g, TotalBars= %g",CurtaBuffer[i],MediaBuffer[i],LongaBuffer[i],i,Bars);
   }
}

2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 1.00307 ,  MedMa= 1 ,SlowMa= 0 ,         i= 2058, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 1.00554 ,  MedMa= 1 ,SlowMa= 0 ,         i= 2057, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 1.00444 ,  MedMa= 1 ,SlowMa= 0 ,         i= 2056, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 1.00281 ,  MedMa= 1 ,SlowMa= 0 ,         i= 2055, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 0.99988 ,  MedMa= 1 ,SlowMa= 0 ,         i= 2054, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 0.996106 , MedMa= 1 ,SlowMa= 0 ,         i= 2053, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 0.992913 , MedMa= 1 ,SlowMa= 0 ,         i= 2052, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 0.993639 , MedMa= 1 ,SlowMa= 0 ,         i= 2051, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 0.996096 , MedMa= 1 ,SlowMa= 0 ,         i= 2050, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 0.998452 , MedMa= 1 ,SlowMa= 0 ,         i= 2049, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 1.00168 ,  MedMa= 1 ,SlowMa= 0 ,         i= 2048, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 1.0046 ,   MedMa= 1 ,SlowMa= 0 ,         i= 2047, TotalBars= 2066
2022.01.01 17:27:01.332 Didi_Index EURUSD,Daily: FastMa= 1.005 ,    MedMa= 1 ,SlowMa= 1.00186 ,   i= 2046, TotalBars= 2066
 
Daniel Cioca: d why I get ZeroDivideError for the indicator at the end of the calculation loop.

There is no long MA after Bars-1-Longa.

Do your lookbacks correctly #9#14 & #19

.
 
William Roeder #:

There is no long MA after Bars-1-Longa.

Do your lookbacks correctly #9#14 & #19

.
Done… thanks
Reason: