NinjaTrader Support Forum  

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-14-2009, 08:34 AM   #1
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default Cancelling limit orders based off of time...

Is there a stopwatch feature in Ninja Trader that allows me to cancel orders based off of time?

Say I place a limit order... then after 10 seconds pass, I want to cancel the order.... so I can place it again anything of the such?
BigDog008 is offline  
Reply With Quote
Old 07-14-2009, 08:52 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

BigDog008, please take a look at this sample for custom timer events used in NinjaScript - http://www.ninjatrader-support2.com/...ead.php?t=5965
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-14-2009, 09:10 AM   #3
BigDog008
Senior Member
 
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

could I use the ToTime() function?

ie...

some_variable = ToTime(Time[0])

and then...

if ToTime(Time[0]) > some_variable + 10

CancelOrder()

??
BigDog008 is offline  
Reply With Quote
Old 07-14-2009, 09:14 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

This should also do it, or count the bars since order placement on a added tick or second timeframe.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 04-09-2010, 09:49 AM   #5
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

Bertrand,

I know this thread hasn't been updated in awhile but...

How would you count the bars since order placement? and can this be done on a millisecond time frame?
wahooj is offline  
Reply With Quote
Old 04-09-2010, 10:02 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

For a basic start you can check into the snippet we have on the CancelOrder page - http://www.ninjatrader-support.com/H...ncelOrder.html

This could of course also be done after the order reports for example filled (checking IOrder object fillstates).
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 04-09-2010, 11:29 AM   #7
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

the cancelorder page seems that will do it, However what would you suggest to replace barNumberOfOrder with that would put it in a Time parameter? Or could i use barNumberOfOrder and set that equal to something other than CurrentBar that would also put it into seconds or milliseconds.
wahooj is offline  
Reply With Quote
Old 04-09-2010, 01:37 PM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

wahooj,

I am not exactly sure what you mean by 'barNumberOfOrder'. Can you please clarify?
NinjaTrader_Josh is offline  
Reply With Quote
Old 04-09-2010, 06:17 PM   #9
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

barNumberofOrder is used as a variable in the help file.
http://www.ninjatrader-support2.com/...ead.php?t=5965

In the cancel example, barNumberofOrder variable is set = 0, and then set as Currentbar which is an int. What variable type would I create if I later want to set it to a time format (seconds or millisecs).
So, if I used the cancel example:

private IOrder myEntryOrder = null;
private ?? variable = 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");
variable = _Some Time Format_;

// If more than 5 bars has elapsed, cancel the entry order
if (_Some Time Format_ > variable + 5)
CancelOrder(myEntryOrder);
}

hope i made sense...
wahooj is offline  
Reply With Quote
Old 04-11-2010, 10:36 PM   #10
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

I will have someone reply to you on Monday. Thank you for your patience.
NinjaTrader_Ben is offline  
Reply With Quote
Old 04-12-2010, 04:35 AM   #11
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

wahooj, either you work directly with a DateTime in C# or you convert to an Int for easier handling via the ToTime() method -

http://www.ninjatrader-support.com/H...V6/ToTime.html
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 04-12-2010, 08:00 AM   #12
wahooj
Member
 
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
Default

Would it be something similar to how BigDog008 did it below, because i tried that in market replay mode and realtime simulator with no luck. I don't think I had log errors but I'll try it again. thanks
wahooj is offline  
Reply With Quote
Old 04-12-2010, 08:33 AM   #13
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
Default

wahooj, yes in general that approach should work - you would need to ensure the timeframe you're working on offers enough granularity in timestamps for your rules to trigger. For this it would be best work with Print statements throughout code and our TraceOrders feature to debug.

http://www.ninjatrader-support.com/H...aceOrders.html
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
Multiple Time Bars & Limit Orders NIKI01 Automated Trading 3 10-06-2008 07:15 AM
Limit Orders Pile Up In Real Time JOHN FORTUNE Automated Trading 5 06-26-2008 03:06 PM
Auto cancelling opposing orders (stop/targets) did not work in real-time... dtf139 Miscellaneous Support 3 06-23-2008 04:07 AM
How to put a time limit on orders sent from TradeStation to NT joeplaya Automated Trading 7 03-24-2008 11:53 AM
Entering orders based on time mtrader ATM Strategies (Discretionary Trading) 0 03-28-2005 01:23 AM


All times are GMT -6. The time now is 11:19 PM.