Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difference between State.DataLoaded and State.Historical

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

    Difference between State.DataLoaded and State.Historical

    Hi everyone,
    I've already read the guide regarding this two states, but I don't have it clear enough...
    Lets suppose I want to add two EMA that will be used in my script in OnBarUpdate section, so I write the following code in State.DataLoaded. In that way, the script works as expected, but, is it also necessary or recommended to set them in State.Historical? Will it suppose any difference?

    .......
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, 5);
    EMA2 = EMA(Close, 10);
    }​

    else if (State == State.Historical)
    {
    EMA1 = EMA(Close, 5);
    EMA2 = EMA(Close, 10);​
    }​
    ......

    Thanks in advance for your support.

    #2
    Hello germanf,

    Thanks for your post.

    The best practice is to instantiate indicators in OnStateChange() when the State == State.DataLoaded. State.DataLoaded will be called one time after ALL data series have been loaded. This is the state where you should use logic that needs to access data-related objects like Bars, Instruments, BarsPeriod, TradingHours or instantiating indicators.

    State.Historical is called once an object is processing historical data. For example, this state is called once when running an object in real-time. This is the state that notifies you that the object is processing historical data.

    See this help guide page for more information: https://ninjatrader.com/support/help...tatechange.htm

    Let me know if I may further assist
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi Brandon, thanks for your prompt response.

      So, if I understood well, instantiating the indicators only have to be done in State.DataLoaded.
      Instantiating them in State.Historical is not necessary, no matter working in real time or if I just want to have a look what the indicators have done in the loaded bars of the chart.

      Then, my code would be just like this...

      else if (State == State.DataLoaded)
      {
      EMA1 = EMA(Close, 5);
      EMA2 = EMA(Close, 10);
      }​​
      protected override void OnBarUpdate()
      {
      if (EMA1 < EMA2){ do something }
      }

      Am I right?

      Comment


        #4
        Hello germanf,

        Thanks for your note.

        That would be correct. Indicators would only need to be instantiated in State.DataLoaded as seen in the code you shared.

        Let me know if you have any further questions.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        368 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        571 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X