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

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.
    Chris L.NinjaTrader Customer Service

    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 RideMe, 04-07-2024, 04:54 PM
      5 responses
      28 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by f.saeidi, Today, 08:13 AM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by DavidHP, Today, 07:56 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Erick  
      Started by kujista, Today, 06:23 AM
      3 responses
      9 views
      0 likes
      Last Post kujista
      by kujista
       
      Started by Mindset, Yesterday, 02:04 AM
      2 responses
      18 views
      0 likes
      Last Post NinjaTrader_RyanS  
      Working...
      X