• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Clarification on AddChartIndicator

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Clarification on AddChartIndicator

    Hi,

    The AddChartIndicator help states

    If you are adding an indicator which is dependent on the correct State of the indicator,
    What exactly it means by correct State? How do I know which indicator have such dependency? Could someone provide a more concrete explanation?

    also is this code equal to the suggested code from help?

    Code:
    private SMA _sma;
            protected override void OnStateChange() {
                if (State == State.DataLoaded){
                    // Charts a 20 period simple moving average to the chart
                    _sma = SMA(20);
                    AddChartIndicator(_sma);
                }
            }
    
            protected override void OnBarUpdate() {
                // call SMA() historically to ensure the indicator processes its historical states as well
                double sma = _sma[0];
            }

    #2
    Hello tolisss,

    Thanks for opening the thread with your question.

    I believe you are referring to this noted Tip in the help guide:
    Tip: If you are adding an indicator which is dependent on the correct State of the indicator, you will need to ensure that you are also calling the indicator from the strategy in OnBarUpdate(), otherwise your indicator will only process in State.RealTime for performance optimizations.
    This tip refers to allowing the calling indicator to process historical data. I have created a demonstration below.

    Demo - https://www.screencast.com/t/oQhPAZjMlRU

    Your code will have the same result. You can perform the same test as I have on a custom indicator to verify.

    Please let me know if I can be of further help.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Orion1504, Today, 09:52 AM
    0 responses
    13 views
    0 likes
    Last Post Orion1504  
    Started by Jimmy73, Today, 09:42 AM
    2 responses
    6 views
    0 likes
    Last Post Jimmy73
    by Jimmy73
     
    Started by Bmatarese, Today, 08:57 AM
    4 responses
    10 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by EnveousColnago, 01-09-2020, 09:09 AM
    3 responses
    28 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by Polo Trader, 01-21-2020, 03:28 PM
    6 responses
    64 views
    0 likes
    Last Post bltdavid  
    Working...
    X