Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

'Object reference not set to an instance of an object' when my strategy call my indic

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

    'Object reference not set to an instance of an object' when my strategy call my indic

    Hi, I am so grateful for your support in NT development. It is a complex platform to master, and with your support its made possible.

    I have a complex indicator I developed, which works great when displaying information on the chart. I used it with data of about 14 days over the chart, and everything is smooth. Attached is a snapshot of a chart for your reference.

    When I'm using the same indicator from a strategy, I get an error message:

    **NT** Error on calling 'OnBarUpdate' method for strategy 'bdtPowerPriceActionStrategy/113b92b6c5d741a18c47c95a32cddf2f': Object reference not set to an instance of an object.
    Analyzing my code and the chart, there is nothing special at the moment of the error (no change in what the indicator is doing from 10/16/13-00:10, until 10/16/13-03:25). So there is no reason I can see for the error to occur at 10/16/13-01:45:00.

    I would like to protect my indicator source. I would be happy if I can send it, so you can take a look, if there is a discreet way to send it! Attached is my Strategy code.

    Here is my debug output, where $$$ppa$$$ is the strategy and the &&&ppa&&& is the indicator. You can see that the strategy calls the indicator on OnStartUp event and that the
    $$$ppa$$$ <OnStartUp> 10/16/13-01:45:00
    &&&ppa&&& OnStartUp 10/16/13-00:05:00
    $$$ppa$$$ <++ OnBarUpdate-Begin> 10/16/13-01:45:00
    &&&ppa&&& <* Reset=Init:> 10/16/13-00:05:00>trendUp=[C=0,S=-99,L=-99,SL=0,LP=0,n=-99,x=-99,nP=0,xP=0,I=-99]
    &&&ppa&&& <** Start trendUp@10/16/13-00:05:00:> 10/16/13-00:05:00>trendUp@10/16/13-00:05:00=[C=0,S=0,L=0,SL=0,LP=0,n=-99,x=-99,nP=0,xP=0,I=-99]
    &&&ppa&&& <* Reset=Init:> 10/16/13-00:05:00>trendDown=[C=0,S=-99,L=-99,SL=0,LP=0,n=-99,x=-99,nP=0,xP=0,I=-99]
    &&&ppa&&& <** Start trendDown@10/16/13-00:05:00:> 10/16/13-00:05:00>trendDown@10/16/13-00:05:00=[C=0,S=0,L=0,SL=0,LP=0,n=-99,x=-99,nP=0,xP=0,I=-99]
    &&&ppa&&& 10/16/13-00:05:00>trendDown@10/16/13-00:05:00=[C=1,S=0,L=0,I=-99]
    &&&ppa&&& <* Reset=Switch Peaks:> 10/16/13-00:10:00>trendUp@10/16/13-00:05:00=[C=0,S=-99,L=-99,SL=131.9375,LP=132,n=0,x=0,nP=131.90625,xP=132, I=-99]
    &&&ppa&&& <** Start trendUp@10/16/13-00:10:00:> 10/16/13-00:10:00>trendUp@10/16/13-00:10:00=[C=0,S=0,L=0,SL=131.9375,LP=132,n=-99,x=-99,nP=131.90625,xP=132,I=-99]
    &&&ppa&&& 10/16/13-00:10:00>trendUp@10/16/13-00:10:00=[C=1,S=0,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:10:00>trendDown@10/16/13-00:05:00=[C=2,S=1,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:15:00>trendUp@10/16/13-00:10:00=[C=2,S=1,L=0,I=-99]
    &&&ppa&&& <* Reset=Switch Peaks:> 10/16/13-00:15:00>trendDown@10/16/13-00:05:00=[C=0,S=-99,L=-99,SL=131.9375,LP=131.96875,n=0,x=0,nP=131.96875,x P=131.96875,I=-99]
    &&&ppa&&& 10/16/13-00:15:00>trendDown@10/16/13-00:05:00=[C=0,S=-99,L=-99,I=-99]
    &&&ppa&&& 10/16/13-00:20:00>trendUp@10/16/13-00:10:00=[C=3,S=2,L=0,I=-99]
    &&&ppa&&& <** Start trendDown@10/16/13-00:20:00:> 10/16/13-00:20:00>trendDown@10/16/13-00:20:00=[C=0,S=0,L=0,SL=131.9375,LP=131.96875,n=-99,x=-99,nP=131.96875,xP=131.96875,I=-99]
    &&&ppa&&& 10/16/13-00:20:00>trendDown@10/16/13-00:20:00=[C=1,S=0,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:25:00>trendUp@10/16/13-00:10:00=[C=4,S=3,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:25:00>trendDown@10/16/13-00:20:00=[C=2,S=1,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:30:00>trendUp@10/16/13-00:10:00=[C=5,S=4,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:30:00>trendDown@10/16/13-00:20:00=[C=3,S=2,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:35:00>trendUp@10/16/13-00:10:00=[C=6,S=5,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:35:00>trendDown@10/16/13-00:20:00=[C=4,S=3,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:40:00>trendUp@10/16/13-00:10:00=[C=7,S=6,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:40:00>trendDown@10/16/13-00:20:00=[C=5,S=4,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:45:00>trendUp@10/16/13-00:10:00=[C=8,S=7,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:45:00>trendDown@10/16/13-00:20:00=[C=6,S=5,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:50:00>trendUp@10/16/13-00:10:00=[C=9,S=8,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:50:00>trendDown@10/16/13-00:20:00=[C=7,S=6,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:55:00>trendUp@10/16/13-00:10:00=[C=10,S=9,L=0,I=-99]
    &&&ppa&&& 10/16/13-00:55:00>trendDown@10/16/13-00:20:00=[C=8,S=7,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:00:00>trendUp@10/16/13-00:10:00=[C=11,S=10,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:00:00>trendDown@10/16/13-00:20:00=[C=9,S=8,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:05:00>trendUp@10/16/13-00:10:00=[C=12,S=11,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:05:00>trendDown@10/16/13-00:20:00=[C=10,S=9,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:10:00>trendUp@10/16/13-00:10:00=[C=13,S=12,L=0,I=-99]
    &&&ppa&&& <* Reset=Switch Peaks:> 10/16/13-01:10:00>trendDown@10/16/13-00:20:00=[C=0,S=-99,L=-99,SL=131.96875,LP=132.0625,n=0,x=0,nP=132.0625,xP =132.0625,I=-99]
    &&&ppa&&& 10/16/13-01:10:00>trendDown@10/16/13-00:20:00=[C=0,S=-99,L=-99,I=-99]
    &&&ppa&&& 10/16/13-01:15:00>trendUp@10/16/13-00:10:00=[C=14,S=13,L=0,I=-99]
    &&&ppa&&& <** Start trendDown@10/16/13-01:15:00:> 10/16/13-01:15:00>trendDown@10/16/13-01:15:00=[C=0,S=0,L=0,SL=131.96875,LP=132.0625,n=-99,x=-99,nP=132.0625,xP=132.0625,I=-99]
    &&&ppa&&& 10/16/13-01:15:00>trendDown@10/16/13-01:15:00=[C=1,S=0,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:20:00>trendUp@10/16/13-00:10:00=[C=15,S=14,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:20:00>trendDown@10/16/13-01:15:00=[C=2,S=1,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:25:00>trendUp@10/16/13-00:10:00=[C=16,S=15,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:25:00>trendDown@10/16/13-01:15:00=[C=3,S=2,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:30:00>trendUp@10/16/13-00:10:00=[C=17,S=16,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:30:00>trendDown@10/16/13-01:15:00=[C=4,S=3,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:35:00>trendUp@10/16/13-00:10:00=[C=18,S=17,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:35:00>trendDown@10/16/13-01:15:00=[C=5,S=4,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:40:00>trendUp@10/16/13-00:10:00=[C=19,S=18,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:40:00>trendDown@10/16/13-01:15:00=[C=6,S=5,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:45:00>trendUp@10/16/13-00:10:00=[C=20,S=19,L=0,I=-99]
    &&&ppa&&& 10/16/13-01:45:00>trendDown@10/16/13-01:15:00=[C=7,S=6,L=0,I=-99]
    **NT** Error on calling 'OnBarUpdate' method for strategy 'bdtPowerPriceActionStrategy/8d60e51b9b7a4407b7ee9f65bf7159d2': Object reference not set to an instance of an object.
    Attached Files

    #2
    Hi There,

    If you'd like you can always feel free to send in some code to support[at]ninjatrader[dot]com and we can look at it there.

    In terms of the Object Reference errors, these are commonly caused by object references when they are null. You'll want to make sure you're adding error handling to ensure we can check an objects property at the time you are access it.

    Please see the following link which may help shed some light on how to handle this error:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by Shai Samuel View Post
      Hi, I am so grateful for your support in NT development. It is a complex platform to master, and with your support its made possible.

      I have a complex indicator I developed, which works great when displaying information on the chart. I used it with data of about 14 days over the chart, and everything is smooth. Attached is a snapshot of a chart for your reference.

      When I'm using the same indicator from a strategy, I get an error message:



      Analyzing my code and the chart, there is nothing special at the moment of the error (no change in what the indicator is doing from 10/16/13-00:10, until 10/16/13-03:25). So there is no reason I can see for the error to occur at 10/16/13-01:45:00.

      I would like to protect my indicator source. I would be happy if I can send it, so you can take a look, if there is a discreet way to send it! Attached is my Strategy code.

      Here is my debug output, where $$$ppa$$$ is the strategy and the &&&ppa&&& is the indicator. You can see that the strategy calls the indicator on OnStartUp event and that the
      This line is trying to access an object that you have declared as null.
      Code:
      orderIOrder = EnterLongStopLimit(0, false, DefaultQuantity, orderEnter, orderStop, orderName);
      Check the IOrder object for nullity.

      Comment


        #4
        Thank you Matthew. I just submitted my code to you.

        As far as I can understand, I don't have any variables, that suppose to have null values. All the dynamic variables are created at the Initialize() or OnStartUp(). All my other variables are either local ones, or local Class vars, which are none Dynamic.

        Comment


          #5
          Thank you Koganam, I just did it, and it works !

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by kaywai, 09-01-2023, 08:44 PM
          5 responses
          601 views
          0 likes
          Last Post NinjaTrader_Jason  
          Started by xiinteractive, 04-09-2024, 08:08 AM
          6 responses
          22 views
          0 likes
          Last Post xiinteractive  
          Started by Pattontje, Yesterday, 02:10 PM
          2 responses
          18 views
          0 likes
          Last Post Pattontje  
          Started by flybuzz, 04-21-2024, 04:07 PM
          17 responses
          230 views
          0 likes
          Last Post TradingLoss  
          Started by agclub, 04-21-2024, 08:57 PM
          3 responses
          17 views
          0 likes
          Last Post TradingLoss  
          Working...
          X