Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trading gaps, need a market-on-open for backtesting

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

    Trading gaps, need a market-on-open for backtesting

    I want to write a strategy to backtest a theory that I can make money trading gaps.

    I can't work out how best to implement this.

    My first attempt was no good because the order is executed on the second bar after the gap is formed, whereas I want to enter at the market as soon as the Open[0] of the first bar arrives.

    I realise i can do this in real-time with CalculateOnBarClose = false, but this doesn't work in backtesting.

    The closest I can get is to use 1 minute bars but then I see I miss a considerable number of ticks.

    Can I place a conditional Market-on-Open i.e. with a stop? I figure this would move into the realm of Unmanaged Orders, as long as I can backtest it.

    Can't find anything in the Help or the forum messages.

    Thanks.

    #2
    adamus, please try adding in a 1 tick series, and then send your orders to that series. You'd be at most 3 ticks late on the entry in that case. There is a reference sample for backtesting with an intrabar granularity.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Austin,

      I have two issues with that.

      Firstly, I have tick data from a third party data provider against which I will test going back to 1997 - but that will take huge amounts of time to run backtests on with a 1 tick series.

      Secondly I have no tick data from Interactive Brokers whom I trade with and I would prefer to do my final backtesting against the data against which I will trade.

      Is there any mechanism I can implement on the order API?

      Thanks

      Comment


        #4
        Unfortunately NinjaTrader does not currently support Market On Open orders.
        AustinNinjaTrader Customer Service

        Comment


          #5
          OK, slightly disappointed but I guess there is no robust way to simulate a market order execution placed once the Open[0] tick is read.

          It's also obviously disappointing that IB don't provide tick data.

          The limits of our technical abilities have been reached, methinks.

          Comment


            #6
            Austin, I've got a related question trying to code this up.

            I'm using a 1 tick series as advised.

            I need the range for Friday, High - Low and I need to access this information in the onBarUpdate for the tick series on the first onBarUpdate on Sunday.

            What's the easiest most performant way to do this?

            Shall I add a 1 day bar time series and set CalculateOnBarClose = true and then do this:

            fridayRange = High[1] - Low[1];

            or is it

            fridayRange = High[0] - Low[0];

            Or is there a better way, from a processing speed point of view?

            Comment


              #7
              adamus, I think just using the PriorDayOHLC for the range would be more performing than adding a series for this task.

              Comment


                #8
                Hi Bertrand,

                I'm trying it with the PriorDayOHLC and I'm getting completely different values for the bars on the Friday in the daily bars and the PriorDayOHLC().High etc.

                My instruments are set to session template: forex

                The PriorDayOHLC output seems to be showing much smaller bars. i.e. as if it were reading bars from the minute bars series.

                Yet PriorDayOHLC should show the actual previous day's OHLC, isn't that so?

                I guess I should look in the source.

                Comment


                  #9
                  adamus, the indicator would be tied to the chart session set, correct - to which series are you attempting to apply it? It would be working for intraday ones only.

                  Comment


                    #10
                    Hmm, I'm not quite sure I follow you.

                    These are the values I'm trying to get when BarsInProgress=1 means the 1 day time series I added as the second bars.

                    HTML Code:
                    if (BarsInProgress == 1 && Time[0].DayOfWeek == System.DayOfWeek.Friday)
                        Print("High==" + High[0] + " Low==" + Low[0] + " Close==" + Close[0]);
                    And this is how I'm trying to get them using PriorDayOHLC() - the bars series is either 1 tick bars or 1 minute bars.

                    HTML Code:
                    private PriorDayOHLC friday;
                    
                    //onStartUp
                    friday = PriorDayOHLC();
                    
                    //onBarUpdate 
                    if (BarsInProgress == 0 && Time[0].DayOfWeek == System.DayOfWeek.Sunday)
                    double fridayRange = friday.High[0] - friday.Low[0];
                    double gapStart = friday.Close[0];

                    Comment


                      #11
                      This likely would not work.

                      "friday" is an indicator object. There is no such thing of High or Low, etc. from that indicator. To access the values of that indicator you need to call the correct plot names for them which are PriorOpen, PriorClose, etc.



                      It would be friday.PriorHigh[0] for example.
                      Josh P.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      633 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      364 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      105 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      567 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      568 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X