Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest Order Delay by 2-3 daily bars always

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

    Backtest Order Delay by 2-3 daily bars always

    Hello,

    I'm looking to understand this issue better. It may be simply a function of using Daily data.

    There is always a one bar delay for orders to be filled after my strategy signal is achieved. If Im using a croffover/crossunder, this becomes a two bar delay.

    For example, if my entry is SMAfast crosses up through SMAslow - and this takes place on Monday, the buy is executed on Thursday.

    If its a stop order that says when price is < $10, and the price closed at $9 on Monday, the stop order is executed on Wedendsday.

    As usual, Im sure Im missing something here. I would assume that if I am using close prices (which I have been and believe all I can do since its daily/free historical data) why could the trades not take place the next day in this back testing?

    Note I am not using anything other than zero in the "bars ago" fields. It is only the crossover/crossunder that forces me to delay an additional day.


    Meegwell

    #2
    Hello Meegwell,

    In a backtest orders are always submitted on the next bar following the condition.A good way to verify which bar the condition returns true is with Drawing objects.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      OK - Ill check that to verify what Im seeing is true, and not a visual issue. I have zoomed in to see only a few daily bars on the screen and still see 2-3 bar delay in execution. I was thinking that maybe this is becuase Im executing on close? I bar t1 is where the event happened, it doesnt know it until bar t2 since its daily data...causing the actual execution to take place on bar t3?

      Comment


        #4
        meegwell,

        If you posted a screenshot we would better be able to analyze the exact specifics of the scenario too. Thanks.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          FIrst time uploading image so I hope its attached....note the signal is when the green line crosses over the blue. In the picture, you'll see that it skipped a bar before executing.

          Meegwell

          EDIT TO MESSAGE: It appears that my issue is one of visual/zoom so I think this can be ignored for now.

          Ive been busting my rump trying to figure out something else, which I will now abondon and ask in the following post.
          Attached Files
          Last edited by meegwell; 02-01-2011, 09:07 PM.

          Comment


            #6
            meegwell, to clarify and explain - what you see is expected behavior, the signal is triggering and your first potential trade location is the open of the next bar after the candle that triggered the signal is closed.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Is there a way to submit a order in the same bar the signal is triggered using EOD data?

              Comment


                #8
                Hello mtcforum,

                This is possible when the strategy is run real time, and calculate on bar close setting is false.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  I mean if it is possible doing it at optimization or backtest routines.

                  Comment


                    #10
                    No, in a backtest or when COBC = true: All conditions are evaluated at the close of bar, and placed on the next bar after the condition is true.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Hmm not sure about this.

                      I know this is an old thread, but it's something I searched specifically for.

                      I too was trying to determine when executions occurred. I was able to produce the following output illustrating that my signals, orders AND executions are occurring on the same bar:



                      Background:
                      -Calculate on bar close is true;
                      -I have a heartbeat output for each bar update that tells me which bar array and which bar number I'm looking at;
                      -Buy signals are generated OnBarUpdate();
                      -Buy orders are submitted OnBarUpdate();
                      -Execution output comes OnExecution()

                      You will see in this MCD example that this all occurs on bar number 2651, before bar 2652 .

                      Ideas?

                      -----
                      Edit - I did confirm, when tracing orders, that although my code is generating the output above, the actual execution (and execution price) seems to be occurring on the subsequent bar.

                      My question is this: Why is OnExecution() telling me then that the execution is occurring one bar before it's actually occurring? For example, in the image provided, I do see that the actual execution for MCD occurred on 7/29/14; however OnExecution() tells me that this occurred on 7/28/14.
                      Attached Files
                      Last edited by cgeorgan; 08-18-2014, 12:09 PM.

                      Comment


                        #12
                        Hi cgeorgan,

                        I'm not quite sure I understand the issue.

                        The trigger, and execution appear to be at the same time.

                        If this is a 1 minute chart, the order would appear on the 4:01:00 bar (close time of that bar).

                        What bar is the order appearing on?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          What I'm saying is this:

                          This strategy is built on daily bars, and results are calculated on the bar close. In the example I provided:
                          - On 7.28.14 bar #2651 was updated (this message was printed as soon as OnBarUpdate() was called).
                          - A buy signal was generated within OnBarUpdate() on bar #2651.
                          - A buy order (unmanaged, via SubmitOrder()) was submitted on the same bar, #2651.
                          - OnExecution() was triggered on the same bar - #2651.
                          -OnBarUpdate() was triggered again (Bar #2652), signifying a new cycle.

                          This thread discusses the fact that orders are submitted on subsequent bars. I traced the order here on the Strategy Analyzer chart used, and confirmed that (at least on the chart) the execution occurred on 7.29.14 - Bar # 2652. However, according to NinjaTrader's event logic, the output shows that as far as NT is concerned, the execution occurred on 7.28.14 (bar #2651), which is the same bar that generated the signal - the same bar which subsequently generated an order and the same bar which reported an execution (an execution which is supposed to happen on the next bar).

                          Thoughts?

                          Comment


                            #14
                            Hello cgeorgan,

                            When NinjaTrader is running with Calculate on bar close (COBC) as true, orders are placed after the bar closes using logic calculated from that bar.

                            Below is a link to the help guide on Calculate on bar close.
                            http://www.ninjatrader.com/support/h...onbarclose.htm

                            This means that any orders that are triggered from that bar are submitted after the bar closes as the new bar opens. As the order is placed as the new bar opens and the timestamp of the order is within the time of the next bar, the order will show on the next bar.

                            If the strategy were running with COBC as false, or if the script has intra-bar granularity and submitted orders on a smaller timeframe, this would cause the timestamp of the order to be within the bar it is triggered on as the order may be submitted intra-bar. This order would show on the same bar as the bar that triggered the order submission.
                            Chelsea B.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Rapine Heihei, Today, 08:19 PM
                            1 response
                            6 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by Rapine Heihei, Today, 08:25 PM
                            0 responses
                            5 views
                            0 likes
                            Last Post Rapine Heihei  
                            Started by f.saeidi, Today, 08:01 PM
                            1 response
                            4 views
                            0 likes
                            Last Post NinjaTrader_Manfred  
                            Started by Rapine Heihei, Today, 07:51 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post Rapine Heihei  
                            Started by frslvr, 04-11-2024, 07:26 AM
                            5 responses
                            98 views
                            1 like
                            Last Post caryc123  
                            Working...
                            X