Programming an indicator and working with the future

 

I have programmed an indicator with graphical objects.

It calculates the values from the past and the "last state" is very important for the working on...

But my rules for the past didn't work in the future

This it the main-loop in the chart function is

   int    counted_bars=IndicatorCounted();
   int    limit=Bars-counted_bars;

                  //-1
   for(i=limit-2; i>=0; i--)  //von der Vergangenheit her soll berechnet werden
   {
    if((High[i-1]>=Open[i-2] && High[i-1]>=Close[i-2]) && (Low[i-1]<=Open[i-2] && Low[i-1] <=Close[i-2]))
    {   
      ...
     }
    }    
 
  1. High[i-1] is NOT in the past, that's in the future.
    if((High[i-1]>=Open[i-2]...
    If you want last bars high >= previous bars open that would be
    if((High[i+1]>=Open[i+2]...

  2.    int    counted_bars=IndicatorCounted();
       int    limit=Bars-counted_bars;
       for(i=limit-2; i>=0; i--)
    This is also wrong - When IndicatorCounted == Bars-1, every case except the initial run, your loop does nothing. Since you are looking up to two bars back you need
       int    counted_bars=IndicatorCounted(); #define DRAWBEGIN 2
       if (counted_bars < DRAWBEGIN) counted_bars = DRAWBEGIN; // Don't look past H[Bars-1]
       int    limit=Bars -1 -counted_bars;
       for(i=limit/*-2*/; i>=0; i--)
Reason: