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
Failed to cancel manually added orders
Collapse
X
-
Yes, per your instruction, I changed to use myAccount.CancelAllOrders(order.Instrument), it worked.
Super!. Thank you so much for your quick help.
-
Hello localappleseed,
Thank you for your post.
The CancelOrder() method should not be called in State.SetDefaults since the strategy will not have processed any orders at this point. Instead, CancelOrder() could be called when the State reaches State.Transition so that orders are canceled when the strategy transitions from processing historical data to real-time data. Please note, CancelOrder() will only cancel orders made by the strategy.
CancelOrder() - https://ninjatrader.com/support/help...ancelorder.htm
You may reference the SampleCancelOrder example script which demonstrates how to use CancelOrder().
SampleCancelOrder - https://ninjatrader.com/support/help...thod_to_ca.htm
If you would like to cancel orders placed on an account outside of the strategy, you could use the AddOn approach to call <Account>.Cancel() when the script reaches a State of State.DataLoaded.
Here is a help guide link about using <Account>.Cancel(). - https://ninjatrader.com/support/help...t8/?cancel.htm
Additionally, to cancel entry and exit orders when a strategy is disabled, you could enable the 'Cancel entry orders when a strategy is disabled' and 'Cancel exit orders when a strategy is disabled' properties. To do so, please follow the instructions below.- In the Control Center, select Tools > Options > Strategies tab.
- Under 'NinjaScript', select the boxes titled 'Cancel entry orders when a strategy is disabled' and 'Cancel exit orders when a strategy is disabled'.
- Click OK.
Let us know if we may further assist.
Leave a comment:
-
Failed to cancel manually added orders
I tried to cancel existing orders which I added manually through SuperDOM. CancelOrder() is called from OnStateChange(), it didn't work, do I have to call CancelOrder() from OnOrderUpdate()? What's the correct way to cancel existing orders?
I am using the following code to cancel, both Prints are working and printed the same results. The order in SuperDOM is still there and it cannot be cancelled.
if (State == State.SetDefaults)
{
// Find our Sim101 account
lock (Account.All)
myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");
foreach (Order order in myAccount.Orders)
{
Print (" 111111 order = " + order);
CancelOrder(order);
Print (" 222222 order = " + order);
}
}Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
4 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
22 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Leave a comment: