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 RookieTrader, Today, 09:37 AM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by kulwinder73, Today, 10:31 AM
        0 responses
        5 views
        0 likes
        Last Post kulwinder73  
        Started by terofs, Yesterday, 04:18 PM
        1 response
        23 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by CommonWhale, Today, 09:55 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Gerik, Today, 09:40 AM
        2 responses
        7 views
        0 likes
        Last Post Gerik
        by Gerik
         
        Working...
        X