Summation with for to next loop

Forums ProRealTime English forum ProBuilder support Summation with for to next loop

  • This topic has 16 replies, 5 voices, and was last updated 3 years ago by avatarVN.
Viewing 15 posts - 1 through 15 (of 17 total)
  • #78095

     

    I’d like to achieve the same result with the following simple ‘for next loop’instead using ‘summation’ but there is no output using the ‘for next loop’

     

    #78097

    The last 5 bars are 0-4, not 1-5 (these are the previous 5 bars).

    The problem could be the value returned by LFC, too big to be displayed.

    On DAX that would be about 62000 (5 * 12400), but your are not resetting it to 0 at the beginning, so within a few bars that could become a huge number!

    #78098

    Thank you so much for your super fast response!
    You are right! I added one reset ahead of the for next loop and it worked.

     

    #78101

    Vagus_Lux – please use the ‘Insert PRT Code’ button when putting code in your posts to make it more readable for others. I have tidied up your posts for you. 🙂

    I am guessing that Robert is posting from his phone otherwise he would have done the same!

    #78103

    AhAhAh…. I am indeed posting from my phone!

    #84509

    I have a quick question there.

    In the example code below, I do have the following query

    is close[28] inside the for statement 28 candles from close[0] or 28 candles from “i” or “close[i]” ?

    Kind Regards,

     

    #84510

    From CLOSE[0], it is constant through the loop.

    To be from i you’ll have to write 28+i within brackets.

    1 user thanked author for this post.
    #121845
    VN

    Hi Roberto, I am trying to count the total number of times an event took place in a given timeframe of my chart.

    For example I am counting the number of times RSI crossed above 70 and I want that calculation to be applied to any timeframe so from the beginning of time to end of time loaded.

    I don’t know how to set the beginning and end of time in a FOR NEXT loop.

    Any eloquent way that this can be achieved?

     

    #121864

    The beginning is always BARINDEX=0.

    BARINDEX is the progressive numeber of bars, so you need to do is, from current bar to zero:

    But… all the above is not necessary, since any indicator ALWAYS starts from the beginning, so all you want to do is to sum any occurrence of the event:

     

     

    1 user thanked author for this post.
    avatar VN
    #132165
    VN

    hi @ robertogozzi, i want to modify the code such that it counts how many times the RSI crossed over 70 in the last 30 bars. So the count will be a rolling count between period zero until 30 periods ago. Can this be done?

    #132166

    There you go:

    X will retain the value you are looking for.

    from current bar [0] up to 30 bars ago [30], it’s 31 bars.

    There’s not need to use loops here.

    #132173
    VN

    thanks Roberto! I did not think of using summation in this context, but that works nicely!

    I used this code to also count the number of times the current close was less than prior close, but that doesn’t return the right answer.

    Have i done something wrong?

    #132177

    What you have coded will compare the current close to the previous close and then the 2nd to last  close to the one before that and then the third to last close to the one before that…. and so on and so on.

    If you want to compare the latest close to the 30 previous candles then you will need a loop.

     

    #132183
    VN

    thanks vonasi..

    the above is part of a wider problem i am trying to code, but with not much success.

    I am trying to count the number of times the price changed direction in a specified period e.g. last 10 candles, in other words the number of times the candle colour changed in the last 10 candles.

    so for example, if the first 3 candles were green, but the forth was red, then the counter = 1 as that is the 1st time the close went below prior close.

    then candle 5 and 6 were both green then the counter = 2 since the close at candle 5 reversed  from red (4th candle) to green (5th candle). I don’t want to count the candles when the colour is same, only when they reverse.

    #132184

    There you go.

Viewing 15 posts - 1 through 15 (of 17 total)

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