INDICATOR: GOOD START BUT NOT UPDATE AND GIVE VALUE ZERO IN SUCCESSIVE BARS

 
It's a problem I've found in almost all the designs I have ...

Although the indicator begins but does not update and informs zero values ​​from the next bar after loading into the drawing.

I give the example attached indicator: normalized ATR.

The trouble is that when using the indicator in EA code gives zero information 

Has anyone had this problem or seen in the attached code the error that I do not?

Thanks for the help 

MQL5.community - User Memo
MQL5.community - User Memo
  • 2010.02.25
  • MetaQuotes Software Corp.
  • www.mql5.com
You have just registered and most likely you have questions such as, "How do I insert a picture to my a message?" "How do I format my MQL5 source code?" "Where are my personal messages kept?" You may have many other questions. In this article, we have prepared some hands-on tips that will help you get accustomed in MQL5.community and take full advantage of its available features.
Files:
norm_ATR.mq5  7 kb
 
josemiguel1812:
It's a problem I've found in almost all the designs I have ...

Although the indicator begins but does not update and informs zero values ​​from the next bar after loading into the drawing.

I give the example attached indicator: normalized ATR.

The trouble is that when using the indicator in EA code gives zero information 

Has anyone had this problem or seen in the attached code the error that I do not?

Thanks for the help 

Your loop is only executed when prev_calculated is 0 (first call) :

   for(int k=inicio; k<limite; k++)
   {
      maxATR= MaxMinAbs(ATRbuffer, true, k, intervReferenc);  
      minATR= MaxMinAbs(ATRbuffer, false, k, intervReferenc);
      ATRbufferNorm[k]= normValor(ATRbuffer[k], maxATR, minATR, nivelMax, nivelMin);
   }

After that your value for inicio is always greater than that of limite, so the loop isn't executed.

 
angevoyageur:

Your loop is only executed when prev_calculated is 0 (first call) :

After that your value for inicio is always greater than that of limite, so the loop isn't executed.

Is it correct the next solution?

(intervReferenc= period to calculate a data from previous bars)

   if(preCalculado==0)
   {
      inicio= 0;
      limite= rangoTotal-preCalculado-intervReferenc;
      if(maxBarras>0) limite= MathMin(limite, maxBarras);
   } 
   else
   {
      inicio= rangoTotal-preCalculado;
      limite= rangoTotal-preCalculado+1;
   }
 
josemiguel1812:

Is it correct the next solution?

(intervReferenc= period to calculate a data from previous bars)

You are using :

   ArraySetAsSeries(ATRbuffer, true);
   ArraySetAsSeries(ATRbufferNorm, true);

So the current candle is 0 and old one is rates_total-1, so :

   inicio= 0;
   if(preCalculado==0)
   {
      limite= rangoTotal-intervReferenc;
      if(maxBarras>0) limite= MathMin(limite, maxBarras);
   } 
   else
   {
      limite= rangoTotal-preCalculado+1;
   }
 
josemiguel1812:

Is it correct the next solution?

(intervReferenc= period to calculate a data from previous bars)

Is that better?...

int OnCalculate(const int rangoTotal, const int preCalculado,
                const int begin,  
                const double& precio[]) 
{
   int inicio, limite, valoresCopiar;
   int barrasPosibles= BarsCalculated(puntATR);
   if(preCalculado==0)
   {
      inicio= 0;
      limite= MathMin(rangoTotal, barrasPosibles)-intervReferenc;
      if(maxBarras>0) limite= MathMin(limite, maxBarras);
      valoresCopiar= limite+intervReferenc;
   } 
   else
   {
      inicio= rangoTotal-preCalculado;
      limite= rangoTotal-preCalculado+1;
      valoresCopiar= limite;
   }
   if(CopyBuffer(puntATR, 0, 0, valoresCopiar, ATRbuffer)<1)
     {
 
josemiguel1812:

Is that better?...

Why ? No it isn't better... I provided you the solution in my previous post. Variable inicio must always be 0.