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

calculate on bar close. same as strategy analyzer

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

    calculate on bar close. same as strategy analyzer

    i'm almost done with my strategy. and, i'm wondering if it calculates on bar close - is that the same on bar close that's used in the strategy anaylyzer? since i'm not calculating ticks within the strategy the strategy analyzer is essentially in sync with what the strategy would produce?

    #2
    Hello SteveReiza,

    Thanks for your post.

    A strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest.

    When in historical data, only the Open, High, Low, and Close will be available 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.

    Please review the help guide document on the differences on real-time vs backtest (historical): https://ninjatrader.com/support/help...ime_vs_bac.htm

    To improve the accuracy of a backtest, you may use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.

    Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

    High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.

    Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

    SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity': https://ninjatrader.com/support/help...ipt_strate.htm

    TickReplay: https://ninjatrader.com/support/help...ick_replay.htm

    Developing for Tick Replay: https://ninjatrader.com/support/help...ick_replay.htm

    Additional information may be found in this NinjaTrader Forum post:
    https://ninjatrader.com/support/forum/forum/ninjatrader-8/strategy-development/100192-comparing-real-time-historical-and-replay-performance?t=102504
    Last edited by NinjaTrader_BrandonH; 02-11-2024, 03:39 PM.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      thanks for the reply. i'm tracking. but, i have my strategy calculate on bar close. so, wouldn't trades execute on "open" of the next bar if all things in the entry method occur. that being said aren't my strategy and the backtest calculating the same then. i'm not concerned with intrabar activity for entry method.

      Comment


        #4
        Hello SteveReiza,

        Thanks for your notes.

        Yes, if your strategy is set to run in the mode of Calculate.OnBarClose which means that the strategy code executes once at the end of each bar and will perform calculations on completed bars. If your strategy determines to enter an order, the order would be placed on the next bar. In this mode, your strategy will operate the same historically as it does when connected to real-time (or replay) data.

        That said, the accuracy of the backtest would ultimately depend on your strategy's logic and how it calculates values and places orders.

        To ensure a backtest is accurate within 1 tick, intrabar granularity should need to be added to the strategy and Tick Replay would need to be used as noted in post # 2.

        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          thanks for the reply. cool cool. but you just said something i need to clarify. if the strategy determines the entry method of what takes place at 1 bar ago, 2 bar ago, and 3 bar ago on [0] (when that bar opens) - the trade won't get executed immediately then? it will be on the start of the following bar?

          Comment


            #6
            Hello SteveReiza,

            Thanks for your notes.

            When Calculate.OnBarClose is used all logic is processed and actions occur at the close of the bar. BarsAgo 0 would refer to the bar that just recently closed.

            This means Open[0] would refer to the open price of the bar that just recently closed.

            Open[1] would refer to the open price 1 bar before the most recently closed bar.

            Open[2] would refer to the open price 2 bars before the most recently closed bar, and so on.

            If the strategy processes logic on completed bars (close of the bar) and determines an order should be placed, the order would be placed on the next bar.

            Calculate: https://ninjatrader.com/support/help.../calculate.htm
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              thanks for the reply. okay sweet thanks for the clarification. so, on bar close i'm really entering two bars too late. i was seeing [0] as the live bar the bar that is acting. and [1] as the most recent bar. its [0] as the most recent closed bar. f$#C#$#*&#!@

              after i adjust everything. i'd like the entry order to fill immediately after what it sees at [0], [1], and [2] without waiting a bar (the bar that determined that a trade needs to occur). if i have it calculate on ticks. will it do that - submit the order during the present active bar (35 second for example)

              Comment


                #8
                Hello SteveReiza,

                Thanks for your notes.

                If you want your strategy to process information and place orders intrabar then you would need to use Calculate.OnPriceChange or Calculate.OnEachTick.

                Note that to backtest a strategy in the Strategy Analyzer that uses Calculate.OnPriceChange or Calculate.OnEachTick, you would need to use Tick Replay along with an added 1-tick series to have logic processed intra-bar and have orders filled intrabar.

                Tick Replay would be used to have the logic process OnEachTick or OnPriceChange with historical data, but this does not allow for intra-bar order fills. You would need to add a single tick data series and submit orders to that single tick data series for a strategy that uses Tick Replay.

                Please reference the SampleIntrabarBacktest example and the following Help Guide links for more information.

                SampleIntrabarBacktest 'Backtesting NinjaScript Strategies with an intrabar granularity': https://ninjatrader.com/support/help...ipt_strate.htm

                TickReplay: https://ninjatrader.com/support/help...ick_replay.htm

                Developing for Tick Replay: https://ninjatrader.com/support/help...ick_replay.htm

                Additional information may be found in this NinjaTrader Forum post:
                https://ninjatrader.com/support/forum/forum/ninjatrader-8/strategy-development/100192-comparing-real-time-historical-and-replay-performance?t=102504​​
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  thanks for the reply. okay sweet. that's important to know when i purchase data further up the road. and, great. we cleared up why orders weren't executing where i thought they should.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Jonafare, 12-06-2012, 03:48 PM
                  5 responses
                  3,986 views
                  0 likes
                  Last Post rene69851  
                  Started by Fitspressorest, Today, 01:38 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Fitspressorest  
                  Started by Jonker, Today, 01:19 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Jonker
                  by Jonker
                   
                  Started by futtrader, Today, 01:16 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post futtrader  
                  Started by Segwin, 05-07-2018, 02:15 PM
                  14 responses
                  1,792 views
                  0 likes
                  Last Post aligator  
                  Working...
                  X