Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate Question

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

    OnBarUpdate Question

    Hi

    I've written the simplest of indicators as follows:

    protected override void OnBarUpdate()
    {

    if(insert condition here)
    {
    PlaySound("Alert1.wav");
    }

    It worked perfectly yesterday but today it won't work and I'm getting the following error message:
    Error on calling 'OnBarUpdate' method for indicator xxx on bar 0: Object reference not set to an instance of an object.

    I'm at a loss here as it compiles fine and worked like a charm yesterday.

    #2
    Hello laocoon,

    Thanks for your post.

    Without seeing all of the code it would be difficult to advise.

    What we suggest is using Print statements to debug your code. You would use print statements before and after lines of code to narrow down when the error occurs. Print statements send their output to the new>output window so make sure that is open first. Here is a link to debugging tips: https://ninjatrader.com/support/foru...ead.php?t=3418

    Comment


      #3
      Thanks Paul but that's the whole code (the rest is the standard code that's there when you create any Ninja indicator/strategy, see below). Also, as I mentioned, there should be nothing to debug as the code worked perfectly yesterday.

      [Description("Enter the description of your new custom indicator here")]
      public class Test: Indicator
      {
      #region Variables
      // Wizard generated variables
      private int myInput0 = 1; // Default setting for MyInput0
      // User defined variables (add any user defined variables below)
      #endregion

      /// <summary>
      /// This method is used to configure the indicator and is called once before any bar data is loaded.
      /// </summary>
      protected override void Initialize()
      {
      CalculateOnBarClose = false;
      AllowRemovalOfDrawObjects = true;
      Add(PeriodType.Minute, 5);
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {

      if(insert condition here)
      {
      PlaySound("Alert1.wav");
      }


      }

      Comment


        #4
        Hello,

        Thanks for your post.

        Please note that you are posting in the NT8 Strategy forum. Your code appears to be NT7 based.

        You are adding a 5 minute data series which means you have created a multi time frame script. I understand you do not wish to show your code in: if(insert condition here) so all we can do is to advise that you review: NT8:

        NT7: https://ninjatrader.com/support/help...nstruments.htm

        Pay attention to the CurrentBars check as well as understand that each data series will call OnBarUpdate which means that any references such as High[1] in one case would point to the High[1] of the previous bar of the chart bars and in the other instance High[1] would point to the previous bar of the 5 minute data series.

        If you are unable to resolve, you are welcome to write into PlatformSupport[at]NinjaTrader[dot]Com, mark the e-mail Atten: Paul and include a link to this thread and include your complete code. While we do not provide debugging services I can take a quick look to suggest a direction for you to resolve.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        72 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X