Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reality different to backtest

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

    Reality different to backtest



    Hi
    I have attached a simple strategy. When I use the same parameters over the same timeframe (1 May 19 to 21 May 19) on the 60 min chart, I get a slightly different result in backtest compared to when I traded it live.

    I've attached the code for my two strategies, which to me, are both exactly the same. The only difference being the code I use for backtesting actually enters a trade to see if trades were profit or loss making, whereas the code I use for live generates an alarm instead telling me I need to go enter a trade at those levels (I'm not good enough to link NT8 to spreadbetting).

    I've attached the example I seen on EURAUD yesterday in the Word doc; in live it generated a trade alert at 11am (and it was a losing trade for me), but when I backtest this today that trade is not there

    LIVEBreaklow.cs is the code I use to generate the alerts and trade live
    Breaklow.cs is the one I use for backtesting

    How can this be so?

    Many thanks
    Steve

    #2
    LIVEBreaklow.cs Breaklow.cs Trades.docx

    Comment


      #3
      Hello lancasterstephen,

      Thank you for your post.

      On what instrument are you running your strategy? Who is your data provider? What kind of chart are you using for your live and backtest (example: 1 minute, 4 Renko, 150 tick, etc)? Are you using Market Replay or Historical data?

      You should expect that a strategy running real-time (live brokerage account, live market simulation, Market Replay etc...) will produce different results than the performance results generated during a backtest. This difference may be more easily seen on certain Bars types (e.g. Point and Figure) than others due to their inherent nature in bar formation.

      During a backtest fills are determined based on 4 data points, OHLC, of a bar since that is the only information that is known during a backtest and there will be no intra-bar data. This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known.

      Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick'.

      Also, here is a link to the differences on real-time vs backtest (historical).


      Adding intra-bar granularity can help with this.

      Intra-bar granularity adds a second data series such as a 1 tick series so that the strategy has finer granularity in the historical data in between the OHLC of the primary series. This allows for more accurate trades by supplying the correct price at the correct time for the order to fill with.

      In NinjaTrader 8, there have been two new enhancements so that programmers do not have to manually add this secondary series and code the script to for high accuracy fills (Order Fill Resolution) and for intra-bar actions (TickReplay).

      Here is a link to our forums that goes into depth on using Order Fill Resolution and Tick Replay to ensure your backtests are as close to real time results as possible:

      Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.


      High Fill Order Resolution and TickReplay cannot be used together. If it is necessary to have both, it is still possible to add intra-bar granularity to a script in the code itself for order fill accuracy and use TickReplay to update indicators with Calculate set to OnPriceChange or OnEachTick historically.

      Please let us know if we may be of further assistance to you.
      Kate W.NinjaTrader Customer Service

      Comment


        #4
        Hi
        As above, I'm running this on EURAUD on 60 minute candlestick charts. Data provider is FXCM. The trade is entered at market based on the Close values in both live and backtest, therefore Backtest should generate the same results as Live I would have thought; the intra bar movements would not be required in this instance and would not lead to different results? This is why I'm confused a lot!

        Thanks
        Steve

        Comment


          #5
          Hello lancasterstephen,

          Thank you for your reply.

          To determine if a trade should have been taken or not, you must also ensure that the data you are testing on is the same.

          This forum post goes into great detail on how to use prints to help figure out where any differences might lie - it might have to do with errant ticks in the real time data that end up with slightly different timestamps in the historical data, but this should get you going in the correct direction. You can even add these using the Strategy Builder.



          One other suggestion to help determine if your strategy should be entering or not would be to turn on TraceOrders for your strategy:

          Strategy Builder > Default Properties > More Properties > Trace Orders, or:

          if (State == State.SetDefaults)
          {
          TraceOrders = true;
          }

          Once you then recompile the strategy, you can open a new NinjaScript Output window under New > NinjaScript Output. This will print a log of any orders submitted by the strategy during while it's running, along with any ignored orders. You can then look through and see what may be occurring.

          If you provide prints from the output of a real-time test and from a historical test, we would be happy to analyze the output and see what is different.

          Please let us know if we may be of further assistance to you.
          Kate W.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Jon17, Today, 04:33 PM
          0 responses
          1 view
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          6 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Started by alifarahani, Today, 09:40 AM
          6 responses
          41 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          21 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Working...
          X