Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 sofortune, Today, 02:31 AM
      0 responses
      6 views
      0 likes
      Last Post sofortune  
      Started by sofortune, Today, 01:55 AM
      1 response
      5 views
      0 likes
      Last Post sofortune  
      Started by cls71, Today, 01:37 AM
      0 responses
      5 views
      0 likes
      Last Post cls71
      by cls71
       
      Started by WHICKED, 06-27-2023, 12:07 PM
      63 responses
      763 views
      1 like
      Last Post Leeroy_Jenkins  
      Started by rtwave, Today, 12:10 AM
      0 responses
      5 views
      0 likes
      Last Post rtwave
      by rtwave
       
      Working...
      X