Does calling CancelOrder() on a non-existent ("=null") IOrder cause an error to occur within the strategy or does ninjascript choose to ignore the CancelOrder() request?
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!
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
NinjaTrader
CancelOrder() on non-existent IOrders
Collapse
X
-
Hello Elynt,
Thank you for your inquiry.
A run-time error will occur if the order is null: "object reference not set to an instance of an object".
It is always suggested to run a null check before attempting to access objects that can be null.
Please take a look at this post in our Tips section for more information about checking for null references: http://ninjatrader.com/support/forum...44&postcount=1
Please, let us know if we may be of further assistance.Zachary G.NinjaTrader Customer Service
-
Thought I'd post a similar problem I'm having in this thread instead of starting a new one.
I'm having difficulty canceling pending entry orders once one entry order is filled. On entry conditions, two different IOrder objects are assigned two different order types at two different prices, one higher and one lower than the current price. Both IOrder objects are sent to the market successfully (one is "accepted" the other "working"). When one order is filled, the other order ought to cancel, but it does not until the close of the bar (at which time the Managed Approach cancels the pending order). The log shows no signs of attempting to close the pending order prior to the close of the bar.
Here is my code:
Code:protected override void Initialize() { CalculateOnBarClose = false; EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; } protected override void OnBarUpdate() { if (Position.MarketPosition != MarketPosition.Flat && nullcheck == false) { nullcheck = true; if (entryOrderUpHigh != null) { if (entryOrderUpHigh.OrderState == OrderState.Filled) { if (entryOrderUpLow != null) { CancelOrder(entryOrderUpLow); entryOrderUpLow = null; } } } if (entryOrderUpLow != null) { if (entryOrderUpLow.OrderState == OrderState.Filled) { if (entryOrderUpHigh != null) { CancelOrder(entryOrderUpHigh); entryOrderUpHigh = null; } } } } [INDENT][INDENT]if (entry conditions) { entryOrderUpHigh = stop order entryOrderUpLow = limit order }[/INDENT][/INDENT][INDENT]if (FirstTickOfBar) { nullcheck = false; }[/INDENT] }
Comment
-
Hello Elynt,
I would suggest utilizing the OnExecution() method to cancel your other pending order once one of them fills rather than doing that in OnBarUpdate(). OnBarUpdate() is only called at the close of a bar (if CalculateOnBarClose is set to true) or on every new tick (if CalculateOnBarClose is set to false).
OnExecution() is called upon the execution, or fill, of an order. More information about the OnExecution() method can be found in the help guide at this link: http://ninjatrader.com/support/helpG...nexecution.htm
If you would like to cancel an order upon another order filling, OnExecution() is what you would want to utilize.
Please, let us know if we may be of further assistance.Zachary G.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
6 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
12 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
4 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
||
Started by gleichnerany, Today, 01:17 AM
|
0 responses
5 views
0 likes
|
Last Post
by gleichnerany
Today, 01:17 AM
|
||
Started by WHICKED, 03-27-2024, 12:33 PM
|
4 responses
47 views
0 likes
|
Last Post Today, 12:28 AM |
Comment