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

Working with dates around month end

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

    Working with dates around month end

    I am using a formula

    ToDay(Time[0]) == date-2

    where date is in 20120702 (int) format, it works fine for the month, but for a month end it wont work,

    Is there a simple solution to take a date stored as an int to work around month ends, just to take away 2 days or so?

    Thanks

    Tinkerz

    #2
    Hello Tinkerz,
    If you try the below code then are you getting the correct values.

    Code:
    if (ToDay(Time[0]) == ToDay(new DateTime(2012, 7, 2).AddDays(-2)))
    {
    	//do something
    }
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      My date time is a list of dates in int format to I am matching them up

      The numbers will be changing all the time, so
      (2012, 7, 2)
      will change to 20120702, how can I make that bit change inline with my date integer?

      Comment


        #4
        Hello tinkerz,
        You have to either use a List of DateTime (List<DateTime>) or you can further custom code it and extract the year, month and day from the integer.

        For example to find the year you can use the below function.

        Code:
        private int IntToYear(int date)
        {
                   return (int)(date / 10000);
        }
        And call it from the code as

        Code:
        int year = IntToYear(20121026);
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        5 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        214 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        547 views
        0 likes
        Last Post PaulMohn  
        Working...
        X