Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-timeframe backtesting with intrabar granularity

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

    Multi-timeframe backtesting with intrabar granularity

    Hello,

    I am backtesting a estrategy on daily bars (as primary bars) with sixty minutes intraday bars as secondary. I only want to use the intraday bars for market open times only, not pre or post market data.

    Can I do that within the code of the estrategy?. If not, how can I set it up?

    Thanks for your help.

    #2
    Miggers,

    Yes, you can configure it to use whichever bar series you want to use for your signals and such. Just use the BarsInProgress that is relevant to your needs. Please see information here for the basics of multi-series strategies: http://www.ninjatrader-support.com/H...ameInstruments

    You can also see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=6652
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Josh, thank you for your reply.

      I am already familiar with both of the links you mentioned, both have been very useful to help me build my strategy.

      The problem I'm having is as follows: I use the OHLC data of the daily (Primary) bars to setup my entry and exit prices. The OHLC data is based on the regular market open hours (09:30 - 16:00 US ET), the Secondary bars (60min) go outside the regular market hours, so my orders are getting filled by the 60 min bars outside the market regular session, which I don't want to happen.

      For example, let's say I have a long position open, with today OHLC bar data I calculate my protective stop for tomorrow and pass the stop from the BarsInProgress = 0 to BarsInProgress = 1. Despite tomorrow's Low being higher than the stop, the stop may get filled anyway, because the secondary bars dipped below the stop and went back above it outside the regular market session.

      How can I code or setup my strategy so that it ignores all the secondary bars outside regular market hours?

      My current OnBarUpdate() method looks like this (in summary):

      If(BarsInProgress == 0)
      {
      Calculate entries, stops and targets...
      EntryLong(0, EntryPrice... I pass the entry to the Primary
      StopLoss (1, StopPrice... I pass the exits to the Secondary
      LimitTarget(1, LimitPrice...
      }
      else return; In the secondary bars code do nothing...


      Thank you for your help

      Comment


        #4
        Miggers,

        If you are not using ETH hours you could just limit your whole strategy to ignore that data through the session definitions of start and end times. This would be done in the UI as you run the strategy.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Miggers,

          Instead of using 60 min bars (that straddle the session open) to achieve "intra session" granularity, could you not use a lesser timeframe (e.g. 30 mins, 15 mins, etc) where a new bar starts cleanly with the session open?

          Comment


            #6
            AnotherTrader, thank you for your comment.

            You're right 60min bars will not work properly in my strategy given the Opening and Closing market times, I have already changed it to 30min. I noticed my mistake last night as I was writing my second post, but decided not to comment on it as I didn't find it relevant to the central issue.

            I don't want to use a much finer time frame because I'm planning to backtest few years back for different symbols, so the amount of historical data would get too large.

            Josh's comment on using the backtest UI would do the job (haven't tried yet...), but I would still like to do it inside the code of the strategy. Any ideas?

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            574 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X