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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      41 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X