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
Thank you GumRai,
It should be j--. and it is the error.
Somehow I type ++ and could no way catch it.
SCFX
scfx: I think my approach is correct and the code is quite straight forward. | Just the opposite. You have two or three nested loops. but break only exits the inner most one. Find, your first condition, break out of that loop. Start the next loop and find the next... |
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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