for(int i = 0; i < this.Orders.Count; i++) { this.Orders[i].Cancel(); }
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Canceling All Orders
Collapse
X
-
Canceling All Orders
My strategy at times tries to reverse its position, and when it does so it first cancels all orders and then places an order to negate my current position. It appears though that my orders are not getting canceled when I look at the execution history in my backtesting. The way I cancel all orders is to do the following:
Code:Tags: None
-
Hello hamburglergt,
We unfortunately do not support working from an orders collection. To cancel orders you must structure them as IOrder and then the IOrder object is passed into CancelOrder() method. This sample can help with CancelOrder() technique:
When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-untilRyan M.NinjaTrader Customer Service
-
-
You pass in the IOrder object into CancelOrder() to cancel it. There's unfortunately not support for an IOrder collection although some users report success using this. NinjaScript is an extension of C# so there is a lot of flexibility in what you can do. However, we can only provide support for the NinjaScript items in our help guide and reference sample on these forums.Ryan M.NinjaTrader Customer Service
Comment
-
My question was a ninjascript question...how do i retrieve all orders? If you're saying the Cancel() method does not work, then how do i obtain all IOrder objects in order to call CancelOrder() on them.
Comment
-
There is not a bulit in method that can be used to retrieve all orders. You can use that sample for reference on how to use CancelOrder(), which accepts an individual IOrder object. An important concept to understand is that the strategy is only aware of orders submitted by the particular strategy instance you're using.
If you are an advanced programmer then you may be able to build an IOrder collection to manage and use. We will not develop this for you, although you can check this sample for some ideas.
If you are not a programmer or have limited time to develop this concept, you may consider hiring a 3rd party NinjaScript consultant to help with areas that are outside of our scope of support. A complete list is available here:
Ryan M.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by denymachado, Today, 04:39 AM
|
0 responses
3 views
0 likes
|
Last Post
![]()
by denymachado
Today, 04:39 AM
|
||
Started by byteman, Yesterday, 11:59 AM
|
5 responses
31 views
0 likes
|
Last Post
![]()
by byteman
Today, 04:24 AM
|
||
Started by Irukandji, 03-21-2025, 04:05 AM
|
4 responses
51 views
0 likes
|
Last Post
![]()
by Irukandji
Today, 03:05 AM
|
||
Started by Zadomani, 03-24-2025, 11:39 PM
|
2 responses
40 views
0 likes
|
Last Post
![]()
by Zadomani
Yesterday, 11:23 PM
|
||
Started by Darkslide_Tom, 03-23-2025, 11:08 PM
|
4 responses
19 views
0 likes
|
Last Post
![]() |
Comment