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 > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 06-28-2012, 01:18 PM   #1
Thomas79
Senior Member
 
Join Date: Apr 2009
Location: Paris
Posts: 146
Thanks: 11
Thanked 0 times in 0 posts
Send a message via MSN to Thomas79
Default Entry Orders cancelled after 5 minutes...

Hi

i run my strategy in a 5 minutes basis, i enter long or short with a limit order, calculateonbarclose=true

i write the code to say, "if the order is not filled during the 5 minutes, keeps it but cancel it after the 3 bar if it is not filled (15 minutes in total)"

but if the entry order is not filled after the 1st 5 minute, it is cancelled...

here my code (as shown on the guide NT7), can you help to tell me what's wrong ?

// Condition buy
if ( entryOrderAchat == null && buycondition)

{
entryOrderAchat = EnterLongLimit(
0, true, 1, Close[0], "Buy");
barNumberOfOrderAchat = CurrentBar;
}

// If entryOrder has not been filled within 3 bars, cancel the order.
elseif (entryOrderAchat != null && CurrentBar > barNumberOfOrderAchat + 3)
{
// When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via EnterLong()
CancelOrder(entryOrderAchat);
}
Thomas79 is offline  
Reply With Quote
Old 06-28-2012, 01:26 PM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Thomas79,

Code looks good from here for what you're looking to do. Is there any reason provided for cancelling this order in TraceOrders output? Enable it in Initialize() section and then check output in Tools > Output Window

Try adding something like below to check if it's cancelling due to your custom logic or if it's something else:

Code:
else if (entryOrderAchat != null && CurrentBar > barNumberOfOrderAchat + 3)
{
Print("CB: " + CurrentBar);
Print("BNO: " + barNumberOfOrderAchat);
// When entryOrder gets cancelled below in OnOrderUpdate(), it gets replaced with a Market Order via
EnterLong()
CancelOrder(entryOrderAchat);
}
NinjaTrader_RyanM is offline  
Reply With Quote
Old 06-28-2012, 02:19 PM   #3
Thomas79
Senior Member
 
Join Date: Apr 2009
Location: Paris
Posts: 146
Thanks: 11
Thanked 0 times in 0 posts
Send a message via MSN to Thomas79
Default

i recheck the code example... and i this i forget this part of code

protectedoverridevoid OnOrderUpdate(IOrder order)
{
// Checks for all updates to entryOrder.
if (entryOrder != null && entryOrder == order)
{
// Check if entryOrder is cancelled.
if (order.OrderState == OrderState.Cancelled)
{
// Reset entryOrder back to null
entryOrder = null;

// Replace entry limit order with a market order.
marketOrder = EnterLong(1, "market order");
}
}
}
Thomas79 is offline  
Reply With Quote
Old 08-16-2012, 11:17 AM   #4
paatech
Junior Member
 
Join Date: Jul 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi, can you please help with programming "Cancel order" in NT Strategy? I have several condition sets in a Strategy and only for 1 of them I need to program Cancel order for a limit order (the other sets have market orders). So far I have:

EnterLongLimit(0, true, DefaultQuantity, Close[0] + -2 * TickSize, "Long2v");

Now the order is active till it is filled. I need to cancel this order after:
1/ 20 minutes or 5 bars

Can you please advise where and how to place the script for cancelling?

Thanks a lot
paatech is offline  
Reply With Quote
Old 08-16-2012, 12:05 PM   #5
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi paatech,

You can see a sample on CancelOrder() here:
http://www.ninjatrader.com/support/f...ad.php?t=18890

This sample cancels the order if not filled within 3 bars, so you should be able to adapt to your needs.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 08-16-2012, 01:19 PM   #6
paatech
Junior Member
 
Join Date: Jul 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_RyanM View Post
Hi paatech,

You can see a sample on CancelOrder() here:
http://www.ninjatrader.com/support/f...ad.php?t=18890

This sample cancels the order if not filled within 3 bars, so you should be able to adapt to your needs.
Thanks a lot, I trtied hard, but still have not managed to complete the set. Would you mind and completed the script for me? This would be great, many thanks. I need to cancel the order after 5 bars or 20 minutes. The condition set is:

// Condition set 6 "Short 2v"
if (CCI(14)[0] < 0
&& CCI(14)[1] < 0
&& CCI(50)[1] < 0
&& CCI(14)[1] > -100
&& CCI(50)[1] > -100
&& CCI(14)[2] < CCI(14)[1]
&& CCI(14)[0] < CCI(14)[1] + -5
&& CCI(50)[2] < CCI(50)[1]
&& CCI(50)[0] < CCI(50)[1] + -5
&& ToTime(Time[0]) >= ToTime(15, 40, 0)
&& ToTime(Time[0]) <= ToTime(18, 0, 0))
{
EnterShortLimit(0, true, DefaultQuantity, Close[0] + -2 * TickSize, "Short2v");
}
Last edited by paatech; 08-16-2012 at 01:23 PM.
paatech is offline  
Reply With Quote
Old 08-16-2012, 02:00 PM   #7
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Unfortunately we are not able to custom code as it would limit our ability to provide support to everyone needing it. We're happy to help with any specific questions you have and if you would like professional custom coding development you can look into our 3rd party NinjaScript consultants here:

http://www.ninjatrader.com/partners
NinjaTrader_RyanM 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
MBTrading, Cancelled Orders, and Me bigfatdrunk Automated Trading 3 03-31-2011 06:41 AM
Order Entry time off by 2 minutes maiganrui Miscellaneous Support 2 10-19-2010 03:11 PM
orders got cancelled light7801 Strategy Development 6 05-04-2010 06:06 AM
NT cancelled ATM orders after bracket entry MTaylor123 ATM Strategies (Discretionary Trading) 1 02-04-2009 02:33 AM
NT cancelled ATM orders after bracket entry MTaylor123 ATM Strategies (Discretionary Trading) 0 02-03-2009 07:35 PM


All times are GMT -6. The time now is 12:42 PM.