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 NullPointStrategies, Today, 05:17 AM
      0 responses
      50 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      126 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      68 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      42 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      46 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X