Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

DateTime

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

    DateTime

    Apologies if these are C# questions but I'm initialising

    startDateTime = DateTime.Parse("08/18/2018 18:00:00", System.Globalization.CultureInfo.InvariantCulture) ;
    endDateTime = DateTime.Parse("08/19/2018 15:00:00", System.Globalization.CultureInfo.InvariantCulture) ;

    defined as properties

    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")]
    [Display(Name="Start DateTime", Description="Start DateTime", Order=1, GroupName="Setup")]
    public DateTime startDateTime
    { get; set; }

    [NinjaScriptProperty]
    [PropertyEditor("NinjaTrader.Gui.Tools.ChartAnchorT imeEditor")]
    [Display(Name="End DateTime", Description="End DateTime", Order=2, GroupName="Setup")]
    public DateTime endDateTime
    { get; set; }


    how can I initialise startDateTime to todays date and endDateTime to tomorrows date?

    also will the initialisation work in the UK (dd/mm/yyyy) and in the US (mm/dd/yyyy)


    #2
    if I add the following in State.SetDefaults

    DateTime today = DateTime.Today;
    DateTime tomorrow = DateTime.Today.AddDays(+1);

    startDateTime = DateTime.Parse(today.ToString(), System.Globalization.CultureInfo.InvariantCulture) ;
    endDateTime = DateTime.Parse(tomorrow.ToString(), System.Globalization.CultureInfo.InvariantCulture) ;

    it compiles ok but my indicator no longer appears on the chart indicator list.​

    Comment


      #3
      You only need to do parsing if you are converting from a string. You're starting with a DateTime value so there's no need to convert to string then parse it back to a DateTime value like you're doing. This is all you need in SetDefaults:

      startDateTime = DateTime.Today;
      endDateTime = DateTime.Today.AddDays(1);

      Comment


        #4
        Hello fingers,

        If your indicator no longer appears in the list you likely have an error happening, you can check the control center log tab to confirm that.

        As kevinenergy mentioned you don't need the second part of your code to re parse the DateTime, you just need to set a default value.

        As a side note you can use NinjaTrader.Core.Globals.Now in place of DateTime.Today to support the playback connection, DateTime.Today is your PC clock time and NinjaTrader.Core.Globals.Now is the platforms version of that which supports all NinjaTrader tools.

        Code:
        startDateTime = NinjaTrader.Core.Globals.Now;
        endDateTime = NinjaTrader.Core.Globals.Now.AddDays(1);
        ​

        Comment


          #5
          ok thanks.

          do I not need System.Globalization.CultureInfo.InvariantCulture if the code is being used In the UK & US?​

          I also need to initialise both date & time e.g. "10/20/2023 18:00:00"
          Last edited by fingers; 10-20-2023, 10:34 AM.

          Comment


            #6
            Hello fingers,

            If you need to use a specific time you would have to create a new date time that has the given time. Using the DateTime.Today will only create a date of today for example: 10/20/2023 12:00:00 AM

            https://learn.microsoft.com/en-us/do...ramework-4.8.1

            You can construct a new datetime using the datetimes constructor like the following:


            Code:
            DateTime today = NinjaTrader.Core.Globals.Now;
            DateTime tomorrow = NinjaTrader.Core.Globals.Now.AddDays(1);
            startDateTime = new DateTime(today.Year, today.Month, today.Day, 18, 0,0);
            endDateTime = new DateTime(tomorrow.Year, tomorrow.Month, tomorrow.Day, 18, 0,0);


            Because you are not parsing a string you wouldn't need to add the cultureinfo to that.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            587 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            341 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            555 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X