Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time Range Сondition

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

    Time Range Сondition

    I'm trying to make a condition on a time interval, the problem is that I need the condition to work on the converted time My local and NT time is different from the converted one

    The task for the condition to work according to the convertible time

    the code

    Code:
    StartMaxVol = DateTime.Parse("10:00", System.Globalization.CultureInfo.InvariantCulture) ;
    EndMaxVol = DateTime.Parse("22:00", System.Globalization.CultureInfo.InvariantCulture) ;
    
    TM = "Eastern Standard Time";
    
    // TIME CONVERTED
    
    DateTime ExchangeDateTime = TimeZoneInfo.ConvertTimeBySystemTimeZoneId(DateTim e.Now, (TM));
    
    
    if (!UseTime || ExchangeDateTime >= StartMaxVol && ExchangeDateTime <= EndMaxVol)
    {
    
     // LOGIC
    
    }
    Why does not it work?
    Last edited by memonolog; 11-21-2020, 01:47 AM.

    #2
    Hello memonolog,

    The time of the chart bars and DateTime.Now will always be your local computer time and will never be in the exchange time zone. Do you have NinjaTrader set to a different time zone than your computer's clock time zone?

    To confirm, you are trying to convert your local time zone to the time in eastern time no matter what your local time zone is, is this correct?

    What is your PC time zone, or the time zone NinjaTrader is set to?

    What prints for Time[0] (or DateTime.Now)?

    What prints for ExchangeDateTime?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello memonolog,
      To confirm, you are trying to convert your local time zone to the time in eastern time no matter what your local time zone is, is this correct?
      Have already converted the time - ExchangeDateTime

      How can I make the condition work by converted time, no matter what is the local time?

      how to specify the scope of work conditions for converting time? (syntax)
      Last edited by memonolog; 11-23-2020, 01:24 AM.

      Comment


        #4
        Hello memonolog,

        To confirm, you are wanting to convert from universal time or from the exchange time to your local time zone for the condition?

        To convert a date time to your local time zone use TimeZoneInfo.ConvertTimeFromUtc().
        Code:
        DateTime universalDate = new DateTime(2020, 11, 23, 15, 30, 5);
        DateTime convertedToMyTimeZoneDate = TimeZoneInfo.ConvertTimeFromUtc(universalDate, TimeZoneInfo.Local);
        Print(string.Format("{0} UTC is {1} {2}", universalDate, convertedToMyTimeZoneDate, TimeZoneInfo.Local.Id));
        If you want to convert a time from another time zone to your time zone an easy way would be to get the date objects .ToUniversalTime(), then convert this to your local time zone with TimeZoneInfo.ConvertTimeFromUtc().

        Or you could use TimeZoneInfo.ConvertTime().
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        571 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        330 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        548 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        549 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X