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 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 07-03-2009, 03:13 PM   #1
Trade1953
Member
 
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
Default Cancel Order after "X" Bars have printed

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
Trade1953 is offline  
Reply With Quote
Old 07-03-2009, 03:24 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Joe,

You can use BarsSinceEntry().

Code:
if (BarsSinceEntry() > 10)
     CancelOrder(someIOrder);
NinjaTrader_Josh is offline  
Reply With Quote
Old 07-03-2009, 04:43 PM   #3
Trade1953
Member
 
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
Default

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
Trade1953 is offline  
Reply With Quote
Old 07-04-2009, 01:26 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Glad you figured it out...
NinjaTrader_Ray 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
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


All times are GMT -6. The time now is 03:10 PM.