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 Hwop38, 05-04-2026, 07:02 PM
            0 responses
            161 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            310 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            245 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            350 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            179 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X