Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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();
    	}
    	
    	[COLOR="Green"]//if the instrument is on the Eurex and the time is 
    	//at least 5 minutes before the end of the session[/COLOR]
    	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 rdtdale, Today, 01:02 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by alifarahani, Today, 09:40 AM
    3 responses
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by RookieTrader, Today, 09:37 AM
    4 responses
    18 views
    0 likes
    Last Post RookieTrader  
    Started by PaulMohn, Today, 12:36 PM
    0 responses
    9 views
    0 likes
    Last Post PaulMohn  
    Started by love2code2trade, 04-17-2024, 01:45 PM
    4 responses
    41 views
    0 likes
    Last Post love2code2trade  
    Working...
    X