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

how to get seconds/minutes passed after bar start?

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

    how to get seconds/minutes passed after bar start?

    I thought Time[0] would give me i.e. 09:47:31 (hour,minute,second) on the last, realtime bar.


    when on realtime chart (lets say, 5 min), i thought:

    Time[0]-Time[1] would give i.e. 2 mins, if 2 minutes is passed after bar start. however it doesnt do that.


    how to get current minutes passed after the last bar started?
    Probably with datetimes, but a i say, i cant make it work.

    #2
    Found one solution for only LIVE-BAR - DateTime.Now.

    however, that doesnt work in backtesting.. for example, when TickReplay is, i cant still get current H:M:S of execution on that tick. Time[0] always returns such time:

    09:35:00
    09:40:00
    ....etc

    Comment


      #3
      Hello,

      Thanks for your post.

      Instead of Time[0]-Time[1] To get the time since the last bar started in OnBarUpdate() you would compare the times you mentioned similar to the snippet below:

      Time[0].Subtract(Time[1])

      The following help guide article will go into further detail on the DateTime object.

      Represents an instant in time, typically expressed as a date and time of day.


      If you have any further questions please let me know.
      Josh G.NinjaTrader Customer Service

      Comment


        #4
        Time[0].Subtract(Time[1]) even returns the same value as `Time[0]-Time[1]`.

        The only solution seems (but not in simple backtesting) DateTime.Now - Time[1], but this works only in LIVE data (or Market Replay).

        Also, i am trying to solve the problem with granularity/ intrabar orders, but in backtesting, i have some problems at this moment.
        However, thanks for help!

        Comment


          #5
          Originally posted by selnomeria View Post
          Time[0].Subtract(Time[1]) even returns the same value as `Time[0]-Time[1]`.

          The only solution seems (but not in simple backtesting) DateTime.Now - Time[1], but this works only in LIVE data (or Market Replay).

          Also, i am trying to solve the problem with granularity/ intrabar orders, but in backtesting, i have some problems at this moment.
          However, thanks for help!
          The only way to get intrabar granularity access in NT7 is to use a secondary price series. I always use 1-second, but there are those that insist that one must use 1-tick.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by bmartz, 03-12-2024, 06:12 AM
          5 responses
          32 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by Aviram Y, Today, 05:29 AM
          4 responses
          13 views
          0 likes
          Last Post Aviram Y  
          Started by algospoke, 04-17-2024, 06:40 PM
          3 responses
          28 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by gentlebenthebear, Today, 01:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by cls71, Today, 04:45 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X