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

Need to understand BarsInProgress. Potential Bug?

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

    Need to understand BarsInProgress. Potential Bug?

    Hi,

    My strategy involves multiple TFs. I am using Range 1 and 1 Tick timeframes.
    I have added 1 Tick as the secondary Timeframe and 1 Range is my primary where I have added my strategy.
    It seems like the order in which BarsInProgress is being called is incorrect. In my mind, the 1 Tick should be called first and then the 1 Range.

    Just to test things, I added the following code so see how things are,

    switch(BarsInProgress)
    {

    case 0: // 1 Range TF
    Print("Range1: Highs="+ Highs[0][0]+"Lows=" +Lows[0][0]);
    break;

    case 1: // 1 Tick TF
    Print("Tick1: Highs="+ Highs[1][0]+"Lows=" +Lows[1][0]);

    break;


    }


    and here is the output I am getting

    Tick1: Highs=3828.25Lows=3828.25 <---Correct
    Range1: Highs=3828.25Lows=3828 <----Called before 3828 tick is posted
    Tick1: Highs=3828Lows=3828 <-----Called after 1 Range has been posted
    Range1: Highs=3827.75Lows=3827.5
    Tick1: Highs=3828Lows=3828
    Tick1: Highs=3828Lows=3828
    Tick1: Highs=3827.5Lows=3827.5
    Tick1: Highs=3827.5Lows=3827.5
    Tick1: Highs=3827.25Lows=3827.25
    Tick1: Highs=3827.25Lows=3827.25
    Tick1: Highs=3827.25Lows=3827.25
    Tick1: Highs=3827.5Lows=3827.5
    Tick1: Highs=3827.25Lows=3827.25
    Range1: Highs=3827.5Lows=3827.25
    Tick1: Highs=3827.5Lows=3827.5
    Range1: Highs=3828Lows=3827.75
    Tick1: Highs=3828.25Lows=3828.25
    Range1: Highs=3828.25Lows=3828
    Tick1: Highs=3827.5Lows=3827.5
    Range1: Highs=3827.75Lows=3827.5
    Tick1: Highs=3827.25Lows=3827.25
    Tick1: Highs=3827Lows=3827
    Range1: Highs=3827.25Lows=3827


    Now, if you look at the pictures attached, you can see the issue, if I am using Tick TF to drive calculations and paint results on 1 range TF then it throws things off.
    Because, if you look at the 2nd and 3rd line of the output, Range 1 is called before Tick 1 TF. Shouldn't it be the other way around?

    #2
    I believe what you have found is expected behavior.

    Study "Working With Multi-Time Frame Objects" here.

    Comment


      #3
      Hi MyFirstMillion, thanks for posting. This is expected, see this note from the multi time frame page:
      Note: Historical bars are processed according to their timestamps with the primary bars first, followed by the secondary, which is NOT guaranteed to be the same sequence that these events occurred in real-time. If your development requires ticks to process in the same sequence historically as well as in real-time, you will need to enable Tick Replay (utilizes more PC resources).
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Thank you for the reply. I have enabled Tick Replay and I am still seeing the same problem. Just to test it further, I added two data series as secondary -1 Tick and 1Range

        AddDataSeries(Data.BarsPeriodType.Tick, 1);
        AddDataSeries(Data.BarsPeriodType.Range, 1);

        switch(BarsInProgress)
        {

        case 1:
        Print("Tick1: Highs="+ Highs[1][0]+"Lows=" +Lows[1][0]);
        break;

        case 2:
        Print("Range1: Highs="+ Highs[2][0]+"Lows=" +Lows[2][0]);

        break;


        }


        With the tick replay enabled, here is the output

        Range1: Highs=3828.25Lows=3828 <---Range TF is getting called before the Tick TF.
        Range1: Highs=3827.75Lows=3827.5
        Tick1: Highs=3828.25Lows=3828.25
        Tick1: Highs=3828Lows=3828
        Tick1: Highs=3828Lows=3828
        Tick1: Highs=3828Lows=3828
        Tick1: Highs=3827.5Lows=3827.5
        Tick1: Highs=3827.5Lows=3827.5
        Tick1: Highs=3827.25Lows=3827.25
        Tick1: Highs=3827.25Lows=3827.25
        Tick1: Highs=3827.25Lows=3827.25
        Tick1: Highs=3827.5Lows=3827.5
        Range1: Highs=3827.5Lows=3827.25
        Range1: Highs=3828Lows=3827.75


        What am i doing wrong?

        Thanks

        Comment


          #5
          Nothing.

          Tick Replay does not alter the order in which
          the Bars data is processed -- that is, primary
          bars first, followed by the secondary -- Tick
          Replay does not change that.

          For Support to imply that Tick Replay could
          affect your complaint/inquiry was misleading
          and incorrect, IMHO, of course.

          What to do?

          Study the entire page of that link I sent you.

          Seriously, you need become expert with what
          that page reveals -- it is critical education and
          absolutely explains what really happens -- and
          why your expectations were flat wrong.

          Comment


            #6
            Hi MyFirstMillion, The tick replay will sequence each series properly, not send the ticks in sequence relative to each added series. The primary series updates will still come first even if the timestamps of the secondary series are sooner relative to the primary time stamps. Tick Replay will sequence the 1 tick series and primary series individually.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi All,

              Thanks again for your responses. I went back and re-read the notes using the links you provided. I understand that Primary Bars are processed first regardless of whether or not TickReplay is enabled.

              So, since my goal is to be able to view candles form synced to 1 Tick, is there anyway I can create custom candles driven by Tick chart? I have already tried adding drawing objects but it slows down the system and my PC hangs.
              Last edited by MyFirstMillion; 07-08-2022, 08:37 PM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by geddyisodin, Today, 05:20 AM
              0 responses
              3 views
              0 likes
              Last Post geddyisodin  
              Started by JonesJoker, 04-22-2024, 12:23 PM
              6 responses
              33 views
              0 likes
              Last Post JonesJoker  
              Started by GussJ, 03-04-2020, 03:11 PM
              12 responses
              3,239 views
              0 likes
              Last Post Leafcutter  
              Started by AveryFlynn, Today, 04:57 AM
              0 responses
              6 views
              0 likes
              Last Post AveryFlynn  
              Started by RubenCazorla, 08-30-2022, 06:36 AM
              3 responses
              79 views
              0 likes
              Last Post PaulMohn  
              Working...
              X