• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

entryOrder = null; ERROR

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

    entryOrder = null; ERROR

    Hello,

    I keep running into an error of "Object reference not set to an instance of an object." when I set the entryOrder to Null after it has been cancelled.

    Below is the block of code that I found in several of the example strategies.
    Code:
            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
              double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
            {
                AssignOrderToVariable(ref order);
    
                // Reset the entryOrder object to null if order was cancelled without any fill
                if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
                {
                    Print(string.Format("40  |  OOU  | entryOrder CANCELED  |  Currenbar:  {0}  |  {1}",
                        CurrentBar, DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff tt")));
    
                    entryOrder = null;
                }
    }
    Below is the error:
    Code:
    30 | LongEntry Triggered | BarNumberOfOrder: 335 | Position Quantity: 44 | LowOfLongEntryBar: 9060 | EntryPrice: 9061.75 | InitialStop: 9059.5 | 06/30/2020 09:46:36.847 PM
    4/29/2020 7:22:17 PM Strategy 'T5/204825027': Entered internal SubmitOrderManaged() method at 4/29/2020 7:22:17 PM: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=44 LimitPrice=0 StopPrice=9061.75 SignalName='Long_Entry' FromEntrySignal=''
    20 | CancelEntries | entryOrder.OrderState: Working | Currenbar: 339 | 06/30/2020 09:46:36.847 PM
    4/29/2020 7:23:20 PM Strategy 'T5/204825027': Cancelled custom managed order: orderId='NT-00006-27266' account='Sim101' name='Long_Entry' orderState=Working instrument='MNQ 09-20' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=9061.75 quantity=44 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2020-04-29 19:22:17' gtd='2099-12-01' statementDate='2020-06-30'
    40 | OOU | entryOrder CANCELLED | Currenbar: 339 | 06/30/2020 09:46:36.847 PM
    Strategy 'T5': Error on calling 'OnBarUpdate' method on bar 339: Object reference not set to an instance of an object.
    Questions:
    1. Is the order object automatically set to null internally by NT after the order is cancelled and therefore there is no need to set to null in OOU after cancelled?
    2. I am also setting entryOrder to null in OEU if the order is filled as well at the beginning of each day because I am trading intraday only and neither of those cause the error.
    3. Please let me know if you have any feedback to what would cause the error?
    4. NinjaTrader_ChelseaB posted an example strat named ProfitChaseStopTrailExitOrdersExample that used an empty order object named placeHolderOrder. Can you please explain why and what placeHolderOrder specifically does in that code?

    Thanks
    Last edited by Epistemophilic; 06-30-2020, 10:11 PM.

    #2
    Hello Epistemophilic,

    The error 'Object reference not set to an instance of an object' means that you are using a variable with a null value.

    You will need to check for null before using any variable that be null.

    No, order objects are not set to null by NinjaTrader as these will continue to hold the order information for later use.

    The placeHolderOrder is used because you must assign order objects from OnOrderUpdate and not when calling the entry method.
    https://ninjatrader.com/support/help...rderupdate.htm
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by jayfutures23, Today, 07:06 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Melissa  
    Started by MojoJojo, Today, 05:59 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by Spark68, Yesterday, 07:48 PM
    1 response
    19 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by Lotyok, Today, 01:08 AM
    4 responses
    27 views
    0 likes
    Last Post NinjaTrader_PaulH  
    Started by Tri-Star, Yesterday, 07:28 PM
    3 responses
    13 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Working...
    X