Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DateTime question

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

    DateTime question

    Hi all



    I need to know on the first bar of the session how many days have gone by since the last trading day. Is there an easy way to calculate that ?

    if(FirstBarOfSession)

    Time[0].........??????


    Bernard

    #2
    Hi Bernard,

    If Time[0] is the current day, then Time[1] should be the bar traded at the last trading day, is that correct? If yes, then you could try something like Time[0].Date - Time[1].Date

    Regards
    Ralph

    Comment


      #3
      Ralph


      What is the return type. TimeSpan ?

      If yes how can I convert that to an int for calculation purposes

      Thanks Ralph


      Bernard

      Comment


        #4
        hmmm, that's true it is a TimeSpan. In this case try TimespanVariable.Days. That seems to return an int.

        Regards
        Ralph

        Comment


          #5
          You could try ToDay(Time[0]) - ToDay(Time[1]). Those are already ints to begin with.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            OK guys I found it


            What I did is :

            TimeSpan ts = Time[0].Date.Subtract(Time[1].Date);
            timeadjustment = ts.TotalDays;


            That gives me a double that I use later in my code.

            Thank you all for your help

            Bernard

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            581 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            338 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X