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
Strategy Builder cancel unfilled orders
Collapse
X
-
Strategy Builder cancel unfilled orders
I'm using the strategy builder and can't seem to figure out a way to cancel an unfilled limit order. My strategy will enter a limit order at a specific price, but if the current price moves to far away from the limit order, I need a way to cancel that unfilled order. Is there a way to accomplish this in the Strategy Builder?Tags: None
-
Hello srtrader,
Thanks for your post.
There are no means to cancel orders in the Strategy Builder.
Limit orders in the Strategy builder will automatically be canceled at the end of the bar they are submitted on.
From the Managed Approach help guide page: "By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted"
See this help guide page for more information about using the Managed Approach Methods: https://ninjatrader.com/support/help...d_approach.htm
To accomplish this, you would need to unlock your script from the Strategy Builder by clicking the 'Unlock code' button. The CancelOrder() method could be used in an unlocked script to cancel a specified order.
See this help guide page for more information about CancelOrder(): https://ninjatrader.com/support/help...ancelorder.htm
And, see this reference sample: https://ninjatrader.com/support/help...thod_to_ca.htm
Let me know if I may assist further.Brandon H.NinjaTrader Customer Service
- Likes 1
-
Thanks for the info! I'll definitely look into this more. Question on the Cancel Order code though. I see this example on the page you mentioned:
if (CurrentBar > barNumberOfOrder + 5)
CancelOrder(myEntryOrder);
I'll be cancelling the order if price moves a certain distance away from my signal bar. I think I can figure that part out. The last line of this code where it refers to (myEntryOrder), is that what I need to put into my code or is "myEntryOrder" referring to what I have named that entry.
This is what my code looks like for a long entry:
EnterLongLimit(Convert.ToInt32(DefaultQuantity), LongEntry, @"LongTradeEntry");
So to cancel this specific Limit order if parameters are met, would I just put CancelOrder(LongTradeEntry) ??
Comment
-
Hello srtrader,
If you are using CancelOrder, you need to handle order objects.
This would involve adding OnOrderUpdate, and assigning the Order object when the order parameter's Name property matches your signal name. Also, the Order object will need to be set to null when filled/canceled if you want to submit the order again. (Since the logic to submit the order makes sure the order object is null before the order is submitted) A null order object would then represent that the order is not active.
The example Brandon linked includes some code to show order object handling.
Brandon also mentions that from the Strategy Builder, limit and stop orders that are submitted with Enter/Exit methods will cancel if you do not call the method on the next bar.
You could consider writing logic in Conditions and Actions that:- Condition that sets a bool to true when you want the order to be active
- Condition that sets a bool to false when you want the order to be cancelled
- Condition that checks if the bool is true or false, and then submits the order
If you need more deliberate control than this, using unlocked code and CancelOrder would be the way forward.JimNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by helpwanted, Today, 03:06 AM
|
1 response
9 views
0 likes
|
Last Post Today, 03:35 AM | ||
Started by Brevo, Today, 01:45 AM
|
0 responses
7 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
242 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
385 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
Comment