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 cmoran13, 04-16-2026, 01:02 PM
        0 responses
        51 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        31 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        165 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        100 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        160 views
        2 likes
        Last Post CaptainJack  
        Working...
        X