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-21-2009, 05:16 AM   #1
cicondo
Member
 
Join Date: Oct 2007
Posts: 49
Thanks: 0
Thanked 0 times in 0 posts
Question Close a position to a specific time

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
cicondo is offline  
Reply With Quote
Old 07-21-2009, 05:36 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-21-2009, 06:31 AM   #3
cicondo
Member
 
Join Date: Oct 2007
Posts: 49
Thanks: 0
Thanked 0 times in 0 posts
Exclamation

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:
Originally Posted by NinjaTrader_Bertrand View Post
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
cicondo is offline  
Reply With Quote
Old 07-21-2009, 06:45 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

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
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-21-2009, 07:47 AM   #5
cicondo
Member
 
Join Date: Oct 2007
Posts: 49
Thanks: 0
Thanked 0 times in 0 posts
Default

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
cicondo 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
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


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