
3505 
for(int j=i+5;j>=i;j++) //look back 5 bar I'm not sure what you are trying to achieve, but the above is a bad loop. You don't look back a maximum of 5 bars, you START your look back at i + 5. j is initialised at a value higher than i and then is increased at each pass. Therefore the condition j>=i will always be true 


Hi Everyone,
I am writing an indicator based on 2 variables.
The rule is that: Whenever variable1 (take value 0 and 1) turns to 1 from 0. find the very first bar (including this turning bar) that has variable1 =1 and varibale2=100. It is like looking back, and I choose to look back 5 bars.
My approach is below:
I think my approach is correct and the code is quite straight forward. But still it doesn't work correctly. It assign found[k] to the first condition met even though it is 20 bar away from the turning bar. So the condiiton 5 bar look back is ignore, somehow.
Any help is very much appreciated.
SCFX