Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entry always 1 bar late

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

    Entry always 1 bar late

    I was running a strategy which 2 different Bar objects using the same 5 min period. The signal will be based on the secondary bar object (XLF) but the entry will be on the primary bar object (GS). However I notice the entry on the primary bar object (GS) is always one bar later than it should. Why is that so?

    I am using the following code:

    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose =
    true;
    TraceOrders =
    true;
    Add(
    "XLF", PeriodType.Minute, 5);
    }
    ///<summary>
    /// Called on each bar update event (incoming tick)
    ///</summary>
    protectedoverridevoid OnBarUpdate()
    {
    if (BarsInProgress == 1)
    {
    if(High[0]>10.9)
    EnterShort(
    0, 1, "Short");
    if(Low[0]<-10.6)
    EnterLong(
    0, 1, "Long");
    }
    }

    #2
    Screenshot please. Make sure Text and Marker is turned on.

    I think probably what you are seeing is the signal entering a position on the new bar, the moment the prior bar closed, which is what triggered your entry.

    Mike

    Comment


      #3
      Originally posted by ctrlbrk View Post
      Screenshot please. Make sure Text and Marker is turned on.

      I think probably what you are seeing is the signal entering a position on the new bar, the moment the prior bar closed, which is what triggered your entry.

      Mike
      Attached the screenshot. A signal should be generated on 13:25 when the high (10.91) of XLF was above 10.9. However the entry on GS was not on the open of bar (13:30) but on the open of bar (13:35) which was the 1 bar late I was mentioning about.
      Attached Files
      Last edited by tjendra; 04-28-2009, 02:58 AM.

      Comment


        #4
        Are you getting these results on live data or in Strategy Analyzer?
        I was having the same issue in Strategy analyzer and belived this was an issue, but then I read the manual and found out that it is the norm in strategy analyzer because of the lack of tick data/ depth etc. as opposed to realtime. Plus you are using calculate on bar close = True.
        You could perhaps try CalculateOnBarClose = False for live strategy.

        Cheers

        Chris

        Originally posted by tjendra View Post
        Attached the screenshot. A signal should be generated on 13:25 when the high (10.91) of XLF was above 10.9. However the entry on GS was not on the open of bar (13:30) but on the open of bar (13:35) which was the 1 bar late I was mentioning about.

        Comment


          #5
          Thanks for the input Chris, in backtesting this is expected - to simulate intrabar fills, please review this this reference sample > http://www.ninjatrader-support2.com/...ead.php?t=6652

          Comment


            #6
            Originally posted by NinjaTrader_Bertrand View Post
            Thanks for the input Chris, in backtesting this is expected - to simulate intrabar fills, please review this this reference sample > http://www.ninjatrader-support2.com/...ead.php?t=6652
            Hi Bertrand, Chris,

            I understand if a the strategy doesn't execute on Bar close and execute on the next bar open. But my problem here is that it enter 2 bars after the signal is generated. If the entry was on XLF itself, it would have have entered on the open of bar (13:30) not bar (13:35). But since the entry is on a different instrument (GS), it enter on the open of bar (13:35) instead. Why is that so since both are on the same timeframe?

            Comment


              #7
              tjendra, did you simplify the strategy to execute on one symbol only to check? Or is your statement below just from a 'visual' check?

              Comment


                #8
                Originally posted by NinjaTrader_Bertrand View Post
                tjendra, did you simplify the strategy to execute on one symbol only to check? Or is your statement below just from a 'visual' check?
                Hi Bertrand,

                It was from a visual check. From the attached screenshot, you can see the condition of XLF high[0] > 10.9 was generated on bar (13:25). So even in a backtest, the short should be entered on the open of bar (13:30) in GS isn't it? Why was it entered on the open of bar (13:35) instead?

                The strategy need to use a signal generated by one instrument for entry and exit in another instrument in the same timeframe. So if there is this 1 bar lag, it won't work well. You were saying to use intrabar fill, but then the 2 timeframe would be different, so the strategy wouldn't work as well.

                Comment


                  #9
                  Just responded to you via mail tjendra, I would suggest you check this on one frame first and make sure the set condition fires the trade as you had in mind and then move to a multiseries approach. You can still use the intrabar fill concept to simulate a quicker fill as you can achieve in realtime running.

                  Comment


                    #10
                    Originally posted by NinjaTrader_Bertrand View Post
                    Just responded to you via mail tjendra, I would suggest you check this on one frame first and make sure the set condition fires the trade as you had in mind and then move to a multiseries approach. You can still use the intrabar fill concept to simulate a quicker fill as you can achieve in realtime running.
                    Hi Bertrand,

                    The error you corrected shouldn't have any bearing on the strategy, since the signal is taken from XLF and it should be executed on GS. I am applying this strategy to a GS 5 min chart, so on the GS chart, you will only see the "GS Short" and "GS Long" being executed. I did the "XLF Short" and "XLF Long" to test if the entry on the secondary bar (XLF) is same as the primary bar (GS) but forgot that it can't be seen visually as the strategy is not done on XLF.

                    For the correct entry, all you need is to take away "if (BarsInProgress == 1)" in the strategy and test the strategy on a XLF 5 min chart, then that would show the correct entry. Attach a screenshot.
                    Attached Files

                    Comment


                      #11
                      tjendra,

                      To understand when the bars update in a multi-instrument strategy it is highly recommended you just print timestamps from each bar series first. Once you are familiar with the order of events then you can start placing trades to understand how those interact.

                      Please do something like this:
                      Code:
                      if (BarsInProgress == 0)
                           Print(Time[0] + " BarsInProgress 0");
                      else if (BarsInProgress == 1)
                           Print(Time[0] + " BarsInProgress 1");
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #12
                        I print the timestamp as you suggested by using the following code:

                        protectedoverridevoid OnBarUpdate()
                        {
                        if (BarsInProgress == 0)
                        Print(Time[
                        0] + " BarsInProgress 0");

                        if (BarsInProgress == 1)
                        {
                        Print(Time[
                        0] + " BarsInProgress 1");
                        if(High[0]>10.9){
                        EnterShort(
                        0, 1, "Short");
                        Print(Time[
                        0] + " Short");
                        }
                        if(Low[0]<10.6){
                        EnterLong(
                        0, 1, "Long");
                        Print(Time[
                        0] + " Long");
                        }
                        }

                        }

                        For the trade that triggered in post #3, the timestamp as follows:

                        13-Apr-09 1:25:00 PM BarsInProgress 0
                        13-Apr-09 1:25:00 PM BarsInProgress 1
                        13-Apr-09 1:25:00 PM Entered internal PlaceOrder() method at 13-Apr-09 1:25:00 PM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short' FromEntrySignal=''
                        13-Apr-09 1:25:00 PM Short

                        Based on the above timestamp, should the trade trigger on the open of bar (1:30 PM) or on the open of bar (1:35 PM) in backtesting?

                        Comment


                          #13
                          tjendra, based on your output, it would trigger on the open of the 13:35 bar then.

                          Comment


                            #14
                            Originally posted by NinjaTrader_Bertrand View Post
                            tjendra, based on your output, it would trigger on the open of the 13:35 bar then.
                            Hi Bertrand,

                            I don't think that is correct.

                            If I use the following code without the "BarsInProgress", the entry was on the open of the 13:30 bar rather than the open of the 13:35 bar.

                            Why the difference in entry if I use the "BarInProgress" function?

                            protectedoverridevoid OnBarUpdate()
                            {
                            if(High[0]>10.9){
                            EnterShort(
                            0, 1, "Short");
                            Print(Time[
                            0] + " Short");
                            }
                            if(Low[0]<10.6){
                            EnterLong(
                            0, 1, "Long");
                            Print(Time[
                            0] + " Long");
                            }
                            }

                            Timestamp Output:
                            13-Apr-09 1:25:00 PM Entered internal PlaceOrder() method at 13-Apr-09 1:25:00 PM: Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Short' FromEntrySignal=''
                            13-Apr-09 1:25:00 PM Short

                            The signal was also generated on the 13:25 bar as with the code with "BarsInProgress".

                            Comment


                              #15
                              tjendra, in backtesting this is expected as working with multiple BarsInProgress or not does matter.

                              Consider having only one BarsInProgress > you submit the order at 1:25, it fills at 1:30.

                              As you submit across multiple BarsInProgress it takes an extra step in between to submit from one to another, on 1:25 you submit it from BarsInProgress 1 to BarsInProgess 0, this actually happen on the 1:30 bar so it gets filled on the 1:35 one as you reported.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              558 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              324 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              101 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              545 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              547 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X