Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-time frame for backtesting barsinprog/entry

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

    Multi-time frame for backtesting barsinprog/entry

    Guys is there a sample script here that demonstrates how you should employ both of these if you're just trying to add a smaller timeframe to your chart for accuracy?

    The one I saw before just has barsinprogress == 0 in and that just produces a "you must use the overload that has a 'barsinprogress' parameter....." error when running from OnBarUpdate. It's not clear how to employ both to achieve this simple goal.

    Thanks..!

    #2
    PS. 15M for primary with 1M for secondary would be perfect

    Comment


      #3
      Hello Darrentate,

      Thank you for your post.

      I would recommend that you take a look at the reference sample on multiple timeframes available in NinjaTrader by going to Tools -> Edit NinjaScript -> Strategy - > SampleMultitimeframeStrategy

      Additionally, here is reference sample from our forum page -
      http://www.ninjatrader.com/support/f...ead.php?t=6652

      Let me know if I can be of further assistance.
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Thanks but that was the script I referred to that created the error "you must use the overload that...."

        Comment


          #5
          Darrentate,

          Is this for submitting orders?

          How are you submitting the orders in the script?

          What is the full error message you are receiving?
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            Orders can be submitted with either EnterLong(contractno,signalname) or EnterLongLimit(contractno,price,signalname) depending on a user defined parameter.

            I want to be able to process the 15M but using the intrabar data for accuracy provided by a 1m or tick chart.

            I have added the same instruments secondary time frame using:

            Add(this.Instrument.FullName, PeriodType.Minute, 1, MarketDataType.Bid);
            Add(this.Instrument.FullName, PeriodType.Minute, 1, MarketDataType.Ask);

            Inside the OnBarUpdate (which calls lots of other methods such as OnOrderUpdate etc.) I have inserted:

            if (BarsInProgress == 0)
            { does the rest of the OnBarUpdate code
            else
            {return
            }

            I tried adding a "1" to the start of the EnterLong / EnterLongLimit function to refer to the correct bar array which just created more errors.

            The error I'm getting is "you must use the overload that has a 'BarInProgress' parameter when calling the BarsSinceEntry() method in the context of a multi-time frame and instrument strategy.

            I used BarsSinceEntry for a check (but just BarsSinceEnter(signalname)). Maybe the problem is that I have to refer to the correct BarArray?

            Comment


              #7
              Darrentate,

              Correct, when using multiple time frames there is an additional overload for this -
              Code:
              BarsSinceEntry(int barsInProgressIndex, string signalName, int entriesAgo)
              http://www.ninjatrader.com/support/h...sinceentry.htm

              Let me know if I can be of further assistance.
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Thanks Cal.... well as you asked...

                Any thoughts why a strategy in backtest mode wouldn't be taking all the trades that it takes when running live / market replay? It seems to miss out at least a third of them which it wouldn't otherwise.

                Comment


                  #9
                  Darrentate,

                  Its going to depend on how you run the strategy in live vs back-test

                  Below is a link from our help guide on understanding these differences -
                  http://www.ninjatrader.com/support/h...ime_vs_bac.htm

                  Let me know if I can be of further assistance.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Well I've chosen liberal with a market order set and am using tick data so it's strange 80% aren't being filled still even based on those algorithms.

                    Comment


                      #11
                      Darrentate,

                      What do you set the Property CalculateOnBarClose to when running live?

                      FillType is only going to really apply to Limit orders in this case. -

                      When using Limit orders, using the default fill type, the price must go through the limit price in order to fill

                      With Liberal, the price must touch it.
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        Cal,

                        I setup another post on this.

                        I removed some code earlier that did a health check for a VPS. Suddenly the system took all the trades and all was well.

                        Then several hours ago it stopped and it went back to how it was taking just 10% of the trades.

                        CalculateOnBarClose live has to be false as it's a tickbytick computated strategy.

                        Comment


                          #13
                          Darrentate,

                          Just to clarify here, the backtest will only run on OnBarUpdate() Calculation per bar when running. This can cause different scenario with regards to trades being taken when you are running tick by tick.
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Cal can that not be overcome then by implementing the second time frame on a tick by tick basis?

                            What's thrown me is earlier it appeared to be taking all the trades at the correct point (which then later stopped). I assumed this was happening because of the second time frame.

                            Could one potentially derive the general parameters that are required from BarsInProgress == 0 then create the code that takes the trades and implement it in the BarsInProgress == 1 as a workaround?

                            Comment


                              #15
                              Hello darrentate,

                              By adding a 1 tick series you would be adding the granularity needed to make a more accurate backtest.

                              By processing on the second added data series (BarsInProgress 1) you will be processing with the tick data.

                              I want to confirm that you have historical minute ask and bid data available. Who are you connected to for data?
                              Chelsea B.NinjaTrader Customer Service

                              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
                              573 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X