Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Account.CreateOrder - Unhandled exception: Object reference not set to an instance

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

    Account.CreateOrder - Unhandled exception: Object reference not set to an instance

    hi following the example in:


    I tried to create order in an indicator

    myEntryOrder= myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.StopMarket, OrderEntry.Automated, TimeInForce.Day, 1, 0, 1400, "myOCO", "stopOrder", Core.Globals.MaxDate, null);

    It passes compiling, but at run time, it gets error. Unhandled exception: Object reference not set to an instance of an object.
    Does it fail at the "Instrument"?

    But I think Instrument is an instance. because I tried to Print(Instrument.FullName); and it does print MNQ 03-22.

    #2
    Hello leontancfa,

    Thank you for your reply.

    Is the order going to be linked by OCO to another order? If not, you should use an empty string for that parameter.

    Aside from that, nothing looks amiss with this particular line of code. Could you provide a larger code snippet so I may get a better understanding of where it may be erroring?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Originally posted by leontancfa View Post
      myEntryOrder= myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.StopMarket, OrderEntry.Automated, TimeInForce.Day, 1, 0, 1400, "myOCO", "stopOrder", Core.Globals.MaxDate, null);
      What is the value of myAccount?

      Comment


        #4
        Originally posted by leontancfa View Post
        That example is woefully incomplete and does not show
        anything about how myAccount is defined or how it gets
        assigned a value.

        Better to look for other working sample code, which can
        be found using google.

        Comment


          #5
          If myAccount is something like myAccount= AccountSelector.SelectedAccount then you can always do a check like this:
          Code:
          if(myAccount != null && myAccount.ToString() != string.Empty) // sometimes != null won't catch that myAccount == string.Empty--you need both if you do a check like this
          {
              myEntryOrder= myAccount.CreateOrder(Instrument, OrderAction.Sell, OrderType.StopMarket, OrderEntry.Automated, TimeInForce.Day, 1, 0, 1400, "myOCO", "stopOrder", Core.Globals.MaxDate, null);
          }

          Comment


            #6
            I successfully make the order submitted now!

            my next question is how to trigger adding ATMStrategy once the order is filled?

            The closest thing I found is below, but it is for strategy, not for an order filled by Addon order creation....

            Comment


              #7
              Hello leontancfa,

              Thank you for your reply.

              It is possible to submit an order with an ATM attached from an add-on.
              http://ninjatrader.com/support/forum...555#post515555

              It would also be possible to create an Add-on that would submit a stop and limit order as a stop loss and profit target by either checking the account position after a button press or automatically from monitoring an account position update.
              https://ninjatrader.com/support/help...ns_account.htm
              https://ninjatrader.com/support/help...tionupdate.htm
              https://ninjatrader.com/support/foru...720#post820720

              Please let us know if we may be of further assistance to you.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              637 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              366 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              107 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              569 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              571 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X