For with IF statement bugged as far as I can see

Forums ProRealTime English forum ProOrder support For with IF statement bugged as far as I can see

Viewing 3 posts - 1 through 3 (of 3 total)
  • #211748

    Hi All,

    I have come across this a few times on different occasions  but couldnt work out why code was failing, this time around I “graph” the variables so I could check them on each candle. So what I am seeing is that when “BarsToCheck” is set to 10 the IF statement is found to be true and the code goes on to set s2 to TRUE, however if I then set BarsToCheck to 15 to include more candles it finds the IF statement to be false and not run the rest of the code?

    If the condition exists in 10 candles it has to exist in 15 right? I have included a screen grab hovering over the same candle so that you can see that the IF statement fails(s2 is not set to TRUE/1) if it has to check more candles(even though the selection is bigger and the result should be the same in my eyes)..

     

    #211750

    FYI I just figured this out, and now I feel silly but I will leave it up for anyone ELSE (excuse the pun) who runs in to this.

    It was because I was using an ELSE clause in my code block. As in if it finds the condition to be true in on the Nth candle it then overwrites that with the remaining for loops. I have set the s2 variable to false to begin with outside the loop and now there isnt an issue as it doesnt get overwritten:

     

    1 user thanked author for this post.
    #211764

    Yes of course, the loop will go the end as long as you don’t BREAK it, so your s2 variable could be set to 0 even if you have set it to 1 previously in the loop.

    Your first version could be modified with a BREAK at first iteration that found that your Close[i]>ema50 is found:

     

Viewing 3 posts - 1 through 3 (of 3 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login