diff --git a/indicators/News.cs b/indicators/News.cs index d16ff48..677aa2a 100644 --- a/indicators/News.cs +++ b/indicators/News.cs @@ -126,6 +126,9 @@ namespace NinjaTrader.NinjaScript.Indicators // Remove any extraneous HTML tags from the time string time = Regex.Replace(time, "<.*?>", string.Empty); + // Convert the time to the user's time zone + time = ConvertToUserTimeZone(time); + newsEvents.Add(new NewsEvent { Time = time, Currency = currency, Title = title }); } } @@ -136,6 +139,26 @@ namespace NinjaTrader.NinjaScript.Indicators } } + private string ConvertToUserTimeZone(string time) + { + try + { + // Assumed to be in US Eastern Time + DateTime easternTime = DateTime.ParseExact(time, "h:mmtt", System.Globalization.CultureInfo.InvariantCulture); + TimeZoneInfo easternTimeZone = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"); + + DateTime userTime = TimeZoneInfo.ConvertTime(easternTime, easternTimeZone, Core.Globals.GeneralOptions.TimeZoneInfo); + + // Format the time as "hh:mmtt" (e.g., "06:30am") + return userTime.ToString("hh:mmtt").ToLower(); + } + catch (Exception ex) + { + Print("Error converting time: " + ex.Message); + return time; // Return original time if conversion fails + } + } + protected override void OnBarUpdate() { } protected override void OnRender(ChartControl chartControl, ChartScale chartScale)