How to make a loop

Forums ProRealTime English forum ProBuilder support How to make a loop

Viewing 11 posts - 1 through 11 (of 11 total)
  • #15464

    Hi All,

    How do I loop the below sample code?

    c1 = low < Low[1]  and  high > high[1]
    c2 = low < Low[2] and  high > high[2]
    c3 = low < Low[3] and  high > high[3]

    c4 = etc….

     

    does not seem to loop it correctly.

    Any thoughts?

    #15469

    >> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<

    Your loop statement is ok, but you are not couting how much time your condition on line 5 is true. You should set it as a variable and count how much time this variable is returned true by storing this count in another variable.

    #15515

    Thank you Nicolas.

    I am a novice at programming so you assistance is greatly appreciated.

    How do I set line 5 as a variable to count how much time this variable is returned true and how do I sort this count in another variable?

     

    #15533

    You can do it this way:

    x is your variable condition, if its true, then increment your new “count” variable. That’s all.

     

    #31104

    Good day all. I’m new to Prorealcode and want your help with what should be a “fairly” simple loop! this is the requirement:

    for a stock, loop from the first bar (index 0) bar to the 5th bar (index 4) and determine if the stochastic at the previous bar (index n+1) is less than or equal to 50 (or 20) and the next bar (index n) is greater than or equal to 50 (or 20). Please see my code below. I’m not sure why its not working like it should.

     

    #31106

    @donaldthetrader

    You could also code the loop like this: (always a better idea to declare your indicator outside of the loop). Since you want to test a crossover of the stochastic, we embed the indicator declaration into a boolean variable to test the cross.

     

    #31118

    @Nicolas, thanks for the quick reply! update the code and see the outcome…

    #31130

    @nicolas, i’ve tried the above code. I’m not looking for a %D and %K crossover i simply want to know if the %K has ever gone below 50 or 20 and now moving over 50 or 20 over “n” periods. In this case the last 5 bars.

    #31138

    and this is exactly what it does (example attached).

    for 5 bars lookback instead of 3, the code need to be modified though:

     

    #31152

    Nice!. Thanks @Nicolas

    #31248

    @ Nicolas, hope you are well..

    Pls desperately need your input on this topic: https://www.prorealcode.com/topic/previous-years-highest-high-and-lowest-lows/

    Thanks!

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

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