Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Incorrect value on first bar of the day

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

    Incorrect value on first bar of the day

    I have noticed a repeating issue with a long running multi-timeframe, multi-instrument, strategy. This strategy uses very long SMAs – e.g. 100 day. Any ideas would be appreciated

    Background:
    A) Primary instrument is a highly liquid ETF and the strategy runs on 10 Minute bars. All other instruments are indexes used in calculations
    B) There are no errors or any anomalies in the logs or trace.
    C) My strategy stores values to file while running and I have narrowed it down to the simple issue below.
    D) Calculations and strategy runs flawlessly in Strategy Analyzer and Market Replay.
    E) Running in US Equities RTH
    F) PROBLEM: A calculation in the strategy fails because in the Live strategy the value of Closes[3][0] is always incorrect at 9:40AM. Here is an example of my raw output. The value "Prior Ind" is equal to Closes[3][0] in all 3 cases – it is the exact same function that is outputting this data.

    2/7/2014 9:40:00 AM Prior Vol = 19.29 Prior Ind = 3455.65
    2/7/2014 9:50:00 AM Prior Vol = 19.29 Prior Ind = 3497.01
    2/7/2014 10:00:00 AM Prior Vol = 19.29 Prior Ind = 3497.01
    2/10/2014 9:40:00 AM Prior Vol = 16.55 Prior Ind = 3497.01
    2/10/2014 9:50:00 AM Prior Vol = 16.55 Prior Ind = 3560.36
    2/10/2014 10:00:00 AM Prior Vol = 16.55 Prior Ind = 3560.36

    G) The value of Closes[3][0] at 9:50AM and 10:00AM are correct. It is clear that the value at 9:40AM is from a prior bar/day.

    My Guess as to the Problem:
    There is a boundary condition that is being caused since Closes[3][0] is taken at the first 10 Minute bar of the trading session at 9:40 AM. In the Live strategy, NT does treat the first bar as closed yet and so gives the value from the previous bar which is the last bar of the prior day. This is a total guess and I would love to be wrong or told what I am doing wrong which is creating this situation.

    Further info regarding setup:
    Initialize:
    Add(Instrument.FullName, PeriodType.Minute, 10);
    Add(triggerName, PeriodType.Minute, 390);
    Add(IndexName, PeriodType.Minute, 390);
    TraceOrders = true;
    CalculateOnBarClose = true;

    #2
    Hello joesandyego,

    It may help better understand what bars is being access if you also Print out the time of the BarIndex 3 using Times[3][0].



    Could you try this and let me know the result?
    JCNinjaTrader Customer Service

    Comment


      #3
      Sure. It will take until tomorrow to get the result since I have to wait until market open.

      Comment


        #4
        You are right. The timestamps (attached) shows Instrument 3 has the incorrect bar at 9:40AM. It also shows that the Instrument 2 bar is correct. I only point this out since both are 390 minute bars.

        Instrument 2 is ^VXN
        Instrument 3 is ^NDX

        I am using IQFeed. Does this mean that IQFeed is passing the wrong real-time data, but correct historical data for ^NDX? The problem with this argument is that using Replay, the data is correct, and I thought that Replay was the exact recording of real-time data (coming from IQFeed in my case). Why would it be different?
        Attached Files

        Comment


          #5
          Hello joesandyego,

          This is going to be due when you are calling the Closes[3][0]. You may want to make sure that when you are accessing the data that that the Index Series 3 has been updated.

          For example:
          Code:
          if(BarsInProgress == 3)
               //Do something
          There is a good diagram on how bars are referenced in our Help Guide at the following link.
          JCNinjaTrader Customer Service

          Comment


            #6
            Hi JC,

            I understand that this is an update issue on Instrument 3. However, from my understanding of multi-timeframe strategies there should be no issue here.

            I am asking for Closes[3][0] on the day after it has closed. Why would the Closes[3][0] update not be available 17.5 hours after the bar closed?

            Secondly, why does it work correctly on Instrument 2, which is also a 390 Minute Bar?

            Sorry for wanting to go deeper into this, but to not be able to trade at or near market open because a bar isn't updating after being closed for 17.5 hours is problematic.

            I would be very happy to hear that I am doing something wrong and how I can fix it. Also, I would like to understand how Replay works correctly but real-time doesn't since it should be identical data.

            Thanks for your continued help.

            Comment


              #7
              Hello joesandyego,

              NinjaTrader is not going to consider the bar closed until it has gotten a new tick of data has come in which is why you waiting until BarsInProgress (BIP) 3 to access this information is what you may want to do.

              You are using both a Multi-Time Frame and Multi-Instrument approach which is going to act similarly but it will still require a check for the BarsInProgress 3 to be checked first.

              When the call first comes up you may see this show up since it is another instrument and it will load the data at the same time at the start, but after this it will be processed sequentially meaning that BIP 0-2 will get called before 3.

              If you add the BIP 3 check does your results come up as you would expect?
              JCNinjaTrader Customer Service

              Comment


                #8
                Hi JC,
                Attached is the BIPs and Closes data. It does show that Instrument 3 closes at 9:40AM instead of 4PM the previous day. Is there anything that I can do to change this behavior? It seems to be unique to ^NDX.
                Attached Files

                Comment


                  #9
                  Hello joesandyego,

                  There is no way to change the behavior as NinjaTrader is not going to close the bar until a new tick of data comes in.

                  On line 4 of your text documents you can see that when the BIP 3 is being called it is updating while still at 9:40 so you may do your calculations at this point to have all of the updated data.

                  Let us know if we can be of any further assistance.
                  JCNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kaywai, Today, 06:26 AM
                  1 response
                  5 views
                  0 likes
                  Last Post kaywai
                  by kaywai
                   
                  Started by ct, 05-07-2023, 12:31 PM
                  6 responses
                  203 views
                  0 likes
                  Last Post wisconsinpat  
                  Started by kevinenergy, 02-17-2023, 12:42 PM
                  118 responses
                  2,780 views
                  1 like
                  Last Post kevinenergy  
                  Started by briansaul, Today, 05:31 AM
                  0 responses
                  10 views
                  0 likes
                  Last Post briansaul  
                  Started by traderqz, Yesterday, 12:06 AM
                  11 responses
                  28 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X