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 reynoldsn, Today, 07:26 PM
      0 responses
      1 view
      0 likes
      Last Post reynoldsn  
      Started by ETFVoyageur, 05-07-2024, 07:05 PM
      12 responses
      76 views
      0 likes
      Last Post bltdavid  
      Started by Haiasi, 04-25-2024, 06:53 PM
      5 responses
      76 views
      0 likes
      Last Post alancurry  
      Started by ZeroKuhl, Today, 04:31 PM
      0 responses
      16 views
      0 likes
      Last Post ZeroKuhl  
      Started by Vulgoth_t_Destroyer, 05-09-2022, 04:45 PM
      54 responses
      5,337 views
      0 likes
      Last Post Gaterz
      by Gaterz
       
      Working...
      X