Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

How to replicate Back-Test Results with different Data Series?

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

    How to replicate Back-Test Results with different Data Series?

    Hello,

    My strategy uses Tick Replay and Calculates OnPriceChange and uses two Data Series. The primary Data Series changes between a High Time Series or a High Tick Series based on what indicators I use and the Secondary Series is always 1 Tick for intra-bar fills and events. I will give a simple example of how my strategy operates:
    --------------------------------------------------------------------------------------
    private double Benchmark;
    private double StartTime = 93000 (HHMMSS)

    if (State == State.Defaults)
    {
    Calculate = Calculate.OnPriceChange;
    Slippage = 0;
    OrderFillResoultion = Standard;
    }

    else if (State == State.Configure)
    {
    //Primary Data Series is 30 Min
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    }

    OnBarUpdate()
    {
    if (BarsInProgress == 0)
    {
    if ((ToTime(Time[0]) == StartTime))
    {
    Benchmark = Open[0]; //Algo captures the open price of 9:30 Bar as key value to base its trading, other logic is added to have this value calculated only once for the rest of the trading day
    }

    //Secondary Series (1 Tick) is used for intra bar trading
    If (GetCurrentBid(1) && Ask(1) >= (Benchmark + (4 * TickSize)))
    {
    EnterLong(1, xxx, xxx, ...);
    }

    if (Position.MarketPosition == MarketPosition.Long)
    {
    if (GetCurrentBid(1) && Ask(1) <= Benchmark)
    {
    ExitLong(1, xxx, xxx, ...)
    }
    }
    }
    }
    --------------------------------------------------------------------------------------

    This setup has shown great results in backtests when primary BIP is the 30min; however out of curiosity I changed the Primary Series to the 1 Tick, still keeping The secondary 1tick for entries and exits, to see if results would be the same. My "StartTime" value was changed to 90000 (9:00AM) so that it returns the same "Benchmark" as it would when returning the Open[0] of the 9:30AM Bar with the 30 Minute Series. The "Benchmarks" return exactly the same but it turns out that the trading is definitely not the same as I see worse results. I believe the version using the 1tick as the primary BIP is the most accurate since I can actually see how the trading is happening tick by tick.

    My main question is this: Based on the example above, How would one go about returning the same trading results using Higher Time/Tick Series as I do when performing all logic solely on a 1 Tick Data Series?

    I read that the higher time series should always be set to the primary BIP, so I would like to use the higher time frame just to get the benchmark value, and then preform all other logic on the 1 tick but I haven't figured out how to write this in my code.

    Since testing using primary BIP of 1 Tick has given the most accurate results and the tick data used should be the same all the way around either using 30mins or 1tick, I want to produce the exact same results when using a Higher Time/Tick Series as the primary for backtesting as it makes a more pragmatic approach when using indicators and studying results over longer testing periods.

    #2
    Hello Don22Trader1,

    Because you change the primary series that would change how the OnBarUpdate is called for BarsInProgress 0 which would effect results if you have any logic used in the BarsInProgress. There is not a way to make it have the same results if you are making substantial changes to how the script operates.

    For backtesting you can use a secondary series for more granular fills like you have, you would otherwise use the higher timeframe or the timeframe you wanted your normal logic executed as the primary.

    When backtesting everyhting is run OnBarClose so using a higher timeframe for your fills won't produce the same results as using a more granular series such as a 1 tick series. You would need to just keep the configuration you have usng the 30 minute as the primary for executing logic and then using the 1 tick series for fills if you wanted to have the most granularity for results.

    Keep in mind that using TickReplay does not help with getting better results, that is a processing mode so that OnMarketData can be used historically and that will not help with fill resolution. Also keep in mind that the strategy will operate differently in realtime when using OnPriceChange, the strategy will operate OnBarClose historically and then change to OnPriceChange for realtime which will cause differences. You can read about comparing the different modes here: https://ninjatrader.com/support/foru...ay-performance
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by popecapllc, 08-09-2023, 07:42 PM
    11 responses
    1,874 views
    0 likes
    Last Post tradgrad  
    Started by morrnel, 05-12-2024, 06:07 PM
    7 responses
    106 views
    1 like
    Last Post tradgrad  
    Started by mmike, Yesterday, 10:33 PM
    0 responses
    4 views
    0 likes
    Last Post mmike
    by mmike
     
    Started by Pole123, Yesterday, 06:02 PM
    0 responses
    9 views
    0 likes
    Last Post Pole123
    by Pole123
     
    Started by samish18, Yesterday, 05:27 PM
    0 responses
    6 views
    0 likes
    Last Post samish18  
    Working...
    X