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

Determine Market Open from Addon

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

    Determine Market Open from Addon

    Is there a way to determine if the Market is open from an Addon?

    I know there is SessionIterator but it requires a Bars object. I see it offers a TradingHours constructor as well.

    I tried passing in a TradingHours template as obtained from an instrument through Instrument.MasterInstrument.TradingHours. This seems to retrieve data for the the last 6 years going from 2015 through to 2021. What happens if I want/need more historical information going back further then 2015?


    #2
    Hi ntbone, thanks for your question.

    The trading hours for the BarsRequest can be set like this:
    barsRequest.TradingHours = NinjaTrader.Data.TradingHours.Get("CME US Index Futures RTH");

    The BarsRequest does return a Bars object to use, so one can use the Bars.IsFirstBarOfSessionByIndex() method. Here is what I did in the Addon Framework example to demonstrate:

    Code:
    private void PrintBarsRequest(NinjaTrader.Data.BarsRequest bars)
    {
    outputBox.Text = "REQUESTED BARS: " + bars.Bars.Count;
    
    SessionIterator sessionIterator = new SessionIterator(bars.Bars);
    
    // Process returned bars here. Note: The last returned bar may be a currently in-progress bar
    for (int i = 0; i < bars.Bars.Count; i++)
    {
    if(bars.Bars.IsFirstBarOfSessionByIndex(i))
    {
    sessionIterator.GetNextSession(bars.Bars.GetTime(i ), true);
    
    // store the desired session information
    DateTime tradingDay = sessionIterator.ActualTradingDayExchange;
    DateTime beginTime = sessionIterator.ActualSessionBegin;
    DateTime endTime = sessionIterator.ActualSessionEnd;
    
    outputBox.AppendText(string.Format("The Current Trading Day {0} starts at {1} and ends at {2}{3}",
    tradingDay.ToShortDateString(), beginTime, endTime, Environment.NewLine));
    }
    
    outputBox.AppendText(string.Format("{0}Time: {1}{0}Open: {2}{0}High: {3}{0}Low: {4}{0}Close: {5}{0}Volume: {6}{0}",
    Environment.NewLine,
    bars.Bars.GetTime(i),
    bars.Bars.GetOpen(i),
    bars.Bars.GetHigh(i),
    bars.Bars.GetLow(i),
    bars.Bars.GetClose(i),
    bars.Bars.GetVolume(i)
    ));
    }
    
    }
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I am not needing to do BarsRequest though either. Having to do a BarsRequest just to get the trading ours just to get an SessionIterator seems like quite a bit of overhead.

      The following does the job and does not require me doing a BarsRequest to get it.

      Code:
      var sessionIterator = new SessionIterator(TradingHours.Get("US Equities RTH"));
      Looking at what is contained in the Trading Hours templates either through the NinjaTrader UI or through code shows that the trading hours data only extends as far back as 2015. What happens if I try to go back earlier? A brief test shows that it doesn't seem to correctly calculate trading hours for holidays prior to 2015.

      Comment


        #4
        Hi ntbone, thanks for your reply.

        That override is not documented so I can not say it should be used (if it's not documented it is possible it's not meant to be used at all). We have holiday info from the release of NinjaTrader 8, unfortunately, the prior holiday info is not kept on our servers and a custom trading hours template would need to be created that holds dates further than 2015.

        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Understood. I noticed the it was flagged to not even show up as browesable. Feature request to make this an official API as having to do a bars request just to get the trading session is undesirable.

          In my situation I want to know what time the US markets open next as the add-on has to do some things at market open. It doesn't need market data for anything it does.

          Comment


            #6
            Hi ntbone,

            I'll submit a feature request for this. I found this publicly available API that can be used to get trading hours data:
            TradingHours.com is the most trusted source for financial calendar reference data. Industry leading accuracy and reliability. Trading Hours, Market Holidays, Non-Settlement Dates, Currency Holidays and Irregular Schedules for hundreds of markets around the globe.


            You can also parse the template data with an XML reader, the templates are held in Documents\NinjaTrader 8\templates\TradingHours.

            Best regards,
            -ChrisL
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi ntbone,

              The feature tracking ID is SFT-5283

              Please check the release notes upon future updates to check for added features with the ID:
              https://ninjatrader.com/support/help...ease_notes.htm

              Best regards,
              -ChrisL
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by suroot, 04-10-2017, 02:18 AM
              5 responses
              3,021 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by Stanfillirenfro, Today, 07:23 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by cmtjoancolmenero, Yesterday, 03:58 PM
              2 responses
              22 views
              0 likes
              Last Post cmtjoancolmenero  
              Started by olisav57, Yesterday, 07:39 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by cocoescala, 10-12-2018, 11:02 PM
              7 responses
              944 views
              0 likes
              Last Post Jquiroz1975  
              Working...
              X