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

SessionIterator

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

    SessionIterator

    Hello,

    How can I use the SessionIterator to get the start and end times for the RTH session?

    Thanks.

    #2
    Hello AdeptistJune,

    Thanks for your post.

    SessionIterators require a Bars object to be created. If you want to use a SessionIterator for Trading Hours that are different than the primary data series, you would need to add a data series with the new Trading Hours template, then use the BarsArray[X] for that data series to create the SessionIterator in/after State.DataLoaded.

    As I understand, you are trying to work around a behavior where if multiple data series are added with different templates, all data series first need to be aligned. See warning in AddDataSeries

    This would mean that adding another data series to use the SessionIterator would not be a solution for you. You could use user input variables for the RTH times, or you could parse the TradingHours template on your own and compare with the current bar timestamp (Time[0])

    Parsing the TradingHours template would involve remaking a bit of logic that is done in a SessionIterator. I do not have any example code prepared to navigate that, but you could look into checking the Sessions collection for regular session hours and PartialHolidays collection for holiday late starts/early closes.

    TradingHours.Get("CME US Index Futures RTH")

    TradingHours - https://ninjatrader.com/support/help...adinghours.htm

    TradingHours.Sessions - https://ninjatrader.com/support/help...s_sessions.htm

    TradingHours.PartialHolidays - https://ninjatrader.com/support/help...alholidays.htm

    I have attached some rough examples to get you started for setting up conditions to check if you are in a new session using user input variables, and to hold onto the prior day's values. You can also see how this could work adding the additional data series and SessionIterator.

    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Hello, JIm,

      I figured out a way to get the code to work. I had to add a data series the script.

      Comment


        #4
        My attempt is slightly different. I would like to have the futures instrument ETH series on chart display however in my strategy I would like to reference the RTH template to actually trade the specified regular hours and have RTH determined values like IsFirstBarOfSession etc - any help please? Also need to determine the RTH timezone mapped to my timezone (i.e. CST to EST)

        Comment


          #5
          Hello WattMan,

          Thanks for your message.

          You could add an RTH data series to the script to make it a multi time frame script, and then you would be able to use items like IsFirstBarOsSession on that data series.

          AddDataSeries(string instrumentName, BarsPeriod ba rsPeriod, string tradingHoursName)
          AddDataSeries(string instrumentName, BarsPeriod ba rsPeriod, string tradingHoursName, bool? isResetOn NewTradingDay)
          AddDataSeries(string instrumentName, BarsPeriod ba rsPeriod, int barsToLoad, string tradingHoursName, bool? isResetOnNewTradingDay)


          AddDataSeries - https://ninjatrader.com/support/help...dataseries.htm

          Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

          However, please keep in mind the note from the AddDataSeries documentation:

          If your NinjaScript object is using AddDataSeries() allowing to specify a tradingHoursName, please keep in mind that: An indicator / strategy with multiple DataSeries of the same instrument will only process realtime OnBarUpdate() calls when a tick occurs in session of the trading hour template of all added series. Any ticks not processed will be queued and processed as a tick comes in for all subsequent DataSeries.
          If this is prohibitive for you needs, you could consider operating on the ETH data series only, and then use time checks to identify when you are in the RTH session.
          JimNinjaTrader Customer Service

          Comment


            #6
            Hello, WattMan,

            Let me if this helped.
            Attached Files
            Last edited by AdeptistJune; 02-03-2022, 12:09 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by geddyisodin, Yesterday, 05:20 AM
            7 responses
            45 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by gbourque, Today, 06:39 AM
            2 responses
            5 views
            0 likes
            Last Post gbourque  
            Started by cre8able, Yesterday, 07:24 PM
            1 response
            13 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by cocoescala, 10-12-2018, 11:02 PM
            6 responses
            939 views
            0 likes
            Last Post Jquiroz1975  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            1 response
            19 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X