Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Auto order cancel
Updated December 4, 2016
trending_up
1,357 views
thumb_up
1 thanks given
group
2 followers
forum
5 posts
attach_file
0 attachments
Auto order cancel
December 2nd, 2016, 07:21 AM
Pawleys Island SC
Posts: 3 since Aug 2016
Thanks Given: 2
Thanks Received: 1
Does anyone know of a way to automatically cancel a pending order at a price point with the ATM or a strategy?
Example: entry is pending to enter on a stop limit order short. However if the market rises to a certain price then we want to cancel the entry.
Thanks
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
December 3rd, 2016, 10:26 AM
Gits (Hooglede) Belgium
Legendary Market Wizard
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863
You can use CancelOrder().
If a strategy has created an order, then it is aware of the context and can cancel the order.
If not, then the strategy can't 'watch' pending orders, and then would have to know when to cancel the order
using CancelOrder() at what level for long and short, you could read the DB directly for outstanding orders
December 3rd, 2016, 01:04 PM
Pawleys Island SC
Posts: 3 since Aug 2016
Thanks Given: 2
Thanks Received: 1
rleplae
You can use CancelOrder().
If a strategy has created an order, then it is aware of the
context and can cancel the order.
If not, then the strategy can't 'watch' pending orders, and then would have to know when to cancel the order
using CancelOrder() at what level for long and short, you could read the DB directly for outstanding orders
So since the order would be manually entered, I would need to write a strategy to cancel it correct.
December 3rd, 2016, 01:10 PM
Gits (Hooglede) Belgium
Legendary Market Wizard
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863
ttiller
So since the order would be manually entered, I would need to write a strategy to cancel it correct.
Straight forward, a strategy can only cancel what i has 'started'.
Code
private IOrder myEntryOrder = null;
myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry");
CancelOrder(myEntryOrder);
In your case you would not have the IOrder object.
You can however in a bit more advanced way, iterate through all the orders
as follows :
Code
for (int i=0; i < NinjaTrader.Cbi.Globals.Accounts.Count; i++ ) {
for (int j=0; j < NinjaTrader.Cbi.Globals.Accounts[i].Positions.Count; j++ )
{
Print(""
+NinjaTrader.Cbi.Globals.Accounts[i].Name +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].Instrument.FullName +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].MarketPosition +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].Quantity +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].AvgPrice
);
}
for (int j=0; j < NinjaTrader.Cbi.Globals.Accounts[i].Orders.Count; j++ )
if (NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].Filled == 0 && NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].OrderState.ToString() != "Cancelled")
{
Print(""
+NinjaTrader.Cbi.Globals.Accounts[i].Name +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].Instrument.FullName +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].OrderAction + " "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].Quantity +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].OrderType + " "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].LimitPrice + " "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].StopPrice + " "
);
}
}
December 3rd, 2016, 01:39 PM
Gits (Hooglede) Belgium
Legendary Market Wizard
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863
This might be helpful for you :
December 4th, 2016, 04:10 PM
Pawleys Island SC
Posts: 3 since Aug 2016
Thanks Given: 2
Thanks Received: 1
Thanks! This helps a lot!
rleplae
Straight forward, a strategy can only cancel what i has 'started'.
Code
private IOrder myEntryOrder = null;
myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry");
CancelOrder(myEntryOrder);
In your case you would not have the IOrder object.
You can however in a bit more advanced way, iterate through all the orders
as follows :
Code
for (int i=0; i < NinjaTrader.Cbi.Globals.Accounts.Count; i++ ) {
for (int j=0; j < NinjaTrader.Cbi.Globals.Accounts[i].Positions.Count; j++ )
{
Print(""
+NinjaTrader.Cbi.Globals.Accounts[i].Name +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].Instrument.FullName +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].MarketPosition +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].Quantity +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Positions[j].AvgPrice
);
}
for (int j=0; j < NinjaTrader.Cbi.Globals.Accounts[i].Orders.Count; j++ )
if (NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].Filled == 0 && NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].OrderState.ToString() != "Cancelled")
{
Print(""
+NinjaTrader.Cbi.Globals.Accounts[i].Name +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].Instrument.FullName +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].OrderAction + " "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].Quantity +" "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].OrderType + " "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].LimitPrice + " "
+NinjaTrader.Cbi.Globals.Accounts[i].Orders[j].StopPrice + " "
);
}
}
Last Updated on December 4, 2016