FYI: State.DataLoaded is skipped for BarsTypes

**Just FYI: After some debugging I found BarsType does not enter State.DataLoaded.

AI notes:** The official state reference documents a full pipeline (SetDefaults → Configure → Active → DataLoaded → Historical → Transition → Realtime → Terminated), but that page is generic across all NinjaScript object types, not BarsType-specific. A NinjaTrader support forum post, based on their own team’s direct testing of a custom bar type, states plainly that State.DataLoaded is not considered in a custom bar type — their observed sequence went straight from Configure to Active to OnDataPoint. Treat any one-time setup you need as not guaranteed to have a home in OnStateChange for this object type — a lazy/defensive init check (e.g. “if this collection is still null, initialize it now”) at the top of OnDataPoint is more reliable than betting on a specific state firing. ninjatrader

2 Likes

No, State.DataLoaded does not pertain to bar types. The explanation at https://ninjatrader-live.ninjatrader.com/support/helpguides/nt8/NT%20HelpGuide%20English.html?understanding_the_lifecycle_of.htm is specific to indicators and strategies. See this explanation which makes it quite clear which states apply to bar types (Active etc. not data loading states): NinjaTrader 8 .

Additionally you should look at the provided examples for bar types like Minute or Tick and see how they work - they show you the proven pattern for managing state.

Your AI is doing you a disservice here - you’ll want to look at the real examples and documentation.

Thanks for pointing that out. OnStateCahnge() is very clear about it, and corroborates what you’ve stated:

After State.Configure, each type of NinjaScript type has its own state management system which can be classified under two categories:

•Active state: State.Active

•Data Processing states: State.DataLoaded, State.Historical, State.Transition, State.Realtime

+----------------------------+---------------------------+
| NinjaScript Type           | State Management System  |
+----------------------------+---------------------------+
| AddOns*                    | Active state              |
| BarTypes                   | Active state              |
| ChartStyles                | Active state              |
| DrawingTools               | Active state              |
| Indicators                 | Data Processing states    |
| ImportTypes                | Active state              |
| Market Analyzer Columns    | Data Processing states    |
| OptimizationFitnesses      | Active state              |
| Optimizers                 | Active state              |
| PerformanceMetrics         | Active state              |
| ShareServices              | Active state              |
| Strategies                 | Data Processing states    |
| SuperDOM Columns           | Active state              |
+----------------------------+---------------------------+

To summarize, BarsTypes transitions: State.SetDefaults → State.Configure → State.Active → OnDataPoint()