Download MetaTrader 5

Indicator : Repainting to non repainting (MQL5)

To add comments, please log in or register
Icham Aidibe
10391
Icham Aidibe  

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;
Rodrigo Malacarne
Moderator
10587
Rodrigo Malacarne  
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
Icham Aidibe
10391
Icham Aidibe  
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.
hmwangi
6
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

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

404. The page does not exist

Mladen Rakic
64240
Mladen Rakic  
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)
Jose Francisco Casado Fernandez
4093
Jose Francisco Casado Fernandez  
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.
Icham Aidibe
10391
Icham Aidibe  

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.

Mohamad Zulhairi Baba
7829
Mohamad Zulhairi 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++)
Alain Verleyen
Moderator
33626
Alain Verleyen  
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.
To add comments, please log in or register