NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 07-12-2010, 02:06 AM   #1
Sauronix
Junior Member
 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default CancelOrder() not work

Sorry for my bad English.
Try use CancelOrder() but command does not work!

Code:
EntryAskOrder=EnterShortLimit(quantity,EnterPrice,"Open Short");

if (EntryAskOrder != null)
		  {
			
		min=EntryAskOrder.LimitPrice+AskShift+Shift;
		   if (GetCurrentAsk() < min)
			{
				Print("Try cancel Order id="+EntryAskOrder.Token.ToString()+",State="+EntryAskOrder.OrderState.ToString());
				CancelOrder(EntryAskOrder);
				
 			}
		  }
in Output window i see that

Code:
Bid=1068
Calc Price=1067
12.07.2010 13:14:00 Entered internal PlaceOrder() method at 12.07.2010 13:14:00: Action=Buy OrderType=Limit Quantity=1 LimitPrice=1067,00 StopPrice=0 SignalName='Open Long' FromEntrySignal=''
Order Changed: id=ff8629b187be4257a1ccb0075225ffd0;State=PendingSubmit
Order Changed: id=ff8629b187be4257a1ccb0075225ffd0;State=Accepted
Order Changed: id=ff8629b187be4257a1ccb0075225ffd0;State=Working
Try cancel Order id=ff8629b187be4257a1ccb0075225ffd0,State=Working
Try cancel Order id=ff8629b187be4257a1ccb0075225ffd0,State=Working
Try cancel Order id=ff8629b187be4257a1ccb0075225ffd0,State=Working
Try cancel Order id=ff8629b187be4257a1ccb0075225ffd0,State=Working
Try cancel Order id=ff8629b187be4257a1ccb0075225ffd0,State=Working
Help please. What I do wrong?
Sauronix is offline  
Reply With Quote
Old 07-12-2010, 04:59 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
Default

Welcome to our forums here at NinjaTrader - could it be the order expires to quick before you get a chance to cancelOrder it? It would just last for one OnBarUpdate() per default, try for example submitting the original one with liveUntilCancelled set to true -

http://www.ninjatrader-support.com/H...LongLimit.html
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2010, 05:11 AM   #3
Sauronix
Junior Member
 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default

For Long order CancelOrder() work if I use "EnterLongLimit(0,true,quantity,EnterPrice,"Op en Long")" but
with short orders this don`t work. OrderState Changed to "Canceled" but event OnOrderUpdate() does not occur.
Sauronix is offline  
Reply With Quote
Old 07-12-2010, 07:01 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
Default

Which NT version are you using as you run into this issue (Help > About).

Please just run your short order part and enable the TraceOrders feature in the Strategy's Initialize() to debug your order behaviors.

http://www.ninjatrader.com/support/f...ead.php?t=3627
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-12-2010, 07:38 AM   #5
Sauronix
Junior Member
 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default

NT 6.5.1000.16, TraceOrders=true; Instrument=ES 09-10.
in Output Window I see message "Cancelled custom managed order" but function OnOrderUpdate() not run and order not cancel at NT orders tab.
Sauronix is offline  
Reply With Quote
Old 07-12-2010, 08:36 AM   #6
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

Sauronix, could you please provide the code sample that you're using here that does not cancel the order? We'd like to test this out on our end and see if there is anything else that could be going on.
NinjaTrader_Austin is offline  
Reply With Quote
Old 07-13-2010, 12:46 AM   #7
Sauronix
Junior Member
 
Join Date: Jul 2010
Posts: 4
Thanks: 0
Thanked 0 times in 0 posts
Default

Enter order code:
Code:
if (devi>MinTradeDeviation && devi<MaxTradeDeviation && Position.MarketPosition==MarketPosition.Flat)
		 {
	  
		if (em>Close[0]) 
	      {
			if (EntryBidOrder==null && EntryAskOrder==null)
			{
				firstExitTry=false;
				EnterPrice=GetCurrentBid()-bidShift;
				Print("Bid="+GetCurrentBid());		
				Print("Calc Price="+EnterPrice.ToString());
				EntryBidOrder=EnterLongLimit(0,true,quantity,EnterPrice,"Open Long");
			}
		  } 
	   if (em<Close[0]) 
			{
			if (EntryBidOrder==null && EntryAskOrder==null) 
			{
		    	firstExitTry=false;
				EnterPrice=GetCurrentAsk()+AskShift;
		    	Print("Ask="+GetCurrentAsk());
				Print("Calc Price="+EnterPrice.ToString());
				EntryAskOrder=EnterShortLimit(0,true,quantity,EnterPrice,"Open Short");}
 			}
		 }
		
		}
Cancel order code:

Code:
if (EntryBidOrder != null)
		  {
	
			max=EntryBidOrder.LimitPrice+BidShift+Shift; //Правильный вариант
		   if (GetCurrentBid() > max)
			{
				Print("Try cancel Order id="+EntryBidOrder.Token.ToString()+",State="+EntryBidOrder.OrderState.ToString());
				CancelOrder(EntryBidOrder);
				
			}
		  }
		
		if (EntryAskOrder != null)
		  {
			
			min=EntryAskOrder.LimitPrice-AskShift-Shift; //Правильный вариант
		   if (GetCurrentAsk() < min)
			{
			Print("Try cancel Order id="+EntryAskOrder.Token.ToString()+",State="+EntryAskOrder.OrderState.ToString());
				CancelOrder(EntryAskOrder);
 			}
		  }
Sauronix is offline  
Reply With Quote
Old 07-13-2010, 07:42 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
Default

Thanks Sauronix, could you please send us the complete script also with the OnOrderUpdate() section to support at ninjatrader dot com referencing this thread?

Also: have you tried the same script on our NT7 beta?
NinjaTrader_Bertrand is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Unmanaged + OCO + CancelOrder cls71 Version 7 Beta General Questions & Bug Reports 2 05-06-2010 11:16 AM
Using CancelOrder with SampleATMStrategy jthom ATM Strategies (Discretionary Trading) 1 03-11-2010 08:32 AM
CancelOrder() problem boreland Strategy Development 1 12-28-2009 05:33 AM
How CancelOrder() work? xewoox Strategy Development 6 02-18-2009 02:21 PM
CancelOrder() problem John833 Strategy Development 41 10-31-2008 03:15 PM


All times are GMT -6. The time now is 09:23 AM.