Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 alifarahani, Today, 09:40 AM
    6 responses
    38 views
    0 likes
    Last Post alifarahani  
    Started by Waxavi, Today, 02:10 AM
    1 response
    18 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by Kaledus, Today, 01:29 PM
    5 responses
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Waxavi, Today, 02:00 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by gentlebenthebear, Today, 01:30 AM
    3 responses
    17 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X