Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on Calling OnBarUpdate Method

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

    Error on Calling OnBarUpdate Method

    I am running a strategy which calls an atm when it executes. The strategy executes as it should the first time it runs but won't execute a second time unless disable it and renable it. Here is the text I am getting in the output file. I am sending comments to the file at various points in the execution so I can tell what is going on. Here's some of that text:

    1
    RC_ATM Code is entering Long Entry Test.
    1
    RC_ATM Code is entering Short Entry Test.
    RC_ATM 1
    RC_ATM Code has entered the status print out.
    1/17/2012 7:21:16 AM M = 143.571428571428 V = 357
    2
    RC_ATM Code is entering Long Entry Test.
    2
    RC_ATM Code is entering Short Entry Test.
    RC_ATM 2
    RC_ATM Code has entered the status print out.
    1/17/2012 7:21:19 AM M = 130.071428571428 V = 25
    3
    RC_ATM Code is entering Long Entry Test.
    3
    RC_ATM Code is entering Short Entry Test.
    RC_ATM 3
    RC_ATM Code has entered the status print out.
    1/17/2012 7:23:00 AM M = 136 V = 184
    4
    RC_ATM Code is entering Long Entry Test.
    4
    RC_ATM Code is entering Short Entry Test.
    RC_ATM 4
    RC_ATM Code has entered the status print out.
    1/17/2012 7:23:49 AM M = 123.142857142857 V = 95
    5
    RC_ATM Code is entering Long Entry Test.
    5
    RC_ATM Code is entering Short Entry Test.
    RC_ATM 5
    RC_ATM Code has entered the status print out.
    1/17/2012 7:25:27 AM M = 133.357142857143 V = 177
    6
    RC_ATM Code is entering Long Entry Test.
    6
    RC_ATM Code is entering Short Entry Test.
    **NT** GetAtmStrategyMarketPosition() method error: AtmStrategyId 'RC_ATM' does not exist
    6 Executing RC_ATM_Sell
    **NT** Submitting order with strategy 'RenkoCrawlMod3opencodeATM/9c27f9501e9145e9af2ba20abda99aaa'
    **NT** Error on calling 'OnBarUpdate' method for strategy 'RenkoCrawlMod3opencodeATM/9c27f9501e9145e9af2ba20abda99aaa': Object reference not set to an instance of an object.
    1/17/2012 7:27:31 AM M = 134.428571428571 V = 147
    1/17/2012 7:27:36 AM M = 131.428571428571 V = 33
    Near the bottom of the text above is the Error statement I am trying to figure out. NT Error on calling OnBarUpdate method for strategy.....Object reference not set to an instance of an object.

    What should I be looking for in the code to fix? This code is something I have used over and over again, but this is the first time it runs once then errors out?

    Thanks
    DaveN

    #2
    DaveN, that would normally mean you attempt to access an empty object instance, so you're missing a check for null in one of your conditions -



    One potential way to find the offending code section, is try / catch -

    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks Bertrand,
      I did find the problem. I was referencing a DataSeries that I did not initialize properly (new DataSeries(this). Thanks for the advice and reference information. I need to figure out how to do a better job of debugging, and the try/catch may help.
      DaveN

      Comment


        #4
        Glad you could resolve it DaveN!
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I am also having the same problem.

          the error code is:

          05/03/2013 12:20:00 System.NullReferenceException: Object reference not set to an instance of an object.
          at NinjaTrader.Strategy.DivergenceADXR.Utils.pivotUp( IDataSeries input, Int32 barsLookBack, Int32 startAt, Int32 leftSideBars, Int32 rightSideBars, Int32 instance)
          at NinjaTrader.Strategy.DivergenceADXR.OnBarUpdate()


          I get this with my try-catch to debug the code.

          Looks like it is in this part of the code, which is outside OnBarUpdate()

          #region pivot
          public static class Utils
          {
          /// <summary>
          /// look for a pivot. a pivot is the lowest/highest point *between* a left side and right side bar.
          /// input : input data for pivot lookup
          /// barsLookBack : max bars to look bar for pivot lookup
          /// startAt : bars ago to start pivot lookup
          /// leftSideBars : pivot left bars to analyse
          /// rightSideBars : pivot right bars to analyse
          /// instance : instance of pivot to fetch. 1st instance is the nearest to current bar
          /// hiLo : 1 for lookup of pivots going up, -1 for pivots going down
          /// Return : pivot bars ago, or -1 if not found.
          /// </summary>
          public static int pivot(IDataSeries input, int barsLookBack, int startAt, int leftSideBars, int rightSideBars, int instance, int hiLo)
          {
          if ( hiLo == 1 )
          return pivotUp(input, barsLookBack, startAt, leftSideBars, rightSideBars, instance);
          else if ( hiLo == -1 )
          return pivotDown(input, barsLookBack, startAt, leftSideBars, rightSideBars, instance);
          return -1;
          }

          private static int pivotUp(IDataSeries input, int barsLookBack, int startAt, int leftSideBars, int rightSideBars, int instance)
          {
          for ( int barsAgo=startAt ; barsAgo <barsLookBack ; barsAgo++ )
          {
          int pivot = barsAgo + rightSideBars;
          int right = pivot - rightSideBars;
          int left = pivot + leftSideBars;

          if ( input[left] > input[pivot] && input[pivot] < input[right] )
          {
          double low = input[right];
          for (int idx = right; idx <= left; idx++)
          if ( input[idx] < low )
          low = input[idx];

          if ( input[pivot] == low && --instance == 0 )
          return pivot;
          }
          }
          return -1;
          }


          private static int pivotDown(IDataSeries input, int barsLookBack, int startAt, int leftSideBars, int rightSideBars, int instance)
          {
          for ( int barsAgo=startAt ; barsAgo <barsLookBack ; barsAgo++ )
          {
          int pivot = barsAgo + rightSideBars;
          int right = pivot - rightSideBars;
          int left = pivot + leftSideBars;

          if ( input[left] < input[pivot] && input[pivot] > input[right] )
          {
          double high = input[right];
          for (int idx = right+1; idx <= left; idx++)
          if ( input[idx] > high )
          high = input[idx];

          if ( input[pivot] == high && --instance == 0 )
          return pivot;
          }
          }
          return -1;
          }
          }
          #endregion


          Please advise.

          Comment


            #6
            Hi Bertrand,

            I get a similar error in my Output window, but in the context of using BarsSinceEntry() function. Strategy is applied to an ES chart where I add another instrument in the Initialize() function.

            BarNr: 37; ABC_signal is 1 and position is: Flat; Enter Long;
            BarNr: 38; Position is: Long;
            **NT** Error on calling 'OnBarUpdate' method for strategy 'ESandABC/cc18ed2d3faa447284ae8f8a619d7e33': You must use the overload that has a 'BarsInProgress' parameter when calling the BarsSinceEntry() method in the context of a multi-time frame and instrument strategy.

            Switching to the 3rd BarsSinceExit overload, similar to the below:

            BarsSinceEntry(BarsInProgress,"sName",1)

            will always produce BarsSinceEntry = 0 even if position is long:

            if (BarsInProgress == 0) {
            ...
            Print("BarNr: " + CurrentBar + "; Position is: " + Position.MarketPosition + ";" + " BarsSinceEntry is: " + BarsSinceEntry(BarsInProgress,"sName",1));
            // always produces:
            BarNr: 38; Position is: Long; BarsSinceEntry is: 0
            BarNr: 39; Position is: Long; BarsSinceEntry is: 0
            BarNr: 40; Position is: Long; BarsSinceEntry is: 0
            BarNr: 41; Position is: Long; BarsSinceEntry is: 0
            BarNr: 42; Position is: Long; BarsSinceEntry is: 0
            BarNr: 43; Position is: Long; BarsSinceEntry is: 0
            BarNr: 44; Position is: Long; BarsSinceEntry is: 0
            BarNr: 45; Position is: Long; BarsSinceEntry is: 0
            BarNr: 46; Position is: Long; BarsSinceEntry is: 0
            ...
            }
            Can you please let me know if you have a suggestion of how to correct this - how can you have BarsSinceEntry 0 while position is Long?
            Thanks
            Last edited by andrei.reiand; 07-28-2015, 05:21 PM.

            Comment


              #7
              Hello andrei.reiand,

              Thank you for writing in. Calling BarsSinceEntry(BarsInProgress,"sName",1) is requesting the BarsSinceEntry of the entry named "sName" before the last entry named "sName". If you want the BarsSinceEntry of the previous entry named "sName", please use a entriesAgo value of 0 instead of 1.
              For example:
              Code:
              BarsSinceEntry(BarsInProgress,"sName",0);
              Please see our help guide for more information: http://ninjatrader.com/support/helpG...sinceentry.htm

              Please let me know if you continue to experience issues.
              Michael M.NinjaTrader Quality Assurance

              Comment


                #8
                this is awesome. spent an hour trying to find this, then with this suggestion , found a null reference in 5 minutes.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,262 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by WeyldFalcon, 12-10-2020, 06:48 PM
                14 responses
                1,429 views
                0 likes
                Last Post Handclap0241  
                Started by DJ888, 04-16-2024, 06:09 PM
                2 responses
                9 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                41 views
                0 likes
                Last Post jeronymite  
                Working...
                X