Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Remaining time for the current bar

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

    Remaining time for the current bar

    Hello,

    I'm using Calculate.OnEachTick. However, I only want to do my processing during the last 5 or 10 seconds of the current bar. My goal is place an order essentially as the bar closes but before the next bar begins. I'm using time based bars (5-minute).

    What is the easiest way to determine the remaining time in the current bar?

    I could use a BarTimer indicator in my code, but I'm not seeing any method or property that returns number of seconds remaining (or counting up). Further, I couldn't find any webpage or website with a BarTime API. And it isn't listed here: https://ninjatrader.com/support/help...indicators.htm

    Thanks!
    Matt


    #2
    Hi Matt, thanks for your post.

    You would need to look at the source code for BarTimer.cs and implement the same timer in your indicator to get the same functionality. There is also the PercentComplete method that could prove useful.

    Please let me know if you have any further questions on this.

    Comment


      #3
      Hi Chris,

      Thank you for the quick reply. Reviewing that code, I came up with the following method in my strategy.

      Code:
      [FONT=courier new]private int getSecondsRemaining() {
         // Code/logic taken from BarTimer.cs - Ninja Trader indicator code
         DateTime now = (Cbi.Connection.PlaybackConnection != null ? Cbi.Connection.PlaybackConnection.Now : Core.Globals.Now);
         if (now.Millisecond > 0) now = Core.Globals.MinDate.AddSeconds((long)Math.Floor(now.Subtract(Core.Globals.MinDate).TotalSeconds));
      
         TimeSpan barTimeLeft = Bars.GetTime(Bars.Count - 1).Subtract(now);
         return barTimeLeft.Seconds;
      }[/FONT]
      Hopefully that will work. I'll try to remember to come back here to confirm.

      Thanks!
      Matt

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      87 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      132 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      118 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      67 views
      0 likes
      Last Post PaulMohn  
      Working...
      X