Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question aboutplatform time and computer system time

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

    Question aboutplatform time and computer system time

    I am not sure if i've got something mixed up here.

    I am trying to get currentTimeOfDay in EST. My ninjatrader platform is set to EST, my system clock is UTC +8 which is 12 hours from EST.

    Code:
    TimeZoneInfo estTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
    DateTime estCurrentTime = TimeZoneInfo.ConvertTime(Time[0], estTimeZone);
    TimeSpan currentTimeOfDay = estCurrentTime.TimeOfDay;
    
    Print($"Current Time (EST): {estCurrentTime}, Current Time of Day: {currentTimeOfDay}");


    The print is giving me the same time for both, this is the result of the print

    Current Time (EST): 4/28/2025 12:30:00 AM, Current Time of Day: 00:30:00
    Any ideas what i've got wrong here?

    #2
    hello sofortune,

    The code you are printing is printing the same property twice. estCurrentTime is the DateTime which you created. currentTimeOfDay used estCurrentTime to get the time of day which is the same time.

    Do you want the current bar time or the current time when the code is executed based on the selected timezone?

    If you want the current bar time you can use Time[0]. In historical that represents the last closed bar time. In realtime it is also that unless OnEachTick or OnPriceChange are being used, in which it will be the building bars close time.

    If you are using OnEachTick and want to know the offset PC time you can use NinjaTrader.Core.Globals.Now to get the current platform DateTime.

    Comment


      #3
      Oh my you are right.

      I just want to check if a time parameter is greater than for example the current platform time.

      So would it look something like this

      Code:
      if(NinjaTrader.Core.Globals.Now.Time > tradeStartTime)

      Comment


        #4
        Hello sofortune,

        Right, C# lets you compare DateTime objects with greater or lesser operators like that. you can use a print to additionally see what values each have to see how it equates.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        25 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        121 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X