Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help Needed: CS0103 Error with IsHistorical in NinjaTrader Indicator

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

    Help Needed: CS0103 Error with IsHistorical in NinjaTrader Indicator

    Hi everyone,

    I'm working on developing a custom indicator in NinjaTrader and I've run into a couple of CS0103 errors stating that the name IsHistorical does not exist in the current context.
    Here are the error details:

    ​Error Code: CS0103
    File: EnhancedLiquidityIndicator.cs
    Line: 72
    Column: 21
    Description: The name 'IsHistorical' does not exist in the current context

    And another similar error:

    Error Code: CS0103
    File: EnhancedLiquidityIndicator.cs
    Line: 123
    Column: 17
    Description: The name 'IsHistorical' does not exist in the current context

    Here are the relevant parts of my code:

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    // Default settings
    }
    else if (State == State.DataLoaded)
    {
    // Initialization
    vwap = new Series<double>(this);
    if (IsHistorical) // Error occurs here
    {
    string logFilePath = NinjaTrader.Core.Globals.UserDataDir + "LiquidityScores.csv";
    System.IO.File.WriteAllText(logFilePath, "DateTime,LiquidityScore\n");
    }
    }
    }

    protected override void OnBarUpdate()
    {
    // Code logic
    if (IsHistorical && Bars.IsFirstBarOfSession) // Error occurs here
    {
    string logFilePath = NinjaTrader.Core.Globals.UserDataDir + "LiquidityScores.csv";
    System.IO.File.AppendAllText(logFilePath, $"{Time[0]},{liquidityScore}\n");
    }
    }

    How can I correctly check if the context is historical within the OnStateChange and OnBarUpdate methods?
    Is there a specific property or method I should be using instead of IsHistorical?

    Any guidance would be greatly appreciated.

    Thank you!
    António​

    #2
    Welcome to the forums!

    Use State.Historical, like this,

    if (State == State.Historical)

    More info here.

    Comment


      #3
      Thank you very much.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      595 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      343 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      556 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      554 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X