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

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 rbeckmann05, Yesterday, 06:48 PM
            1 response
            12 views
            0 likes
            Last Post bltdavid  
            Started by llanqui, Today, 03:53 AM
            0 responses
            6 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by burtoninlondon, Today, 12:38 AM
            0 responses
            10 views
            0 likes
            Last Post burtoninlondon  
            Started by AaronKoRn, Yesterday, 09:49 PM
            0 responses
            15 views
            0 likes
            Last Post AaronKoRn  
            Started by carnitron, Yesterday, 08:42 PM
            0 responses
            11 views
            0 likes
            Last Post carnitron  
            Working...
            X