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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #196898 quote
    xbldevbbxbldevbb
    Participant
    New

    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 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    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?

    xbldevbb thanked this post
    #196981 quote
    xbldevbbxbldevbb
    Participant
    New

    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 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    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:

    DEFPARAM PreLoadBars = 0   //10000 max allowed
    xbldevbb thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
xbldevbb @xbldevbb Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzirobertogozzi
4 years, 2 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 07/06/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...