Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What bar indices should be used 0 or 1 for back test and eventually automated?

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

    What bar indices should be used 0 or 1 for back test and eventually automated?

    Hi,

    I moved over from eSignal and getting familiar with the Strategy Builder. I have a few general question on creating a strategy that can be accurately back tested with the eventual goal to run as an fully automated strategy. In general for both back testing and eventual trading is there anything specific that should be included for a successfully back tested system to then by loaded and run real time.

    I created a basic strategy just to familiarize myself with the builder and included several common indicators, EMA SMA Momentun etc.

    Does the EnterLong() and EnterShort() enter a trade on the open of the nextbar which would enable the use of bar 0 in indicator comparasions/crossovers

    In general is it recommended that the current bar 0 or bars 1 back ago be used for moving average cross overs, price above a moving average?

    In esignal there was always a problem using the current bar in strategies as that bar was being build real time and the back tester used OHLC so the back testing results never matched real time trading. The suggestion was to always use 1 bar back for all indicators is that also true in Ninja Trader?

    Similiar question for Open[0] > Close[0] to determine a red or green candle is the comparison ma each tick with the close[0] being the last tick or after the bar closes?






    #2
    Hello demarcog,

    Thank you for your post.

    EnterLong() and EnterShort() would be fired off immediately if you are running the strategy with Calculate set to OnEachTick, immediately after a price change if using OnPriceChange, and when the next bar opens after the current bar closes if using OnBarClose.

    Whether you check for a crossover on the current bar or the previous bar would be up to your discretion. It's worth noting that when using OnPriceChange or OnEachTick, the 0 bar refers to the bar that is currently forming, whereas when running the strategy using OnBarClose the 0 bar will be the last closed bar.

    Similiar question for Open[0] > Close[0] to determine a red or green candle is the comparison ma each tick with the close[0] being the last tick or after the bar closes?
    This would be dependent on the strategy settings and whether you're running it on live data or in a backtest. If the strategy is set to Calculate OnEachTick or OnPriceChange and is not being run in a Strategy Analyzer in a backtest, this would be checked with each incoming tick or price change of the currently forming bar. If the strategy is set to Calculate OnBarClose or the strategy is run in a Strategy Analyzer backtest, it would be checked once per bar, when it closes.

    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 you can select conservative or liberal fill algorithms which will produce different results. 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).
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    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:

    https://ninjatrader.com/support/foru...mance?t=102504

    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.

    I would note here that you can backtest a strategy using Market Replay data in the Playback connection which will give the most accurate to real time result as Market Replay plays the market back tick by tick. However, this is generally only recommended for testing over short time frames as running over a long time frame will result in performance impacts.

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

    Comment


      #3
      Kate,

      I can't thank you enough for that comprehensive and informative response. Honestly I will have to study it further to make sure I understand completely.

      In my experience the coding issues and back test inaccuracies of doing anything tick by tick is not worth the effort as I'm not a "real" developer.

      In addition, I prefer some of the non time based chart types from a strategy performance point of view so could you please tell me if my approach going forward makes sense.

      My objective would be to use the last completed bar for all indicator trigger values and the opening price of the next bar for entry and exit.

      I want to keep it as simple as possible, produce the closest possible back test to real time results and the same code for back testing and auto trading.

      Is this possible using OnBarClose?

      The next major obstacle for me is assuming my strategy specifies OnBarClose and I am using renko charts. Would using Orderfillresolution of High/Tick be sufficient to approximate as close as possible to real time trading results assuming slippage is factored in?

      It seems when I do that and the strategy is profitable in real time sim trading a strategy that may make $1000 a day looses $1000 a day and I can't figure why, any suggestions?

      Thank you very much for all your assistance, Ninja Trader Support is the best I've ever experienced in many years.

      Glen


      Comment


        #4
        Hello demarcog,

        Thank you for your reply.

        It does sound like you'd want to use OnBarClose, if you want to evaluate for a cross at the close of the bar and trigger an order to be submitted at the open of the next. That's pretty much exactly what OnBarClose does.

        Using Renko bars in a backtest will produce results that are not comparable to real-time results due to the way Renko bars are built, regardless of your OrderFillResolution settings.

        Renko bars on real-time data re-draw the open based on the direction of the bar. This cannot be simulated historically, since backtests use four, and only four data points: the open, high, low and close. Other means of backtesting, such as Market Replay/Play Back, can still yield appropriate results.

        If you're testing a strategy on real time in Sim that uses market orders, it's quite likely that slippage is a factor in your results on a live account. Since market orders are guaranteed to fill, but do not guarantee at what price that fill will be, there are situations in which your order may not fill at the price you'd expect, especially in a volatile market. I would experiment with specifying a slippage value to be applied to market orders on Sim in the strategy parameters to see if that seems to bring your sim results closer to your live results.

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

        Comment


          #5
          Hi Kate,

          Thank you again for the helpful response it is appreciated. I understand the slippage issues and only trade the most liquid instruments, ES, NQ where slippage is minimized and it's easy to overestimate to insure slippage is not a factor.

          If my orderfillresolution is High/tick wouldn't the actual ticks rather then be used when calculating P&L rather then OHLC, I thought that was the purpose of High/Tick?

          Is Market Replay the same a Playback?

          Understood the issue on Renko I've been testing with unirenko bars when a very small tick trend as in 1 or 2 ticks. In this case the bar is essentially no more then 2 ticks off in accuracy I believe?

          Do you have any recommendations on how when using Unirenko bars to come as close as possible. to real time results?

          Such as if the Tick Trend and OpenOffset are small and close to one another then the open of the next unirenko bar should be very close to the actual price. I am not sure how the size of Tick reversal would effectthe back test results.

          Again I appreciate it and apologize for asking more questions this is essentially my full time job since COVID and the way I am supporting my family.

          Any help or suggestions you can provide in helping me achieve accurate testing results and also realize you cannot make trading system recommendations but for educational purposes in coding properly if there are any examples that I can use as a starting point I would greatly appreciate it.

          glen

          Comment


            #6
            Hello demarcog,

            Thank you for your reply.

            OrderFillResolution would only apply to orders on historical data, so keep that in mind. Setting the order fill resolution to high will load a single tick data series for improving the accuracy of fill prices, that's true.

            The Playback connection can be either used with Historical Data or Market Replay data. Specifically using Market Replay data would give the most accurate backtesting.

            Since Unirenko bars are not a built in feature of the platform, I would not have any recommendations other than since renko type bars use 'virtual' prices for open, high low, close, it would be expected that it ends up with discrepancies in your backtest results. You would want to test strategies intended for use with renko type bars using the Playback Connection with Market Replay data so that the bars are accurate.

            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 AaronKoRn, Today, 03:05 PM
            1 response
            9 views
            0 likes
            Last Post NinjaTrader_Emily  
            Started by zacharydw00, Today, 02:21 PM
            2 responses
            13 views
            0 likes
            Last Post zacharydw00  
            Started by Harvard, Today, 12:01 PM
            2 responses
            13 views
            0 likes
            Last Post Harvard
            by Harvard
             
            Started by DanDaMan, Today, 12:40 PM
            5 responses
            15 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Started by bob999, 02-16-2021, 10:00 AM
            3 responses
            29 views
            0 likes
            Last Post NinjaTrader_Kate  
            Working...
            X