NexusFi: Find Your Edge


Home Menu

 





Auto order cancel


Discussion in NinjaTrader

Updated
    1. trending_up 1,418 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?
Brendt Skorupinsky
Trading Reviews and Vendors
Has anyone taken trading from Agnieska Wood - Ahead Coach?
Psychology and Money Management
Pivot Indicator based on Level2 data
NinjaTrader
What You Know vs How much you know about it
Traders Hideout
How to plot a custom icon for crossover
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
ApexTraderFunding.com experience and review
139 thanks
1 Minute Man
60 thanks
HumbleTraders next chapter
42 thanks
Winning attitudes create winning traders
36 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
25 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,997 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

Follow me on Twitter 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,997 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


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 Twitter 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,997 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863

This might be helpful for you :


Follow me on Twitter 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


© 2024 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 - Privacy Policy - Downloads - Top
no new posts