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 cmoran13, 04-16-2026, 01:02 PM
            0 responses
            43 views
            0 likes
            Last Post cmoran13  
            Started by PaulMohn, 04-10-2026, 11:11 AM
            0 responses
            25 views
            0 likes
            Last Post PaulMohn  
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            163 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            98 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            158 views
            2 likes
            Last Post CaptainJack  
            Working...
            X