Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi Timeframe backtest to market replay

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

    Multi Timeframe backtest to market replay

    Hello,

    I have a multi time frame strat. using 5min, 15 min, hourly, 4hr, daily, and weekly. I have good results from the backtest but I fear they are inacurrate.

    I want to wait till say 1 hour has pasted and use the high and low of that bar. However I am ordering in the 15 min time frame.

    So essentially my code looks something like this:

    Code:
    if (BarsInProgress == 1) 
    if(onehourhigh > fourhourhigh) 
    Enterlong...
    Setprofittarget...
    
    
    if (BarsInProgress == 3)   
    			{
    			if (High[0] >= High[1]+x)
    			{
    			onehourhigh = High[0];
    }
    if (BarsInProgress == 4)  
    			{
    			if (High[0] >= High[1+y)
    			{				
    			 fourhourhigh = High[0]
    }

    Because I thought if I just used Highs[4][0] inside of BarsInProgress=0 it would just update that bar every time it updated the primary time series.. Or would this way produce a more accurate backtest result?

    Also I noticed when I change the primary bars from 15 to 30 mins it changes some of my entry price on bars when backtesting even though I only have reset profittargets in my primary barsinprogress code and I'm not calling for the primary series in any other barinprogress any of the code.

    When I changed my primary bars with CalculateBarsOnClose=true during market replay my entries stayed the same between 15 min 30 min but changed on 60 mins.

    If I run my strat in real time with the Sim account with CalculateBarsOnClose=true, shouldn't my market replay results be very similar as my backtest results?


    Thanks!
    Last edited by oliver1337; 08-04-2012, 03:01 PM. Reason: Update

    #2
    Hello,

    There are known discrepancies in backtesting vs. real time trading.



    Here is a reference sample on adding intra-bar granularity in backtesting.

    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


    And here is our help guide entry on multi-series indicators / strategies which explains how these series are updated, hopefully it can help you understand why your strategy is behaving this way.



    If you have any questions after reviewing these, please let me know and I'd be happy to answer them.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Adam for the fast response. I have reviewed those links thanks, but still a little unsure of a few things as I am still fairly new to ninjatrader.

      My main question is :
      If I run my strat in real time with the Sim account with CalculateBarsOnClose=true, my market replay results should be very similar as my backtest results granted barring volume and market dynamics, right?

      The reason I ask this is because during backtest I get multiple different results when varying primary bars timeframe. But when I do a market replay I get the same results on different timeframes (to be expected as none of my code points to the primary bars for any entries or calcs.)
      I am trying to figure out if my strategy is indeed a "good" one and I'm feeling a little stuck.

      About the code below. Would this be the correct way to get the 1 hour bar after it has pasted and use the high and low of that bar. Or would using Highs[4][0] inside of BarsInProgress=0 produce a more accurate result?

      Thanks!

      Code:
      if (BarsInProgress ==1)
      if(onehourhigh > fourhourhigh) 
      Enterlong...
      Setprofittarget...
      
      
      if (BarsInProgress == 3)   
      			{
      			if (High[0] >= High[1]+x)
      			{
      			onehourhigh = High[0];
      }
      if (BarsInProgress == 4)  
      			{
      			if (High[0] >= High[1]+y)
      			{				
      			 fourhourhigh = High[0]
      }

      Comment


        #4
        oliver,

        What differences are you noticing? You may have missing historical data for the backtest as you need to be sure to download the data for multiseries code in some circumstances. Barring market dynamics, with CalculateOnBarClose = true, backtesting should be much closer to real time or market replay performance.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by bortz, 11-06-2023, 08:04 AM
        47 responses
        1,611 views
        0 likes
        Last Post aligator  
        Started by jaybedreamin, Today, 05:56 PM
        0 responses
        9 views
        0 likes
        Last Post jaybedreamin  
        Started by DJ888, 04-16-2024, 06:09 PM
        6 responses
        19 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by Jon17, Today, 04:33 PM
        0 responses
        6 views
        0 likes
        Last Post Jon17
        by Jon17
         
        Started by Javierw.ok, Today, 04:12 PM
        0 responses
        22 views
        0 likes
        Last Post Javierw.ok  
        Working...
        X