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

Error on calling 'OnBarUpdate' method for strategy

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

    Error on calling 'OnBarUpdate' method for strategy

    my code running perfectly but after some point it stops and i got this message at the bottom of the output window where execution stops

    - < Error on calling 'OnBarUpdate' method for strategy 'rainraingoaway/d380bf5bb9194f569ca67594daee5018': Object reference not set to an instance of an object. > -

    can u tell me how to fix this

    #2
    Hello ,

    Thanks for your note.

    This error message indicates that a variable being called is not instantiated. This can be due to the variable being set to null, or not having been properly instantiated in the variables region.

    I recommend that you add print statements to your code at each step the strategy is taking.

    This will help you to narrow down the particular line of code that is causing the problem.

    Please let me know if I can be of further assistance for you.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks i used
      private IOrder entryOrder = null;
      private IOrder exitOrder = null;

      may due to this ..!! apart from null wat i can use in assigning variable in the public class for iOrders

      Comment


        #4
        Originally posted by DealI View Post
        thanks i used
        private IOrder entryOrder = null;
        private IOrder exitOrder = null;

        may due to this ..!! apart from null wat i can use in assigning variable in the public class for iOrders
        And what are the statements where you used the IOrders to generate the trading orders?

        Comment


          #5
          if(GetCurrentBid() <= refhigh-3 && Position.MarketPosition == MarketPosition.Flat )
          {

          entryOrder = EnterLong();



          }
          if (Position.MarketPosition != MarketPosition.Flat)
          {
          lastboughtprice = entryOrder.AvgFillPrice;


          }


          if(GetCurrentBid() <= lastboughtprice-2 && Position.MarketPosition != MarketPosition.Flat )
          {

          entryOrder = EnterLong();


          }
          if (Position.MarketPosition != MarketPosition.Flat)
          {
          lastboughtprice = entryOrder.AvgFillPrice;


          }


          if(GetCurrentBid() >= Position.AvgPrice )
          {
          exitOrder = ExitLong();
          refhigh =0;

          }


          these where i used iOrders

          Comment


            #6
            Originally posted by DealI View Post
            if(GetCurrentBid() <= refhigh-3 && Position.MarketPosition == MarketPosition.Flat )
            {

            if (entryOrder == null) entryOrder = EnterLong();



            }
            if (Position.MarketPosition != MarketPosition.Flat)
            {
            lastboughtprice = entryOrder.AvgFillPrice;


            }


            if(GetCurrentBid() <= lastboughtprice-2 && Position.MarketPosition != MarketPosition.Flat )
            {

            if (entryOrder == null) entryOrder = EnterLong();


            }
            if (Position.MarketPosition != MarketPosition.Flat)
            {
            lastboughtprice = entryOrder.AvgFillPrice;


            }


            if(GetCurrentBid() >= Position.AvgPrice )
            {
            if (exitOrder == null) exitOrder = ExitLong();
            refhigh =0;

            }


            these where i used iOrders
            You just need to check for the null reference first. Shown in red in your text.

            I do wonder about your exit condition: do you really want to exit as soon as the CurrrentBid is greater than your position's average price?

            Remember to reset your IOrders to null after they are filled, so that you can reuse them. We usually do it in the OnExecution() event handler.

            Comment


              #7
              Remember to reset your IOrders to null after they are filled..//////

              How to reset the IOrders ???

              Comment


                #8
                Originally posted by DealI View Post
                Remember to reset your IOrders to null after they are filled..//////

                How to reset the IOrders ???
                I referred you to OnExecution(). Read it.

                Comment


                  #9
                  yes i got it but i want to know how to reset entryOrder = null in the OnExecution(IExecution execution)

                  pls help
                  Last edited by DealI; 06-10-2013, 01:32 AM.

                  Comment


                    #10
                    Originally posted by DealI View Post
                    yes i got it but i want to know how to reset entryOrder = null in the OnExecution(IExecution execution)

                    pls help
                    Deall, I would highly suggest reviewing this example for working with the advanced order handling approach including IOrders, it will show the resets needed as well.

                    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
                    BertrandNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Segwin, 05-07-2018, 02:15 PM
                    10 responses
                    1,767 views
                    0 likes
                    Last Post Leafcutter  
                    Started by Rapine Heihei, 04-23-2024, 07:51 PM
                    2 responses
                    30 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Started by Shansen, 08-30-2019, 10:18 PM
                    24 responses
                    943 views
                    0 likes
                    Last Post spwizard  
                    Started by Max238, Today, 01:28 AM
                    0 responses
                    9 views
                    0 likes
                    Last Post Max238
                    by Max238
                     
                    Started by rocketman7, Today, 01:00 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post rocketman7  
                    Working...
                    X