![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
|
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); } |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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);
}
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
|
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"); } } } |
|
|
|
|
|
#4 |
|
Junior Member
Join Date: Jul 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#6 | |
|
Junior Member
Join Date: Jul 2012
Posts: 5
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
// 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.
|
|
|
|
|
|
|
#7 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |