What’s the correct way of getting previous values of an indicator?

Forums ProRealTime English forum ProBuilder support What’s the correct way of getting previous values of an indicator?

Viewing 4 posts - 1 through 4 (of 4 total)
  • #196898

    Hi all

    I’m trying to get the values of previous bars of an indicator, and this is what I’m trying to do:

    ema100 = ExponentialAverage[100](close)

    ema100_20barsbefore = ema100[20]

    Is this correct?

    Also how do I check if an indicator actually has a value at a certain point? Like at the start of the day maybe some indicators don’t have values yet, and if I do indicator[20] its value maybe invalidate because of that.

     

    #196918

    Your code is correct.

    I am not sure I understood your second question. If you check your chart you will spot the value retained now by any variable and the one of the 20th previous bar. Is this what you meant?

     

    1 user thanked author for this post.
    #196981

    Thanks <span class=”bbp-author-name”>robertogozzi</span>

    What I mean by 2nd question is that, sometimes an indicator may not have values.

    For example,  ExponentialAverage[100](close) don’t have values for the initial bars, not sure if it’s exactly 100 bars or some other value. If you move your mouse cursor to the bars in the beginning, in the values displayed(open, close etc) it doesn’t have a value. Not sure if this is something I’m doing wrong.

    And the weird thing is, when I try make a simple indicator that checks if some indicator has value, such as ema100 > 0, it correctly detects that at first the indicator doesn’t have value for certain number of bars. But when I try to use the exact checking logic to do backtest, it would generate orders at bars where clearly there’s no indicator value.

     

    #197050

    I think this is due to the fact that ProOrder and ProBackTest preload form 2000 bars (default)  up to 10K bars. Try using this line at the beginning of your code:

     

    1 user thanked author for this post.
Viewing 4 posts - 1 through 4 (of 4 total)

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