![]() |
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: Oct 2007
Posts: 49
Thanks: 0
Thanked 0 times in 0 posts
|
Hi support team,
I want to close a possible open posititon at a time I input into the strategy. Let's assume that I wan't close any position 20sec before 6 pm. My strategy works with "CalculateOnBarClose = true" and the interval is 8min. Normally there is no chance to trigger the close with that constellation, right? My possible solutions are looking as follow: 1. Using a internal Timer and the raising timer event will be checked to close the position. 2. Implementing the code in the callback "OnMarketData" 3. Or Developing a separate timer indicator which has the flag CalculateOnBarClose set to false; And in the ObBarUpdate I check the time and fired a event to the registered strategy. (this way I have implemented) Maybe there are some sideeffects with threadsafe data handling? Many Thanks.... cicondo |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
cicondo, in realtime this should work as ExitOnClose would reference your PC clock time for this. In backtesting you can submit orders to a finer datastream for execution and thus work off the finer timestamps then - http://www.ninjatrader-support2.com/...ead.php?t=6652
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Member
Join Date: Oct 2007
Posts: 49
Thanks: 0
Thanked 0 times in 0 posts
|
Hi Bertrand,
thanks to your quick answer. But what I missed to explain is that I don't want to set the session start or end values. This is because the strategy starts and ends trading in several timed blocks during the day. So it is possible to trade between 9:30am to 11:am then from 1 pm until 5:30pm and so on... Hope this makes something clear... By the way are there any sideeffects using events to cooperate with a strategy? Thanks Bertrand Quote:
|
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
cicondo, I'm not aware of side effect when using custom events in a strategy. You might want to consult this reference sample - http://www.ninjatrader-support2.com/...ead.php?t=5965
You of course don't have to use the session linked ExitOnClose feature, you can also achieve a time exit of positions using the Time / DateTime comparisons - http://www.ninjatrader-support.com/H...deV6/Time.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Oct 2007
Posts: 49
Thanks: 0
Thanked 0 times in 0 posts
|
Bertrand!
PERFECT! This is excactly what need to be sure that events will work. This will clean up my code really. Thank's for your support! cicondo |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How do I get the value of a bar at a specific time | TraderFoo | Strategy Development | 5 | 06-23-2009 12:42 PM |
| Prior Day Close at a specific time | cre8it8 | General Programming | 9 | 12-23-2008 10:33 AM |
| Close order next day at specific time | diffused | Strategy Development | 3 | 11-19-2008 09:14 AM |
| price at specific time | Kowal | General Programming | 2 | 10-06-2008 08:43 AM |
| How to get the highest/lowest close of a specific time range. | strategy1 | General Programming | 4 | 07-23-2008 10:18 PM |