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

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);
        ​
        JesseNinjaTrader Customer Service

        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.
            JesseNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by AaronKoRn, Today, 09:49 PM
            0 responses
            11 views
            0 likes
            Last Post AaronKoRn  
            Started by carnitron, Today, 08:42 PM
            0 responses
            10 views
            0 likes
            Last Post carnitron  
            Started by strategist007, Today, 07:51 PM
            0 responses
            11 views
            0 likes
            Last Post strategist007  
            Started by StockTrader88, 03-06-2021, 08:58 AM
            44 responses
            3,980 views
            3 likes
            Last Post jhudas88  
            Started by rbeckmann05, Today, 06:48 PM
            0 responses
            9 views
            0 likes
            Last Post rbeckmann05  
            Working...
            X