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 Unsuitable, Today, 08:41 AM
    0 responses
    1 view
    0 likes
    Last Post Unsuitable  
    Started by newdill, Today, 07:54 AM
    0 responses
    5 views
    0 likes
    Last Post newdill
    by newdill
     
    Started by qwertyjjj, Today, 06:52 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by NeverDownMoney, 09-25-2020, 09:40 PM
    1 response
    15 views
    0 likes
    Last Post NT-Roland  
    Started by wjadevries, Today, 04:21 AM
    1 response
    12 views
    0 likes
    Last Post wjadevries  
    Working...
    X