Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Possible to get filled on current bar in Strategy Analyzer?

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

    Possible to get filled on current bar in Strategy Analyzer?

    Hello NT,

    I have a strategy that is supposed to exit a trade immediately if the current bar's Open price meets a certain criteria. For some reason (when I backtest it in the Strategy Analyzer) the strategy exits the trade on the following bar and not on the current bar.

    For example, let assume my strategy is supposed to exit immediately if a bar's open price is 1927.25. And lets assume two bars have just passed, with the first bar opening at 1927.25 and the second bar opening at 1927.50. This would cause my strategy to fill at 1927.50 instead of 1927.25.

    Is this just the way the Strategy Analyzer works? Or is there a way to get the fill to happen at 1927.25?

    Thanks,
    P.S.
    I have CalculateonBarClose set to False and am also using the FirstTickOfBar property, but it still does not work.

    #2
    Hello Matheyas5,

    Thank you for writing in.

    Please note that during a backtest, strategies can ONLY be processed at the close of each bar.

    Please take a look at the help guide at this link for discrepancies between real-time and backtesting: https://ninjatrader.com/support/help...ime_vs_bac.htm

    I would suggest taking a look at this reference post in regards to backtesting NinjaScript strategies with an intrabar granularity: http://ninjatrader.com/support/forum...ead.php?t=6652
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the info Zack.

      That is terrible news

      I have many complex exit strategies that rely on monitoring 1 tick bid bars and sending an order once the open of a 1 tick bid bar meets a certain criteria. And this order needs to be executed immediately (not on the following bar).

      The code example you posted here won't solve this problem (because 1 tick bid bars don't have any bars inside them.) http://ninjatrader.com/support/forum...ead.php?t=6652

      Are there any plans to fix this in NT7 and/or NT8?

      Thanks again.

      Comment


        #4
        Hello Matheyas5,

        Thank you for your response.

        You can look to High Fill Resolution and Tick Replay in NinjaTrader 8. In NinjaTrader 7 I would recommend running the strategy in Market Replay with CalculateOnBarClose = FAlse.

        For information on NinjaTrader 8 please visit the following link: http://ninjatrader.com/support/helpG...en-us/beta.htm

        Please let me know if you have any questions.

        Comment


          #5
          Hi Patrick, I tried this in NT8 via High Fill Resolution and Tick Replay, but it did not seem to work.

          How can I request NT8 (as well as NT7) add a feature that will allow backtests/optimizations in the Strategy Analyzer to have immediate fills on the open of a 1 tick bid bar (or the open of any primary or non-primary bar) if the open meets certain criteria?

          There is a whole world of strategies am unable to backtest/optimize because of the lack of this feature.

          Comment


            #6
            Hello Matheyas5,

            Can you explain what occurred when using High Fill Resolution and Tick Replay?

            What was the expected result?
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Apologies for the delay Zack. I'm in process of doing a detailed re-test. Will post specific answers to your questions soon.
              thnks

              Comment


                #8
                Hi Zack,

                So I ran the attached SampleMACrossOverV2.zip strategy in NT8's strategy analyzer with 1 tick bid bars as the primary data series.The exact settings I used for the backtest can be found in the settings.jpg in the attached screenshots.zip file.

                The strategy is simply supposed to exit a trade if the open of the 1 tick Bid bar is either > or < the Position.AveragePrice.

                I found the results within this backtest were inconsistent.
                For example:

                (Note: the white dashes in both mentioned screenshots below represent 1 tick bid bars):

                1.jpg (from the attached screenshots.zip file)= shows the strategy entered a trade at 1888.50 then exited it immediately when the open of a 1 tick bid bar became 1888.25 (rather then waiting for the next bar to exit the trade). This is great! Its the exact result I was looking for when I started this thread!

                2.jpg (from the attached screenshots.zip file)= shows the strategy entered a trade at 1888.00, but (unlike the 1.jpg sample) it did not exit a trade immediately when the open of a 1 tick bid bar became 1888.75 (as shown by the red arrow). It waited till the next bar to exit.

                Any idea why this is?

                P.S.
                I know in live trading its impossible for a strategy to enter a Long trade at the price of a 1 tick Bid bar. I'm using the 1 tick Bid bars for both Long Entries and Long Exits in this example just to keep things simple.
                Attached Files
                Last edited by Matheyas5; 04-07-2016, 09:25 PM.

                Comment


                  #9
                  Hello Matheyas5,

                  Thank you for the additional information.

                  I'll be testing this on my end and provide my findings.
                  Zachary G.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Matheyas5,

                    I wanted to note that in the Strategy Analyzer, that it would be expected for the order to be executed at the open of the next bar.

                    Remember that OnBarUpdate() will run at the close of the bar in the Strategy Analyzer.

                    So, say you have two tick bars. One tick bar is at the price of 2000 and the next tick bar at the price of 2000.25.

                    And then, say that you have logic in your strategy that will submit an order if the bar's price is 2000. Because of how historical orders are filled, the order will actually fill at the price of 2000.25 because it is the next bar's open price.

                    You can see this in action by placing prints in your strategy. I've slightly edited your strategy to add prints as well as added an OnExecutionUpdate() method to show where the order actually filled at.

                    You will see the orders fill at the next bar every time.

                    I have provided the modified script.
                    Attached Files
                    Zachary G.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Zack,

                      When using the Strategy Analyzer In NT7 (and NT8) how can I get my Stop Loss, Take Profit and Trailing Stop orders to be based on non-primary Dataseries without the issue you described (quoted below) happening?

                      For example, lets say my BarsInProgress == 0 is 5 minute Last bars and my BarsInProgress == 1 is 1 tick Bid bars. And lets say I want my long exit's Stop Loss to be 2000 and be based on the 1 tick Bid bars. How could I get the long exit to happen as soon as the 1 tick Bid bar becomes 2000, rather then the exit happening on the following 2000.25 bar (you described below)?

                      Remember that OnBarUpdate() will run at the close of the bar in the Strategy Analyzer.

                      So, say you have two tick bars. One tick bar is at the price of 2000 and the next tick bar at the price of 2000.25.

                      And then, say that you have logic in your strategy that will submit an order if the bar's price is 2000. Because of how historical orders are filled, the order will actually fill at the price of 2000.25 because it is the next bar's open price.
                      ]
                      Thanks!

                      Comment


                        #12
                        Hello Matheyas5,

                        All added series will be following the same logic. Evaluated at the close, execute at the open.

                        There is no way to get around this in a historical backtest.
                        Zachary G.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ZacharyG View Post
                          Hello Matheyas5,

                          All added series will be following the same logic. Evaluated at the close, execute at the open.

                          There is no way to get around this in a historical backtest.
                          This is true regarding NT8's Strategy Analyzer? Or just NT7's?

                          Comment


                            #14
                            Hello Matheyas5,

                            This applies to both NinjaTrader 7 and 8.

                            Please take a look at this help guide page for additional information for the discrepancies between real-time and backtesting: https://ninjatrader.com/support/help...ime_vs_bac.htm
                            Zachary G.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_ZacharyG View Post
                              There is no way to get around this in a historical backtest.
                              Yes, there is.

                              You have to write custom code that explicitly runs only when BarsInProgress == 1.

                              That code will check for your Stop Loss, Take Profit and Trailing Stop conditions.

                              Such custom code is not hard.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by love2code2trade, 04-17-2024, 01:45 PM
                              4 responses
                              31 views
                              0 likes
                              Last Post love2code2trade  
                              Started by cls71, Today, 04:45 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post eDanny
                              by eDanny
                               
                              Started by proptrade13, Today, 11:06 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post proptrade13  
                              Started by kulwinder73, Today, 10:31 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by RookieTrader, Today, 09:37 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X