• 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 Mike3238, Today, 07:09 PM
    0 responses
    1 view
    0 likes
    Last Post Mike3238  
    Started by sambo81, Today, 06:57 PM
    0 responses
    2 views
    0 likes
    Last Post sambo81
    by sambo81
     
    Started by erichuff, Today, 04:53 AM
    1 response
    26 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by stevenev1, Today, 01:43 PM
    0 responses
    8 views
    0 likes
    Last Post stevenev1  
    Started by shinuvu, Today, 11:05 AM
    3 responses
    18 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Working...
    X