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

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 PaulMohn, Today, 03:49 AM
            0 responses
            3 views
            0 likes
            Last Post PaulMohn  
            Started by inanazsocial, Today, 01:15 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jason  
            Started by rocketman7, Today, 02:12 AM
            0 responses
            10 views
            0 likes
            Last Post rocketman7  
            Started by dustydbayer, Today, 01:59 AM
            0 responses
            2 views
            0 likes
            Last Post dustydbayer  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            5 responses
            23 views
            0 likes
            Last Post trilliantrader  
            Working...
            X