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 aslane, 02-04-2017, 11:19 AM
      5 responses
      1,006 views
      1 like
      Last Post eminimagic  
      Started by flonkle, Today, 01:19 AM
      5 responses
      36 views
      0 likes
      Last Post NinjaTrader_LuisH  
      Started by Skechers, 06-17-2024, 12:57 PM
      4 responses
      12 views
      0 likes
      Last Post Skechers  
      Started by WHICKED, 06-27-2023, 12:07 PM
      85 responses
      869 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by sofortune, 06-13-2024, 02:31 AM
      3 responses
      27 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Working...
      X