NexusFi: Find Your Edge


Home Menu

 





Auto order cancel


Discussion in NinjaTrader

Updated
    1. trending_up 2,097 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
ttiller
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


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Iran Fired a Missile at Israel Last Night. The $8M June …
Prediction Markets & Event Contracts
Irans Dual Probability: Guns Quiet at 99.95% While Forma …
Prediction Markets & Event Contracts
Fabrication or Framework? Irans Denied MOU Explains the …
Prediction Markets & Event Contracts
Thanks Mike. Godspeed.
The Elite Circle
Strike Pause Holds, Oil Erases Monday Spike -- May CPI W …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
10 thanks
Darmok and Jalad at Tanagra
3 thanks
Big Mike in Ecuador
1 thanks
30 Sessions
1 thanks
  #2 (permalink)
 
rleplae's Avatar
 rleplae 
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: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,855

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


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
ttiller
Pawleys Island SC
 
Posts: 3 since Aug 2016
Thanks Given: 2
Thanks Received: 1



rleplae View Post
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.


Reply With Quote
  #4 (permalink)
 
rleplae's Avatar
 rleplae 
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: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,855


ttiller View Post
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 + " "
			);
		}
	}


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
rleplae's Avatar
 rleplae 
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: 2,947 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,855

This might be helpful for you :


Follow me on X Visit my NexusFi Trade Journal Reply With Quote
  #6 (permalink)
ttiller
Pawleys Island SC
 
Posts: 3 since Aug 2016
Thanks Given: 2
Thanks Received: 1

Thanks! This helps a lot!




rleplae View Post
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 + " "
			);
		}
	}


Reply With Quote
Thanked by:




Last Updated on December 4, 2016


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts