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 elirion, Yesterday, 09:32 PM
    0 responses
    6 views
    0 likes
    Last Post elirion
    by elirion
     
    Started by cre8able, Yesterday, 09:15 PM
    1 response
    8 views
    0 likes
    Last Post bltdavid  
    Started by cummish, Yesterday, 08:43 PM
    0 responses
    14 views
    0 likes
    Last Post cummish
    by cummish
     
    Started by Option Whisperer, Yesterday, 07:58 PM
    4 responses
    21 views
    0 likes
    Last Post Option Whisperer  
    Started by ETFVoyageur, 05-07-2024, 07:05 PM
    13 responses
    87 views
    0 likes
    Last Post ETFVoyageur  
    Working...
    X