Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Seconds between bars calculation difference

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

    Seconds between bars calculation difference

    Hi NT support,

    Attached is an indicator that calculates seconds per bar. It does it using 2 methods:
    1. Using a secondary (PeriodType.Second,1) period and a counter which is reset in the primary period
    2. Calculating total seconds between Time[0] and Time[1] bars.

    I expect seconds count in both methods to be at least close if not equal but instead there are huge differences (I tested on a sim connection). Could you explain why the seconds count in method 1 would be so off?

    Thanks,
    Tim
    Attached Files

    #2
    Hello Tim,

    Your logic seems to be correct. A second bar will only generate after a Last Price is received from the Broker which, does makes sense during the Market that it would be grater and outside of Market Hours it would be less.

    You may open up a 1 second chart and verify this.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JC View Post
      Hello Tim,

      Your logic seems to be correct. A second bar will only generate after a Last Price is received from the Broker which, does makes sense during the Market that it would be grater and outside of Market Hours it would be less.

      You may open up a 1 second chart and verify this.
      I changed the code to account for that:
      Code:
      	if(BarsInProgress!=0){
      		valup+=(int)(Time[0].Subtract(Time[1]).TotalSeconds);
      		return;
      	}
      The second count is now much more consistent, however it's not perfect and there are areas where there is a visible difference. Please see screenshot.
      Attached Files

      Comment


        #4
        Hello nailz420,

        I am not sure I know exactly what you are looking for based on your changes that you have made. Could you may be clarify what you are looking for Plot0 to be?

        Are you looking for the number of seconds in the 3 Minute bar or are you looking when the last second bar is generated before another 3 Minute bar appears?
        JCNinjaTrader Customer Service

        Comment


          #5
          This indicator is meant to be used on non-time based period types, such as range. I am looking for the number of seconds in a bar and with this test I am trying to show and understand why there is a discrepancy in the results.

          Comment


            #6
            Hello nailz420,

            Thanks for the clarification. If that is the case you should not need to add a secondary Data Series as this will complicate your indicator. You can just use the current Time minus the previous Bars Time for this.

            For example.
            protected override void Initialize()
            {
            Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Bar, "Plot0"));
            CalculateOnBarClose = true;
            Overlay = false;
            }

            protected override void OnBarUpdate()
            {
            if(CurrentBar < 1) return;

            Plot0.Set(Time[0].Subtract(Time[1]).TotalSeconds);
            }
            JCNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            581 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            338 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X