![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I've searched the forum with no luck for a simple way to cancel an order after several bars have printed. I'm using a Ninjascript strategy that does NOT call an ATM strat. I've looked at BarsArray but they all seem to apply to indicators on a multi time frame chart. Is there any way to do this using a variable and possibly a BarsArray? For instance, if order is placed, set a variable orderplaced = 1 then if 6 bars have printed without the order being filled, reset the variable back to 0 so the order is automatically cancelled on the next bar? I just need some way to start the bar count when the order is placed. Thanks, Joe |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Joe,
You can use BarsSinceEntry(). Code:
if (BarsSinceEntry() > 10)
CancelOrder(someIOrder);
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Josh,
I don't think that will work since there is no Entry, just a pending order that has been placed. However, I think I found the answer in Help, under Cancel Order. Here it is for anyone looking at this thread. private IOrder myEntryOrder = null; private int barNumberOfOrder = 0; protected override void OnBarUpdate() { // Submit an entry order at the low of a bar if (myEntryOrder == null) { myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry"); barNumberOfOrder = CurrentBar; } // If more than 5 bars has elapsed, cancel the entry order if (myEntryOrder != null && CurrentBar > barNumberOfOrder + 5) CancelOrder(myEntryOrder); } I tried it and it works great. Thanks Anyway, sorry to bother you! Joe |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Glad you figured it out...
Ray
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| summary of "strategy realized" is not equal "account performance, total net profit"" | Fragolino | Miscellaneous Support | 1 | 02-19-2009 04:12 AM |
| Difference between"Bars ago" & "look Back" | ju1234 | Strategy Development | 3 | 11-21-2008 10:56 AM |
| Please add "Calmar" and "Sterling" ratios to Performance._Trades.TradesPerformance | Elliott Wave | Suggestions And Feedback | 2 | 06-10-2008 09:57 PM |
| the forum can not remember the settings of "Sorted by" and "Sort Order" | clearpicks | Suggestions And Feedback | 1 | 05-23-2008 12:05 PM |
| "'OrderRejected'. Strategy has sent cancel requests" & "There is no market data..." | Elliott Wave | Strategy Development | 6 | 04-12-2008 12:03 AM |