Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Secondary Series for Intrabar Order Granularity in Backtest

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

    Using Secondary Series for Intrabar Order Granularity in Backtest

    Currently in NT7, to get the most accurate fills when backtesting a strategy (particularly if the entry and exit can occur on the same bar) one would add a 1-tick or 1-second secondary dataseries to accurately resolve the order fill price. In NT8, when applying a strategy, there is a new “Order fill resolution” of “High” where you can select a minute, second, or tick granularity. I have a few questions pertaining to this new feature:

    a) If the strategy is being backtested with an "Order fill resolution" of 1-tick or 1-second granularity, do I still need to add a secondary series for this purpose in the strategy?

    b) If the strategy is being backtested on minute based bars, will the necessary tick-based data for the second and tick resolutions be automatically downloaded? (This is not the case in NT7)

    c) If the minute data goes back farther than the available tick-based data, how will the end-user know these are out of sync? (No notification in NT7)

    Thanks!

    Whitmark
    whitmark
    NinjaTrader Ecosystem Vendor - Whitmark Development

    #2
    Originally posted by whitmark View Post
    a) If the strategy is being backtested with an "Order fill resolution" of 1-tick or 1-second granularity, do I still need to add a secondary series for this purpose in the strategy?
    No - if you're just adding these for executions, you do not need to AddDataSeries() - you'd only need to do that if you're trying to calculate signals from another time frame

    Originally posted by whitmark View Post
    b) If the strategy is being backtested on minute based bars, will the necessary tick-based data for the second and tick resolutions be automatically downloaded? (This is not the case in NT7)
    Yes - they should be downloaded. There is logic in place and we are happy with our tests. However hard to test all situations, so let us know if you run into problems.

    Originally posted by whitmark View Post
    c) If the minute data goes back farther than the available tick-based data, how will the end-user know these are out of sync? (No notification in NT7)
    There is no error handling here, but will only Execute orders for when you have data for both the primary and high resolution series.

    For example:

    - You are testing on a 1 minute series, and add a High 1 tick series
    - You setup your back test to run on 365 days of data
    - You have 365 days of minute data
    - You only have 120 days of tick data
    -> Executions will only occur on the last 120 days of data.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Using Ask and Bid tick data in backtesting.

      In order to create a reliable backtest, a profit must be computed as follows:
      For a long trade enter at bid tick exit at ask tick.
      For a short trade enter at ask tick, exit at a bid tick.
      Once one have a tick data, this is the only reliable backtesting scenario.
      In NT7 I am able to add my bid and ask tick data, but I'm not able to implement the scenario above. There is even a problem to submit an order based on my additional bid/ask data series and it is impossible to program NT7 strategy to enter a bid data and to exit on ask data. So I am working hard to create my own backtesting system, completely independent of NT7 strategy backtest. Of course I can define a commission in the Strategy Analyzer, but a commission is fixed and a spread is changing all the time.
      Regarding NT8 :
      1) Will it be possible to submit a historical data order based exactly on bid/ask tick series which are additional data series? It means, when I'm submitting a managed order like
      EnterShort(BarsInProgress, quantity, shortSignalName) ;
      I would expect that the backtesting price will be a tick data of [BarsInProgress] series. It's not a case currently in NT7.
      2) I would suggest to add a feature to Strategy Analyzer – a possiblity to adjust programatically profit/loss on exit, according to the spread on exit time. Once I have a bid and an ask tick data, I know the spread. Deducting it for the profit and adding it to the loss would solve a problem.

      Comment


        #4
        We did overhaul the backtest engine in NinjaTrader 8 from NinjaTrader 7 however the feature of using bid/ask data did not make the cut. I will add your suggestion here on integrating bid/ask support: #338

        To answer your questions directly though.

        1) No, the fill engine is different then BarsInProgress and they are not linked. Backtest fill engine will operate on all added data points.

        2) I have not tested this exactly but I believe you could do this now. Dynamically adjusting the slippage value on the fly in the strategy could do the trick. Slippage is a parameter that belongs to StrategyBase and you can just adjust it by calling Slippage = X;
        BrettNinjaTrader Product Management

        Comment


          #5
          An example in NT7 help is :
          protected override void Initialize()
          {
          Slippage = 2;
          }

          We are going to discuss NT7 problems here, so may be it's better to open another thread.

          The example suggests I can set a slippage during initialization only. I'll try to adjust Slippage before every exit. Even if it works, I should remember a spread during entry, compute it during exit and then adjust Slippage on exit accordingly.

          Even then a problem with NT7 remains. It "tends" to post orders bases on primary data series , even if I'm submitting EnterLong/Short with BarsInProgress as the 1-st argument. So I may try to define tick ask or tick bid as the primary data series and see if it works.

          An update: it's impossible to update Slippage. See http://www.ninjatrader.com/support/f...light=Slippage.
          So I have no choice, but to continue to work on my "poor man backtesting system". What a pity.
          Last edited by xTrader1; 05-08-2015, 02:15 PM.

          Comment


            #6
            If we're talking just backtesting purposes, it is possible. That's just an Initialization example from demonstrations purposes and what is set by default in the UI. NT7 and NT8 support the ability to dynamically set Slippage. Take the SampleMACrossOver strategy for example in NinjaTrader 7

            Code:
            //use random class to generate random slippage value
            Random rand = new Random();
            if (CrossAbove(SMA(Fast), SMA(Slow), 1))
            {
            	//set long slippage to a random value between 1 and 5
            	Slippage = rand.Next(1, 5);
            	EnterLong();
            }
            else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
            {
            	//set long slippage to a random value between 1 and 3
            	Slippage = rand.Next(1, 3);
            	EnterShort();
            }
            As long as you have updated the Slippage property before the Enter call, you should get the value you ask for.
            MatthewNinjaTrader Product Management

            Comment


              #7
              So theoretically if in NT8 Tick Replay is switched on - would this work?:
              Code:
              Slippage = GetCurrentAsk() - GetCurrentBid();
              Or is it unnecessary in this case and Tick Replay uses Ask and Bid prices for executions anyway? Still trying to wrap my head around the concept of Tick Replay - which is quite hard having no data to test it (with bid and ask).
              Last edited by gregid; 05-08-2015, 06:18 PM.

              Comment


                #8
                On second thought, if I understand a slippage correctly, even if it works, it solves only half a problem. I can simulate a spread on entry, but not on exit.
                May be integrating bid/ask support is a big issue, but adding one parameter to ExitLong/ExitShort and placing a few lines of code to adjust profit/loss should be very simple, and I think can be done immediately, once assigned.

                Comment


                  #9
                  Originally posted by gregid View Post
                  So theoretically if in NT8 Tick Replay is switched on - would this work?:
                  Code:
                  Slippage = GetCurrentAsk() - GetCurrentBid();
                  Or is it unnecessary in this case and Tick Replay uses Ask and Bid prices for executions anyway? Still trying to wrap my head around the concept of Tick Replay - which is quite hard having no data to test it (with bid and ask).
                  For strategies, you do not need to code in bid/ask for executions. That will be available while the bars/strategy is being build and should simulate executions based on this level of market data which is provided.
                  MatthewNinjaTrader Product Management

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  666 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  377 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  110 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  575 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  580 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X