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

Filtering trades based on Trading Hours

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

    Filtering trades based on Trading Hours

    Hi all,

    I am creating a strategy that need to enter orders only when the market is open. I am currently using ES. I was using:

    && Times[0][0].TimeOfDay >= new TimeSpan(9, 30, 0)
    && Times[0][0].TimeOfDay <= new TimeSpan(16, 0 , 0)

    The issue with this is that when I do a backtest it won't consider the changes in Day Saving Light changes and Holidays. Do you know a better alternative? (not only for backtest but also for the actual execution of the strategy),

    Thanks for any help,

    #2
    Hello Danilod,

    Thank you for your post.

    Why not just use an RTH chart for running the strategy/backtesting? You can change the selected trading hours in the Strategy Analyzer to CME US Index Futures RTH to have the strategy only run during RTH hours.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Yes, that's interesting. Could work but is not ideal: I have in the same code some entries that do need to be executed ETH so a way to define RTH and ETH session hours directly in the code would be much better. Any way of doing this?

      Thanks,

      Comment


        #4
        Maybe try this technique.

        Comment


          #5
          Hello Danilod,

          Thank you for your reply.

          It is possible to add series to a script and set the trading hours template for an added series. You can use the data from that added series in the script any where in place of the primary series. You could add an RTH data series to the chart and use a SessionIterator to get the start and end times for the RTH session, however, from the help guide:

          "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."

          Below is a public link to the help guide on AddDataSeries().
          https://ninjatrader.com/support/help...dataseries.htm

          It's probably simplest to code the strategy to have inputs for the RTH start and end times and manually adjust this for holidays/DST changes.

          I would also note that bltdavid's approach is not officially supported by NinjaTrader staff.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Thanks to both of you, I will set start times manually and see what happens. Thanks.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by elirion, Today, 01:36 AM
            0 responses
            3 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by gentlebenthebear, Today, 01:30 AM
            0 responses
            3 views
            0 likes
            Last Post gentlebenthebear  
            Started by samish18, Yesterday, 08:31 AM
            2 responses
            9 views
            0 likes
            Last Post elirion
            by elirion
             
            Started by Mestor, 03-10-2023, 01:50 AM
            16 responses
            389 views
            0 likes
            Last Post z.franck  
            Started by rtwave, 04-12-2024, 09:30 AM
            4 responses
            34 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Working...
            X