• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 PeterGolz, 01-17-2020, 10:42 AM
    11 responses
    72 views
    0 likes
    Last Post reubenlasky  
    Started by utilizator, Today, 11:36 AM
    0 responses
    4 views
    0 likes
    Last Post utilizator  
    Started by EnveousColnago, Today, 07:24 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Started by tornadoatc, Today, 10:31 AM
    0 responses
    3 views
    0 likes
    Last Post tornadoatc  
    Started by EnveousColnago, Yesterday, 05:43 PM
    5 responses
    34 views
    0 likes
    Last Post EnveousColnago  
    Working...
    X