MY Code is repainting

 

hello everybody, my code repainting but i'm not use future bars, why its happen???


            
 
Milad Ahmadpanah:

hello everybody, my code repainting but i'm not use future bars, why its happen???

It starts from the current candle, since the current candle is not closed, it may repaint.

Try changing your logic and ignore current candle until it is closed, maybe by starting your loop from 1 instead of 0.

//---
   for(int i=1;i<limit;i++)
 

You have two global variables flag_up and flag_down. The pre-condition is that those variables are from the previous bar.

  1. You are counting up, therefor using future values. Even if you count down, you violate the pre-condition when you process bar zero more than once.
  2. This means, as is, you can't process bar zero (the forming one,) more than once, ever.
    1. You can put them in a buffer so you can get the previous bar value.
    2. Only process bar zero once (or none.)
    3. Save and restore them when processing bar zero. Example at How to predict RSI Level??? - MQL4 programming forum - Page 2 #11 Lines 131 & 193
    4. Use an array (size 2) and use iNS=rates_total-1-iBar, iCur=iNS%2, iPre=!iCur; var[iCur]=function(var[iPre]);. No save/restore required.
 

Don't double post! Don't triple post You already had this thread open.
          General rules and best pratices of the Forum. - General - MQL5 programming forum

I answered your question already. #2

   if(prev_calculated==0) limit = rates_total-2;
   else limit = rates_total - prev_calculated;
//---
   for(int i=limit-1; i>=0; i--)
⋮
   return(rates_total-1);
is also reprocessing bars.
          How to do your lookbacks correctly #9 - #14 & #19
 
William Roeder:

Don't double post! Don't triple post You already had this thread open.
          General rules and best pratices of the Forum. - General - MQL5 programming forum

I answered your question already. #2

is also reprocessing bars.
          How to do your lookbacks correctly #9 - #14 & #19

Sorry, im new to the forum

its never repeatet it

 
Milad Ahmadpanah:

hello everybody, my code repainting but i'm not use future bars, why its happen???

make sure, all var i,  use i+1

example:

arrup[i+1] = low[i+1];

do all var i