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 jclose, Today, 09:37 PM
          0 responses
          6 views
          0 likes
          Last Post jclose
          by jclose
           
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          10 responses
          1,414 views
          0 likes
          Last Post Traderontheroad  
          Started by firefoxforum12, Today, 08:53 PM
          0 responses
          11 views
          0 likes
          Last Post firefoxforum12  
          Started by stafe, Today, 08:34 PM
          0 responses
          11 views
          0 likes
          Last Post stafe
          by stafe
           
          Started by sastrades, 01-31-2024, 10:19 PM
          11 responses
          169 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Working...
          X