Indicator : Repainting to non repainting (MQL5)

 

Hi,

I have written an indicator without taking care of the fact it could repaint. I've searched all around the forum but couldn't find how to make it non repainting. So below some code, the code supposed to be responsible of the repainting (bar calculation). How to make it non repainting ?

//---- calculations of the necessary amount of data to be copied
//---- and the 'limit' starting index for the bars recalculation loop
   if(prev_calculated>rates_total || prev_calculated<=0)// checking for the first start of the indicator calculation
     {
      limit=rates_total-StartBars;       // starting index for calculation of all bars
     }
   else
     {
      limit=rates_total-prev_calculated; // starting index for calculation of new bars
     }

............ some code .............

//---- main loop of the indicator calculation
   for(int bar=limit; bar>=0; bar--)
     {
      count=bar;
      Range=0;
      AvgRange=0;
      for(count=bar;count<=bar+9;count++) AvgRange=AvgRange+MathAbs(high[count]-low[count]);
      Range=AvgRange/10;

....................................

   BuyBuffer[bar]=low[bar]-Range*SignalShift;
   SellBuffer[bar]=high[bar]+Range*SignalShift;
 
blouf:

Hi,

I have written an indicator without taking care of the fact it could repaint. I've searched all around the forum but couldn't find how to make it non repainting. So below some code, the code supposed to be responsible of the repainting (bar calculation). How to make it non repainting ?

Double post. Please take a look at this topic: https://www.mql5.com/en/forum/40874
 
Malacarne:
Double post. Please take a look at this topic: https://www.mql5.com/en/forum/40874
I've made it, indeed it's all about the intern logic of the calculation. For now it's ok, I'm tracking bugs.
 

Hi admin, thanks for your good work. I'm trying to understand repainting and non repainting indicators and the referenced post https://www.mql5.com/en/forum/40874 is no longer available. Could someone please point me to the right direction? Thanks

 
Rodrigo Malacarne:
Double post. Please take a look at this topic: https://www.mql5.com/en/forum/40874

404. The page does not exist

 
hmwangi:

Hi admin, thanks for your good work. I'm trying to understand repainting and non repainting indicators and the referenced post https://www.mql5.com/en/forum/40874 is no longer available. Could someone please point me to the right direction? Thanks

Repainting is almost always (unless it is recalculation - like regression analysis for example) coding error. So, start from the coding errors checking (as a general rule of thumb)
 
Mladen Rakic:
Repainting is almost always (unless it is recalculation - like regression analysis for example) coding error. So, start from the coding errors checking (as a general rule of thumb)
Not always, there are some programmers who make indicators that repaint in order to be nice on the chart for commercial reasons. Regards.
 

Wow. Old post there !

Ok, repainting, redrawing. Attach the indicator to any chart, low timeframe for testing purpose, mark every signal, if after few time, the indicator signals aren't no longer where it was marked : it is redrawing.

It's not always for commercial purpose, I don't think so, nobody, no coders would trade with a redrawing one, comes a point, in your daily usage, you'll need it non redrawing.  

All is about the candles counting, something like, count it once, count it wise - it's an old post, I just remind that it was about logic :).

(I unfav the post). Hope it helps.

 

repainting is mostly occur on. 

for(int bar=limit; bar>=0; bar--)

..and plus you have to look back (shift bar back). the greater the shift, the worst it repaint.
most of the code are necessary (for the sake of coding), depend on which customs indicator are you using. 

I start using counting forward rules in my coding example.
it make almost no repaint (except for current non closing bar).

Hope it help. 

for (int BarMeasure = 0; BarMeasure <= TotalBar; BarMeasure++)
 
Hairi Baba:

repainting is mostly occur on. 

for(int bar=limit; bar>=0; bar--)

..and plus you have to look back (shift bar back). the greater the shift, the worst it repaint.
most of the code are necessary (for the sake of coding), depend on which customs indicator are you using. 

I start using counting forward rules in my coding example.
it make almost no repaint (except for current non closing bar).

Hope it help. 

for (int BarMeasure = 0; BarMeasure <= TotalBar; BarMeasure++)
Counting down or up doesn't matter.