For loop logic question...

 

To get MT to post arrows for past indication of some event I would do something like this...

for (i=0; i<WindowBarsPerChart() ;i++)

      {
            
           // 2 down bars below 0   
            if (( ExtBuffer0[i] < 0
               && ExtBuffer3[i]-ExtBuffer4[i]<ExtBuffer3[i+1]-ExtBuffer4[i+1] 
               && ExtBuffer3[i+1]-ExtBuffer4[i+1]<ExtBuffer3[i+2]-ExtBuffer4[i+2] 
               && ExtBuffer3[i+2]-ExtBuffer4[i+2]>ExtBuffer3[i+3]-ExtBuffer4[i+3]
               && Volume[0]>1 && !UpTrend) 
               
            
            {                  
               ExtMapBuffer2[i] = High[i] + nShift*Point;   

            }
             
           // 2 up bars above 0   
          else if ( ExtBuffer0[i] > 0
               && ExtBuffer3[i]-ExtBuffer4[i]>ExtBuffer3[i+1]-ExtBuffer4[i+1] 
               && ExtBuffer3[i+1]-ExtBuffer4[i+1]>ExtBuffer3[i+2]-ExtBuffer4[i+2] 
               && ExtBuffer3[i+2]-ExtBuffer4[i+2]<ExtBuffer3[i+3]-ExtBuffer4[i+3]
               && Volume[0]>1 && !DownTrend)
                                       
            {

            ExtMapBuffer1[i] = Low[i] + nShift*Point;             

            } 
 


      }

This all worked well, until I wanted to make it add a variable to the condition. For example, let's say I wanted to add...

...

{
     ExtMapBuffer2[i] = High[i] + nShift*Point;             
     strFirstIndication = "Possible Downtrend";
     ObjectSetText("lblSomeLabelOnTheChart", strFirstIndication, 10, "Arial", Black);
}

This is where I had a hair pulling moment. My arrow indicator was correct, while my string variable wasn't always. After much cursing, I finally came to the conclusion that my loop analyzed the chart from front to back, and therefore it was giving me the first chronological indicator which was available to it. To fix this, I changed my loop to...

  for (i=WindowBarsPerChart(); i>0; i--)

      {
         .......
      

... which now reads it correctly.

But here is my issue:

In the first for loop which went backwards, I would get signal generation while the bar was being created -- I could tell because even though the string was incorrect, arrows were still being generated on the chart. For example, if the 2nd bar was positive but then went negative, it would show me the positive indicator, and then take it away once it went negative. The second for loop works correctly; however, it does not show the signal while it is being generated... it will only show the signal after the bar is complete. How do I fix the second loop so that it will show the signal as it is being created?

Thank you.

 
drop
 && Volume[0]>1 
 

Well that figures. I spent 8-10 hours trying to troubleshoot this thing before I gave in and posted. Now, 15 minutes after my post I find the answer. My loop should've been...

     for (i=WindowBarsPerChart(); i>=0; i--)

Sigh.