![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
BigDog008, please take a look at this sample for custom timer events used in NinjaScript - http://www.ninjatrader-support2.com/...ead.php?t=5965
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Dec 2008
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
could I use the ToTime() function?
ie... some_variable = ToTime(Time[0]) and then... if ToTime(Time[0]) > some_variable + 10 CancelOrder() ?? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
This should also do it, or count the bars since order placement on a added tick or second timeframe.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
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).
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
wahooj,
I am not exactly sure what you mean by 'barNumberOfOrder'. Can you please clarify?
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
|
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... |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
I will have someone reply to you on Monday. Thank you for your patience.
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Member
Join Date: Mar 2010
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
|
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
|
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
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
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |