Announcement

Collapse
No announcement yet.

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.

    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.

          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 NullPointStrategies, Yesterday, 05:17 AM
            0 responses
            56 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            133 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            73 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            45 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            49 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X