Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

several doubts regarding - exit on session close - commands

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    several doubts regarding - exit on session close - commands

    good day to everyone,


    i am interested in having all my strategies close all positions before the regular session ends, both on historical data for optimization and testing purposes and also on tick by tick live data if i was executing my strategies for real. i have read some posts in these fora regarding - exit on session close - but i don't think any of them addressed what i have in mind.


    i use large bars like 60 minute and 25 cents range bars on the cl contract and other instruments from different exchanges like eurex, nymex and cme, so i don't think the ordinary - exit on session close - command would get the job done for me.

    i think i can easily add a time filter to the conditions my strategies follow for entries to guarantee no positions will be held outside of the regular session, but what would the best method be so that;

    - ¿all positions on eurex instruments are closed 5 minutes before the end of the regular session (2200 cet as far as i know)?
    - ¿all positions on nymex instruments are closed at 1655 et?
    - ¿all positions on cme instruments are closed at 1610 et?


    in all cases, i'm interested in ensuring all positions are closed both for historical and real time data and i wouldn't mind if i had to create one piece of code for each case or had to add a secondary data series to my strategies to close all positions at the desired times.


    thanks, regards.

    #2
    Hello rtwave,
    Thanks for your post.

    Adding a time filter with Time and ToTime would allow you to close out your positions 5 minutes before the session ends like you describe. If you were running the same strategy for more than one instrument you would also need to add conditions for the exchange as well. To access the exchange property of the instrument and use it as a condition you will need to use foreach(). You could accomplish all this with something similar to the following snippet.

    Code:
    private string myExchange;
    protected override void OnBarUpdate()
    {
    	foreach(var exchange in Instrument.MasterInstrument.Exchanges)
    	{
    		myExchange = exchange.ToString();
    	}
    	
    	//if the instrument is on the Eurex and the time is 
    	//at least 5 minutes before the end of the session
    	if (myExchange == "Eurex" && ToTime(Time[0]) >= 215500)
    		ExitLong();
    }
    I am including links to a forum post that discusses how to add a time filter to your strategy as well as the relevant NinjaScript methods below, for your convenience.

    Using a time filter to limit trading hours
    https://ninjatrader.com/support/foru...ead.php?t=3226

    Time Series
    https://ninjatrader.com/support/help...eries_time.htm

    ToTime()
    https://ninjatrader.com/support/help...us/?totime.htm

    Please let me know if you have any further questions.
    Josh G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by toughiee, Today, 12:04 AM
    0 responses
    2 views
    0 likes
    Last Post toughiee  
    Started by vdoan20, Yesterday, 08:30 PM
    0 responses
    7 views
    0 likes
    Last Post vdoan20
    by vdoan20
     
    Started by gupagoer, Yesterday, 07:42 PM
    0 responses
    9 views
    0 likes
    Last Post gupagoer  
    Started by Holligoly, Yesterday, 05:13 PM
    2 responses
    11 views
    0 likes
    Last Post Holligoly  
    Started by Raginpower, Yesterday, 01:53 PM
    0 responses
    14 views
    0 likes
    Last Post Raginpower  
    Working...
    X