Wizard Trends Clocks displays three live analog market clocks for New York (ET) , Chicago (CT), and California (PT) directly on your NinjaTrader chart. It updates in real time and includes customizable clock sizes, multiple professional color themes, optional digital time and date displays, and a clean, modern interface to help traders quickly monitor major U.S. market time zones.
#region Using declarations
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Threading;
using NinjaTrader.NinjaScript;
#endregion
namespace NinjaTrader.NinjaScript
{
public enum WTClockSizePreset
{
Small,
Medium,
Large
}
public enum WTClockColorTemplate
{
ClassicRed,
MatrixGreen,
ElectricBlue,
Gold,
Purple
}
}
namespace NinjaTrader.NinjaScript.Indicators
{
public class WizardTrendsWorldClocks : Indicator
{
private Grid mainPanel;
private DispatcherTimer clockTimer;
private AnalogClock newYorkClock;
private AnalogClock chicagoClock;
private AnalogClock californiaClock;
private TimeZoneInfo newYorkZone;
private TimeZoneInfo chicagoZone;
private TimeZoneInfo californiaZone;
private ThemePalette activeTheme;
private double activeClockSize;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "Wizard Trends World Clocks";
Description = "Displays live analog clocks for New York, Chicago, and California.";
Calculate = Calculate.OnEachTick;
IsOverlay = true;
DisplayInDataBox = false;
DrawOnPricePanel = true;
PaintPriceMarkers = false;
IsSuspendedWhileInactive = false;
SizePreset = WTClockSizePreset.Medium;
ColorTemplate = WTClockColorTemplate.ClassicRed;
PanelOpacity = 96;
ShowSecondHand = true;
ShowDigitalTime = true;
ShowDate = true;
ShowFooter = true;
}
else if (State == State.DataLoaded)
{
LoadTimeZones();
if (ChartControl != null)
ChartControl.Dispatcher.InvokeAsync(CreateClockPanel);
}
else if (State == State.Terminated)
{
if (ChartControl != null)
ChartControl.Dispatcher.InvokeAsync(RemoveClockPanel);
}
}
protected override void OnBarUpdate()
{
}
private void LoadTimeZones()
{
try
{
newYorkZone =
TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");
chicagoZone =
TimeZoneInfo.FindSystemTimeZoneById("Central Standard Time");
californiaZone =
TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");
}
catch
{
newYorkZone = TimeZoneInfo.Local;
chicagoZone = TimeZoneInfo.Local;
californiaZone = TimeZoneInfo.Local;
}
}
private void CreateClockPanel()
{
RemoveClockPanel();
activeClockSize = GetClockSize();
activeTheme = GetTheme();
double panelWidth = activeClockSize * 3.0 + 95.0;
mainPanel = new Grid
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(10),
Width = panelWidth,
Background = Brushes.Transparent,
IsHitTestVisible = false
};
Border outerBorder = new Border
{
Background = MakeBrush(
activeTheme.PanelBackground,
PanelOpacity),
BorderBrush =
new SolidColorBrush(activeTheme.PanelBorder),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(10),
Padding = new Thickness(12, 10, 12, 10),
Child = BuildPanelContent()
};
mainPanel.Children.Add(outerBorder);
UserControlCollection.Add(mainPanel);
clockTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(200)
};
clockTimer.Tick += ClockTimer_Tick;
clockTimer.Start();
UpdateClocks();
}
private UIElement BuildPanelContent()
{
StackPanel mainStack = new StackPanel
{
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Top
};
TextBlock title = new TextBlock
{
Text = "WIZARD TRENDS",
Foreground =
new SolidColorBrush(activeTheme.TitleText),
FontSize = GetTitleFontSize(),
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 0, 0, 8)
};
mainStack.Children.Add(title);
StackPanel clocksRow = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top
};
newYorkClock = new AnalogClock(
"NEW YORK",
"ET",
activeClockSize,
activeTheme,
ShowSecondHand,
ShowDigitalTime,
ShowDate);
chicagoClock = new AnalogClock(
"CHICAGO",
"CT",
activeClockSize,
activeTheme,
ShowSecondHand,
ShowDigitalTime,
ShowDate);
californiaClock = new AnalogClock(
"CALIFORNIA",
"PT",
activeClockSize,
activeTheme,
ShowSecondHand,
ShowDigitalTime,
ShowDate);
clocksRow.Children.Add(newYorkClock.Root);
clocksRow.Children.Add(chicagoClock.Root);
clocksRow.Children.Add(californiaClock.Root);
mainStack.Children.Add(clocksRow);
if (ShowFooter)
{
Border footerDivider = new Border
{
Height = 1,
Background =
new SolidColorBrush(activeTheme.Divider),
Margin = new Thickness(10, 8, 10, 5)
};
mainStack.Children.Add(footerDivider);
TextBlock footer = new TextBlock
{
Text = "Trading Sessions • Live Market Time",
Foreground =
new SolidColorBrush(
activeTheme.SecondaryText),
FontSize = GetFooterFontSize(),
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 0, 0, 1)
};
mainStack.Children.Add(footer);
}
return mainStack;
}
private void ClockTimer_Tick(object sender, EventArgs e)
{
UpdateClocks();
}
private void UpdateClocks()
{
DateTime utcNow = DateTime.UtcNow;
DateTime newYorkTime =
TimeZoneInfo.ConvertTimeFromUtc(
utcNow,
newYorkZone);
DateTime chicagoTime =
TimeZoneInfo.ConvertTimeFromUtc(
utcNow,
chicagoZone);
DateTime californiaTime =
TimeZoneInfo.ConvertTimeFromUtc(
utcNow,
californiaZone);
if (newYorkClock != null)
newYorkClock.Update(newYorkTime);
if (chicagoClock != null)
chicagoClock.Update(chicagoTime);
if (californiaClock != null)
californiaClock.Update(californiaTime);
}
private void RemoveClockPanel()
{
if (clockTimer != null)
{
clockTimer.Stop();
clockTimer.Tick -= ClockTimer_Tick;
clockTimer = null;
}
if (mainPanel != null)
{
if (UserControlCollection.Contains(mainPanel))
UserControlCollection.Remove(mainPanel);
mainPanel = null;
}
newYorkClock = null;
chicagoClock = null;
californiaClock = null;
}
private double GetClockSize()
{
switch (SizePreset)
{
case WTClockSizePreset.Small:
return 110;
case WTClockSizePreset.Large:
return 185;
default:
return 145;
}
}
private double GetTitleFontSize()
{
switch (SizePreset)
{
case WTClockSizePreset.Small:
return 17;
case WTClockSizePreset.Large:
return 26;
default:
return 21;
}
}
private double GetFooterFontSize()
{
switch (SizePreset)
{
case WTClockSizePreset.Small:
return 9;
case WTClockSizePreset.Large:
return 12;
default:
return 10;
}
}
private SolidColorBrush MakeBrush(
Color color,
int opacityPercent)
{
int clampedOpacity =
Math.Max(0, Math.Min(100, opacityPercent));
byte alpha =
Convert.ToByte(clampedOpacity * 2.55);
return new SolidColorBrush(
Color.FromArgb(
alpha,
color.R,
color.G,
color.B));
}
private ThemePalette GetTheme()
{
switch (ColorTemplate)
{
case WTClockColorTemplate.MatrixGreen:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(4, 12, 7),
PanelBorder =
Color.FromRgb(28, 105, 52),
ClockBackground =
Color.FromRgb(3, 15, 8),
ClockOuterRing =
Color.FromRgb(30, 105, 55),
ClockInnerRing =
Color.FromRgb(18, 65, 35),
Accent =
Color.FromRgb(0, 255, 95),
HourHand =
Color.FromRgb(230, 255, 235),
MinuteHand =
Color.FromRgb(170, 255, 195),
MainText =
Color.FromRgb(235, 255, 240),
SecondaryText =
Color.FromRgb(105, 200, 130),
TitleText =
Color.FromRgb(0, 255, 95),
Divider =
Color.FromRgb(20, 80, 40)
};
case WTClockColorTemplate.ElectricBlue:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(5, 9, 18),
PanelBorder =
Color.FromRgb(35, 95, 175),
ClockBackground =
Color.FromRgb(5, 12, 25),
ClockOuterRing =
Color.FromRgb(40, 105, 190),
ClockInnerRing =
Color.FromRgb(25, 55, 100),
Accent =
Color.FromRgb(0, 170, 255),
HourHand =
Color.FromRgb(235, 245, 255),
MinuteHand =
Color.FromRgb(175, 220, 255),
MainText =
Color.FromRgb(235, 245, 255),
SecondaryText =
Color.FromRgb(105, 170, 225),
TitleText =
Color.FromRgb(45, 180, 255),
Divider =
Color.FromRgb(25, 65, 120)
};
case WTClockColorTemplate.Gold:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(15, 12, 5),
PanelBorder =
Color.FromRgb(145, 105, 25),
ClockBackground =
Color.FromRgb(18, 14, 5),
ClockOuterRing =
Color.FromRgb(155, 115, 30),
ClockInnerRing =
Color.FromRgb(80, 60, 20),
Accent =
Color.FromRgb(255, 185, 35),
HourHand =
Color.FromRgb(255, 250, 225),
MinuteHand =
Color.FromRgb(255, 220, 140),
MainText =
Color.FromRgb(255, 248, 220),
SecondaryText =
Color.FromRgb(200, 160, 75),
TitleText =
Color.FromRgb(255, 190, 45),
Divider =
Color.FromRgb(100, 75, 20)
};
case WTClockColorTemplate.Purple:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(12, 5, 18),
PanelBorder =
Color.FromRgb(105, 45, 155),
ClockBackground =
Color.FromRgb(15, 6, 23),
ClockOuterRing =
Color.FromRgb(120, 55, 175),
ClockInnerRing =
Color.FromRgb(65, 30, 95),
Accent =
Color.FromRgb(200, 75, 255),
HourHand =
Color.FromRgb(250, 235, 255),
MinuteHand =
Color.FromRgb(225, 175, 255),
MainText =
Color.FromRgb(250, 235, 255),
SecondaryText =
Color.FromRgb(175, 105, 210),
TitleText =
Color.FromRgb(215, 95, 255),
Divider =
Color.FromRgb(75, 35, 105)
};
default:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(7, 7, 9),
PanelBorder =
Color.FromRgb(75, 75, 82),
ClockBackground =
Color.FromRgb(14, 14, 17),
ClockOuterRing =
Color.FromRgb(75, 75, 82),
ClockInnerRing =
Color.FromRgb(42, 42, 48),
Accent =
Color.FromRgb(225, 45, 45),
HourHand =
Color.FromRgb(245, 245, 245),
MinuteHand =
Color.FromRgb(220, 220, 225),
MainText =
Color.FromRgb(245, 245, 245),
SecondaryText =
Color.FromRgb(145, 145, 155),
TitleText =
Color.FromRgb(255, 255, 255),
Divider =
Color.FromRgb(55, 55, 62)
};
}
}
#region Properties
[NinjaScriptProperty]
[Display(
Name = "Size Preset",
GroupName = "Appearance",
Order = 1)]
public WTClockSizePreset SizePreset { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Color Template",
GroupName = "Appearance",
Order = 2)]
public WTClockColorTemplate ColorTemplate { get; set; }
[NinjaScriptProperty]
[Range(20, 100)]
[Display(
Name = "Panel Opacity",
GroupName = "Appearance",
Order = 3)]
public int PanelOpacity { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Second Hand",
GroupName = "Display",
Order = 1)]
public bool ShowSecondHand { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Digital Time",
GroupName = "Display",
Order = 2)]
public bool ShowDigitalTime { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Date",
GroupName = "Display",
Order = 3)]
public bool ShowDate { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Footer",
GroupName = "Display",
Order = 4)]
public bool ShowFooter { get; set; }
#endregion
private class ThemePalette
{
public Color PanelBackground;
public Color PanelBorder;
public Color ClockBackground;
public Color ClockOuterRing;
public Color ClockInnerRing;
public Color Accent;
public Color HourHand;
public Color MinuteHand;
public Color MainText;
public Color SecondaryText;
public Color TitleText;
public Color Divider;
}
private class AnalogClock
{
public Border Root { get; private set; }
private readonly Canvas clockCanvas;
private readonly Line hourHand;
private readonly Line minuteHand;
private readonly Line secondHand;
private readonly TextBlock digitalTimeText;
private readonly TextBlock dateText;
private readonly ThemePalette theme;
private readonly double clockSize;
private readonly double center;
private readonly bool showSecondHand;
private readonly bool showDigitalTime;
private readonly bool showDate;
public AnalogClock(
string cityName,
string zoneName,
double requestedSize,
ThemePalette selectedTheme,
bool displaySecondHand,
bool displayDigitalTime,
bool displayDate)
{
clockSize = requestedSize;
center = clockSize / 2.0;
theme = selectedTheme;
showSecondHand = displaySecondHand;
showDigitalTime = displayDigitalTime;
showDate = displayDate;
double containerWidth = clockSize + 20;
StackPanel container = new StackPanel
{
Width = containerWidth,
Orientation = Orientation.Vertical,
HorizontalAlignment =
HorizontalAlignment.Center,
VerticalAlignment =
VerticalAlignment.Top,
Margin = new Thickness(5, 0, 5, 0)
};
clockCanvas = new Canvas
{
Width = clockSize,
Height = clockSize,
HorizontalAlignment =
HorizontalAlignment.Center,
VerticalAlignment =
VerticalAlignment.Top,
Background = Brushes.Transparent
};
DrawClockFace();
hourHand = CreateHand(
center * 0.48,
Math.Max(3.5, clockSize * 0.032),
new SolidColorBrush(theme.HourHand));
minuteHand = CreateHand(
center * 0.68,
Math.Max(2.2, clockSize * 0.021),
new SolidColorBrush(theme.MinuteHand));
secondHand = CreateHand(
center * 0.76,
Math.Max(1.2, clockSize * 0.011),
new SolidColorBrush(theme.Accent));
clockCanvas.Children.Add(hourHand);
clockCanvas.Children.Add(minuteHand);
if (showSecondHand)
clockCanvas.Children.Add(secondHand);
double pinSize =
Math.Max(9, clockSize * 0.075);
Ellipse centerPin = new Ellipse
{
Width = pinSize,
Height = pinSize,
Fill = new SolidColorBrush(theme.Accent),
Stroke =
new SolidColorBrush(
theme.ClockBackground),
StrokeThickness = 1
};
Canvas.SetLeft(
centerPin,
center - pinSize / 2.0);
Canvas.SetTop(
centerPin,
center - pinSize / 2.0);
clockCanvas.Children.Add(centerPin);
TextBlock cityText = new TextBlock
{
Text = cityName,
Foreground =
new SolidColorBrush(theme.MainText),
FontSize =
Math.Max(11, clockSize * 0.095),
FontWeight = FontWeights.Bold,
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 5, 0, 0)
};
TextBlock zoneText = new TextBlock
{
Text = zoneName,
Foreground =
new SolidColorBrush(theme.Accent),
FontSize =
Math.Max(10, clockSize * 0.08),
FontWeight = FontWeights.Bold,
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 0, 0, 1)
};
digitalTimeText = new TextBlock
{
Text = "--:--:-- --",
Foreground =
new SolidColorBrush(theme.MainText),
FontSize =
Math.Max(10, clockSize * 0.075),
FontWeight = FontWeights.SemiBold,
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin =
new Thickness(0, 2, 0, 0),
Visibility = showDigitalTime
? Visibility.Visible
: Visibility.Collapsed
};
dateText = new TextBlock
{
Text = "--- --- --",
Foreground =
new SolidColorBrush(
theme.SecondaryText),
FontSize =
Math.Max(9, clockSize * 0.065),
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin =
new Thickness(0, 1, 0, 3),
Visibility = showDate
? Visibility.Visible
: Visibility.Collapsed
};
container.Children.Add(clockCanvas);
container.Children.Add(cityText);
container.Children.Add(zoneText);
container.Children.Add(digitalTimeText);
container.Children.Add(dateText);
Root = new Border
{
Background = Brushes.Transparent,
Child = container
};
}
private void DrawClockFace()
{
Ellipse outerRing = new Ellipse
{
Width = clockSize - 4,
Height = clockSize - 4,
Stroke =
new SolidColorBrush(
theme.ClockOuterRing),
StrokeThickness =
Math.Max(3, clockSize * 0.025),
Fill =
new SolidColorBrush(
theme.ClockBackground)
};
Canvas.SetLeft(outerRing, 2);
Canvas.SetTop(outerRing, 2);
clockCanvas.Children.Add(outerRing);
Ellipse innerRing = new Ellipse
{
Width = clockSize - 14,
Height = clockSize - 14,
Stroke =
new SolidColorBrush(
theme.ClockInnerRing),
StrokeThickness = 1,
Fill = Brushes.Transparent
};
Canvas.SetLeft(innerRing, 7);
Canvas.SetTop(innerRing, 7);
clockCanvas.Children.Add(innerRing);
for (int minute = 0; minute < 60; minute++)
{
double angle =
minute * 6.0 * Math.PI / 180.0;
bool majorTick =
minute % 5 == 0;
double outsideRadius =
center - 10;
double insideRadius =
majorTick
? center - 22
: center - 16;
double x1 =
center +
Math.Sin(angle) *
insideRadius;
double y1 =
center -
Math.Cos(angle) *
insideRadius;
double x2 =
center +
Math.Sin(angle) *
outsideRadius;
double y2 =
center -
Math.Cos(angle) *
outsideRadius;
Line tick = new Line
{
X1 = x1,
Y1 = y1,
X2 = x2,
Y2 = y2,
StrokeThickness =
majorTick ? 2.2 : 1,
Stroke = majorTick
? new SolidColorBrush(
theme.Accent)
: new SolidColorBrush(
theme.SecondaryText)
};
clockCanvas.Children.Add(tick);
}
AddClockNumber(
"12",
center,
22);
AddClockNumber(
"3",
clockSize - 23,
center);
AddClockNumber(
"6",
center,
clockSize - 22);
AddClockNumber(
"9",
23,
center);
}
private void AddClockNumber(
string number,
double x,
double y)
{
double fontSize =
Math.Max(10, clockSize * 0.09);
TextBlock numberText = new TextBlock
{
Text = number,
Foreground =
new SolidColorBrush(theme.MainText),
FontSize = fontSize,
FontWeight = FontWeights.SemiBold,
Width = 32,
Height = 24,
TextAlignment = TextAlignment.Center
};
Canvas.SetLeft(
numberText,
x - 16);
Canvas.SetTop(
numberText,
y - 12);
clockCanvas.Children.Add(numberText);
}
private Line CreateHand(
double length,
double thickness,
Brush brush)
{
return new Line
{
X1 = center,
Y1 = center,
X2 = center,
Y2 = center - length,
Stroke = brush,
StrokeThickness = thickness,
StrokeStartLineCap =
PenLineCap.Round,
StrokeEndLineCap =
PenLineCap.Round
};
}
public void Update(DateTime time)
{
double secondValue =
time.Second +
time.Millisecond / 1000.0;
double minuteValue =
time.Minute +
secondValue / 60.0;
double hourValue =
time.Hour % 12 +
minuteValue / 60.0;
SetHandPosition(
hourHand,
hourValue * 30.0,
center * 0.48);
SetHandPosition(
minuteHand,
minuteValue * 6.0,
center * 0.68);
if (showSecondHand)
{
SetHandPosition(
secondHand,
secondValue * 6.0,
center * 0.76);
}
if (showDigitalTime)
{
digitalTimeText.Text =
time.ToString("hh:mm:ss tt");
}
if (showDate)
{
dateText.Text =
time.ToString("ddd MMM dd");
}
}
private void SetHandPosition(
Line hand,
double degrees,
double length)
{
double radians =
degrees * Math.PI / 180.0;
hand.X1 = center;
hand.Y1 = center;
hand.X2 =
center +
Math.Sin(radians) *
length;
hand.Y2 =
center -
Math.Cos(radians) *
length;
}
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private WizardTrendsWorldClocks cacheWizardTrendsWorldClocks;
public WizardTrendsWorldClocks WizardTrendsWorldClocks(WTClockSizePreset sizePreset, WTClockColorTemplate colorTemplate, int panelOpacity, bool showSecondHand, bool showDigitalTime, bool showDate, bool showFooter)
{
return WizardTrendsWorldClocks(Input, sizePreset, colorTemplate, panelOpacity, showSecondHand, showDigitalTime, showDate, showFooter);
}
public WizardTrendsWorldClocks WizardTrendsWorldClocks(ISeries<double> input, WTClockSizePreset sizePreset, WTClockColorTemplate colorTemplate, int panelOpacity, bool showSecondHand, bool showDigitalTime, bool showDate, bool showFooter)
{
if (cacheWizardTrendsWorldClocks != null)
for (int idx = 0; idx < cacheWizardTrendsWorldClocks.Length; idx++)
if (cacheWizardTrendsWorldClocks[idx] != null && cacheWizardTrendsWorldClocks[idx].SizePreset == sizePreset && cacheWizardTrendsWorldClocks[idx].ColorTemplate == colorTemplate && cacheWizardTrendsWorldClocks[idx].PanelOpacity == panelOpacity && cacheWizardTrendsWorldClocks[idx].ShowSecondHand == showSecondHand && cacheWizardTrendsWorldClocks[idx].ShowDigitalTime == showDigitalTime && cacheWizardTrendsWorldClocks[idx].ShowDate == showDate && cacheWizardTrendsWorldClocks[idx].ShowFooter == showFooter && cacheWizardTrendsWorldClocks[idx].EqualsInput(input))
return cacheWizardTrendsWorldClocks[idx];
return CacheIndicator<WizardTrendsWorldClocks>(new WizardTrendsWorldClocks(){ SizePreset = sizePreset, ColorTemplate = colorTemplate, PanelOpacity = panelOpacity, ShowSecondHand = showSecondHand, ShowDigitalTime = showDigitalTime, ShowDate = showDate, ShowFooter = showFooter }, input, ref cacheWizardTrendsWorldClocks);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.WizardTrendsWorldClocks WizardTrendsWorldClocks(WTClockSizePreset sizePreset, WTClockColorTemplate colorTemplate, int panelOpacity, bool showSecondHand, bool showDigitalTime, bool showDate, bool showFooter)
{
return indicator.WizardTrendsWorldClocks(Input, sizePreset, colorTemplate, panelOpacity, showSecondHand, showDigitalTime, showDate, showFooter);
}
public Indicators.WizardTrendsWorldClocks WizardTrendsWorldClocks(ISeries<double> input , WTClockSizePreset sizePreset, WTClockColorTemplate colorTemplate, int panelOpacity, bool showSecondHand, bool showDigitalTime, bool showDate, bool showFooter)
{
return indicator.WizardTrendsWorldClocks(input, sizePreset, colorTemplate, panelOpacity, showSecondHand, showDigitalTime, showDate, showFooter);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.WizardTrendsWorldClocks WizardTrendsWorldClocks(WTClockSizePreset sizePreset, WTClockColorTemplate colorTemplate, int panelOpacity, bool showSecondHand, bool showDigitalTime, bool showDate, bool showFooter)
{
return indicator.WizardTrendsWorldClocks(Input, sizePreset, colorTemplate, panelOpacity, showSecondHand, showDigitalTime, showDate, showFooter);
}
public Indicators.WizardTrendsWorldClocks WizardTrendsWorldClocks(ISeries<double> input , WTClockSizePreset sizePreset, WTClockColorTemplate colorTemplate, int panelOpacity, bool showSecondHand, bool showDigitalTime, bool showDate, bool showFooter)
{
return indicator.WizardTrendsWorldClocks(input, sizePreset, colorTemplate, panelOpacity, showSecondHand, showDigitalTime, showDate, showFooter);
}
}
}
#endregion
Impressive! . Excellent work. Thank you, Manny, for sharing this.
I took the liberty of adding a couple of improvements: a button to collapse/expand the panel, and some dropdown menus in the loading window to select the time zone for the clocks. I hope this is useful.
That’s great, adding an alarm would also be useful for Market opening and closing,
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using NinjaTrader.Cbi;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Core.FloatingPoint;
#endregion
using System.Windows.Controls;
using System.Windows.Threading;
using System.Windows.Shapes;
using static NinjaTrader.NinjaScript.Indicators.WizardTrendsWorldClocks;
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
#region class WTTimeZoneIdConverter
///
/// Provides a dropdown with every time zone installed on the system,
/// listed by Windows time zone Id (e.g. “Eastern Standard Time”).
///
public class WTTimeZoneIdConverter : TypeConverter
{
public override bool GetStandardValuesSupported(
ITypeDescriptorContext context)
{
return true;
}
public override bool GetStandardValuesExclusive(
ITypeDescriptorContext context)
{
return true;
}
public override StandardValuesCollection GetStandardValues(
ITypeDescriptorContext context)
{
List<string> ids =
TimeZoneInfo.GetSystemTimeZones()
.Select(tz => tz.Id)
.ToList();
return new StandardValuesCollection(ids);
}
}
#endregion
public class WizardTrendsWorldClocks : Indicator
{
#region Enumerations
public enum WTClockSizePreset
{
Small,
Medium,
Large,
}
public enum WTClockColorTemplate
{
ClassicRed,
MatrixGreen,
ElectricBlue,
Gold,
Purple
}
#endregion
#region class ThemePalette
private class ThemePalette
{
public Color PanelBackground;
public Color PanelBorder;
public Color ClockBackground;
public Color ClockOuterRing;
public Color ClockInnerRing;
public Color Accent;
public Color HourHand;
public Color MinuteHand;
public Color MainText;
public Color SecondaryText;
public Color TitleText;
public Color Divider;
}
#endregion
#region class AnalogClock
private class AnalogClock
{
public Border Root { get; private set; }
private readonly Canvas clockCanvas;
private readonly Line hourHand;
private readonly Line minuteHand;
private readonly Line secondHand;
private readonly TextBlock digitalTimeText;
private readonly TextBlock dateText;
private readonly ThemePalette theme;
private readonly double clockSize;
private readonly double center;
private readonly bool showSecondHand;
private readonly bool showDigitalTime;
private readonly bool showDate;
public AnalogClock(
string cityName,
string zoneName,
double requestedSize,
ThemePalette selectedTheme,
bool displaySecondHand,
bool displayDigitalTime,
bool displayDate)
{
clockSize = requestedSize;
center = clockSize / 2.0;
theme = selectedTheme;
showSecondHand = displaySecondHand;
showDigitalTime = displayDigitalTime;
showDate = displayDate;
double containerWidth = clockSize + 20;
StackPanel container = new StackPanel
{
Width = containerWidth,
Orientation = Orientation.Vertical,
HorizontalAlignment =
HorizontalAlignment.Center,
VerticalAlignment =
VerticalAlignment.Top,
Margin = new Thickness(5, 0, 5, 0)
};
clockCanvas = new Canvas
{
Width = clockSize,
Height = clockSize,
HorizontalAlignment =
HorizontalAlignment.Center,
VerticalAlignment =
VerticalAlignment.Top,
Background = Brushes.Transparent
};
DrawClockFace();
hourHand = CreateHand(
center * 0.48,
Math.Max(3.5, clockSize * 0.032),
new SolidColorBrush(theme.HourHand));
minuteHand = CreateHand(
center * 0.68,
Math.Max(2.2, clockSize * 0.021),
new SolidColorBrush(theme.MinuteHand));
secondHand = CreateHand(
center * 0.76,
Math.Max(1.2, clockSize * 0.011),
new SolidColorBrush(theme.Accent));
clockCanvas.Children.Add(hourHand);
clockCanvas.Children.Add(minuteHand);
if (showSecondHand)
clockCanvas.Children.Add(secondHand);
double pinSize =
Math.Max(9, clockSize * 0.075);
Ellipse centerPin = new Ellipse
{
Width = pinSize,
Height = pinSize,
Fill = new SolidColorBrush(theme.Accent),
Stroke =
new SolidColorBrush(
theme.ClockBackground),
StrokeThickness = 1
};
Canvas.SetLeft(
centerPin,
center - pinSize / 2.0);
Canvas.SetTop(
centerPin,
center - pinSize / 2.0);
clockCanvas.Children.Add(centerPin);
TextBlock cityText = new TextBlock
{
Text = cityName,
Foreground =
new SolidColorBrush(theme.MainText),
FontSize =
Math.Max(11, clockSize * 0.095),
FontWeight = FontWeights.Bold,
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 5, 0, 0)
};
TextBlock zoneText = new TextBlock
{
Text = zoneName,
Foreground =
new SolidColorBrush(theme.Accent),
FontSize =
Math.Max(10, clockSize * 0.08),
FontWeight = FontWeights.Bold,
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 0, 0, 1)
};
digitalTimeText = new TextBlock
{
Text = "--:--:-- --",
Foreground =
new SolidColorBrush(theme.MainText),
FontSize =
Math.Max(10, clockSize * 0.075),
FontWeight = FontWeights.SemiBold,
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin =
new Thickness(0, 2, 0, 0),
Visibility = showDigitalTime
? Visibility.Visible
: Visibility.Collapsed
};
dateText = new TextBlock
{
Text = "--- --- --",
Foreground =
new SolidColorBrush(
theme.SecondaryText),
FontSize =
Math.Max(9, clockSize * 0.065),
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin =
new Thickness(0, 1, 0, 3),
Visibility = showDate
? Visibility.Visible
: Visibility.Collapsed
};
container.Children.Add(clockCanvas);
container.Children.Add(cityText);
container.Children.Add(zoneText);
container.Children.Add(digitalTimeText);
container.Children.Add(dateText);
Root = new Border
{
Background = Brushes.Transparent,
Child = container
};
}
private void DrawClockFace()
{
Ellipse outerRing = new Ellipse
{
Width = clockSize - 4,
Height = clockSize - 4,
Stroke =
new SolidColorBrush(
theme.ClockOuterRing),
StrokeThickness =
Math.Max(3, clockSize * 0.025),
Fill =
new SolidColorBrush(
theme.ClockBackground)
};
Canvas.SetLeft(outerRing, 2);
Canvas.SetTop(outerRing, 2);
clockCanvas.Children.Add(outerRing);
Ellipse innerRing = new Ellipse
{
Width = clockSize - 14,
Height = clockSize - 14,
Stroke =
new SolidColorBrush(
theme.ClockInnerRing),
StrokeThickness = 1,
Fill = Brushes.Transparent
};
Canvas.SetLeft(innerRing, 7);
Canvas.SetTop(innerRing, 7);
clockCanvas.Children.Add(innerRing);
for (int minute = 0; minute < 60; minute++)
{
double angle =
minute * 6.0 * Math.PI / 180.0;
bool majorTick =
minute % 5 == 0;
double outsideRadius =
center - 10;
double insideRadius =
majorTick
? center - 22
: center - 16;
double x1 =
center +
Math.Sin(angle) *
insideRadius;
double y1 =
center -
Math.Cos(angle) *
insideRadius;
double x2 =
center +
Math.Sin(angle) *
outsideRadius;
double y2 =
center -
Math.Cos(angle) *
outsideRadius;
Line tick = new Line
{
X1 = x1,
Y1 = y1,
X2 = x2,
Y2 = y2,
StrokeThickness =
majorTick ? 2.2 : 1,
Stroke = majorTick
? new SolidColorBrush(
theme.Accent)
: new SolidColorBrush(
theme.SecondaryText)
};
clockCanvas.Children.Add(tick);
}
AddClockNumber(
"12",
center,
22);
AddClockNumber(
"3",
clockSize - 23,
center);
AddClockNumber(
"6",
center,
clockSize - 22);
AddClockNumber(
"9",
23,
center);
}
private void AddClockNumber(
string number,
double x,
double y)
{
double fontSize =
Math.Max(10, clockSize * 0.09);
TextBlock numberText = new TextBlock
{
Text = number,
Foreground =
new SolidColorBrush(theme.MainText),
FontSize = fontSize,
FontWeight = FontWeights.SemiBold,
Width = 32,
Height = 24,
TextAlignment = TextAlignment.Center
};
Canvas.SetLeft(
numberText,
x - 16);
Canvas.SetTop(
numberText,
y - 12);
clockCanvas.Children.Add(numberText);
}
private Line CreateHand(
double length,
double thickness,
Brush brush)
{
return new Line
{
X1 = center,
Y1 = center,
X2 = center,
Y2 = center - length,
Stroke = brush,
StrokeThickness = thickness,
StrokeStartLineCap =
PenLineCap.Round,
StrokeEndLineCap =
PenLineCap.Round
};
}
public void Update(DateTime time)
{
double secondValue =
time.Second +
time.Millisecond / 1000.0;
double minuteValue =
time.Minute +
secondValue / 60.0;
double hourValue =
time.Hour % 12 +
minuteValue / 60.0;
SetHandPosition(
hourHand,
hourValue * 30.0,
center * 0.48);
SetHandPosition(
minuteHand,
minuteValue * 6.0,
center * 0.68);
if (showSecondHand)
{
SetHandPosition(
secondHand,
secondValue * 6.0,
center * 0.76);
}
if (showDigitalTime)
{
digitalTimeText.Text =
time.ToString("hh:mm:ss tt");
}
if (showDate)
{
dateText.Text =
time.ToString("ddd MMM dd");
}
}
private void SetHandPosition(
Line hand,
double degrees,
double length)
{
double radians =
degrees * Math.PI / 180.0;
hand.X1 = center;
hand.Y1 = center;
hand.X2 =
center +
Math.Sin(radians) *
length;
hand.Y2 =
center -
Math.Cos(radians) *
length;
}
}
#endregion
#region Properties
[NinjaScriptProperty]
[Display(
Name = "Size Preset",
GroupName = "Appearance",
Order = 1)]
public WTClockSizePreset SizePreset { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Color Template",
GroupName = "Appearance",
Order = 2)]
public WTClockColorTemplate ColorTemplate { get; set; }
[NinjaScriptProperty]
[Range(20, 100)]
[Display(
Name = "Panel Opacity",
GroupName = "Appearance",
Order = 3)]
public int PanelOpacity { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Second Hand",
GroupName = "Display",
Order = 1)]
public bool ShowSecondHand { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Digital Time",
GroupName = "Display",
Order = 2)]
public bool ShowDigitalTime { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Date",
GroupName = "Display",
Order = 3)]
public bool ShowDate { get; set; }
[NinjaScriptProperty]
[Display(
Name = "Show Footer",
GroupName = "Display",
Order = 4)]
public bool ShowFooter { get; set; }
[TypeConverter(typeof(WTTimeZoneIdConverter))]
[Display(
Name = "Clock 1 Time Zone",
GroupName = "Time Zones",
Order = 1)]
public string Clock1TimeZoneId { get; set; }
[TypeConverter(typeof(WTTimeZoneIdConverter))]
[Display(
Name = "Clock 2 Time Zone",
GroupName = "Time Zones",
Order = 2)]
public string Clock2TimeZoneId { get; set; }
[TypeConverter(typeof(WTTimeZoneIdConverter))]
[Display(
Name = "Clock 3 Time Zone",
GroupName = "Time Zones",
Order = 3)]
public string Clock3TimeZoneId { get; set; }
[Display(
Name = "Clock 1 Label",
Description = "Leave empty to derive the label from the time zone.",
GroupName = "Time Zones",
Order = 4)]
public string Clock1Label { get; set; }
[Display(
Name = "Clock 2 Label",
Description = "Leave empty to derive the label from the time zone.",
GroupName = "Time Zones",
Order = 5)]
public string Clock2Label { get; set; }
[Display(
Name = "Clock 3 Label",
Description = "Leave empty to derive the label from the time zone.",
GroupName = "Time Zones",
Order = 6)]
public string Clock3Label { get; set; }
/// <summary>
/// Runtime collapsed state. Hidden from the property grid but
/// serialized, so it survives workspace reloads.
/// </summary>
[Browsable(false)]
public bool PanelStartsCollapsed { get; set; }
#endregion
private Grid mainPanel;
private DispatcherTimer clockTimer;
private Border expandedBorder;
private Border collapseButton;
private Border expandButton;
private bool isCollapsed;
#region OnStateChange
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "WizardTrendsWorldClocks";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
SizePreset = WTClockSizePreset.Medium;
ColorTemplate = WTClockColorTemplate.ClassicRed;
PanelOpacity = 96;
ShowSecondHand = true;
ShowDigitalTime = true;
ShowDate = true;
ShowFooter = true;
Clock1TimeZoneId = "Eastern Standard Time";
Clock2TimeZoneId = "Central Standard Time";
Clock3TimeZoneId = "Pacific Standard Time";
Clock1Label = "NEW YORK";
Clock2Label = "CHICAGO";
Clock3Label = "CALIFORNIA";
PanelStartsCollapsed = false;
}
else if (State == State.DataLoaded)
{
LoadTimeZones();
if (ChartControl != null)
ChartControl.Dispatcher.InvokeAsync(CreateClockPanel);
}
else if (State == State.Terminated)
{
if (ChartControl != null)
ChartControl.Dispatcher.InvokeAsync(RemoveClockPanel);
}
}
#endregion
private AnalogClock newYorkClock;
private AnalogClock chicagoClock;
private AnalogClock californiaClock;
private TimeZoneInfo newYorkZone;
private TimeZoneInfo chicagoZone;
private TimeZoneInfo californiaZone;
private ThemePalette activeTheme;
private double activeClockSize;
protected override void OnBarUpdate()
{
}
#region LoadTimeZones
private void LoadTimeZones()
{
newYorkZone = ResolveTimeZone(Clock1TimeZoneId);
chicagoZone = ResolveTimeZone(Clock2TimeZoneId);
californiaZone = ResolveTimeZone(Clock3TimeZoneId);
}
private TimeZoneInfo ResolveTimeZone(string timeZoneId)
{
try
{
return TimeZoneInfo.FindSystemTimeZoneById(timeZoneId);
}
catch
{
return TimeZoneInfo.Local;
}
}
private string GetZoneShortName(TimeZoneInfo zone)
{
TimeSpan offset = zone.GetUtcOffset(DateTime.UtcNow);
string sign = offset < TimeSpan.Zero ? "-" : "+";
offset = offset.Duration();
return offset.Minutes == 0
? string.Format("UTC{0}{1}", sign, offset.Hours)
: string.Format(
"UTC{0}{1}:{2:00}",
sign,
offset.Hours,
offset.Minutes);
}
private string GetClockLabel(string userLabel, TimeZoneInfo zone)
{
if (!string.IsNullOrWhiteSpace(userLabel))
return userLabel;
return zone.Id
.Replace(" Standard Time", string.Empty)
.ToUpperInvariant();
}
#endregion
#region CreateClockPanel
private void CreateClockPanel()
{
RemoveClockPanel();
activeClockSize = GetClockSize();
activeTheme = GetTheme();
isCollapsed = PanelStartsCollapsed;
double panelWidth = activeClockSize * 3.0 + 95.0;
// Background = null: the empty area of the grid does not
// hit-test, so only the toggle buttons capture the mouse and
// the rest of the panel stays click-through for the chart.
mainPanel = new Grid
{
HorizontalAlignment = HorizontalAlignment.Right,
VerticalAlignment = VerticalAlignment.Top,
Margin = new Thickness(10),
Background = null,
IsHitTestVisible = true
};
expandedBorder = new Border
{
Width = panelWidth,
Background = MakeBrush(
activeTheme.PanelBackground,
PanelOpacity),
BorderBrush =
new SolidColorBrush(activeTheme.PanelBorder),
BorderThickness = new Thickness(1),
CornerRadius = new CornerRadius(10),
Padding = new Thickness(12, 10, 12, 10),
Child = BuildPanelContent(),
IsHitTestVisible = false
};
collapseButton = BuildToggleButton(
BuildArrowNEIcon(),
"Collapse panel");
collapseButton.HorizontalAlignment =
HorizontalAlignment.Left;
collapseButton.VerticalAlignment =
VerticalAlignment.Bottom;
collapseButton.Margin = new Thickness(5, 0, 0, 5);
collapseButton.MouseLeftButtonDown +=
CollapseButton_MouseLeftButtonDown;
expandButton = BuildToggleButton(
BuildClockIcon(),
"Expand world clocks");
expandButton.HorizontalAlignment =
HorizontalAlignment.Right;
expandButton.VerticalAlignment =
VerticalAlignment.Top;
expandButton.MouseLeftButtonDown +=
ExpandButton_MouseLeftButtonDown;
mainPanel.Children.Add(expandedBorder);
mainPanel.Children.Add(collapseButton);
mainPanel.Children.Add(expandButton);
UserControlCollection.Add(mainPanel);
clockTimer = new DispatcherTimer
{
Interval = TimeSpan.FromMilliseconds(200)
};
clockTimer.Tick += ClockTimer_Tick;
ApplyCollapsedState();
UpdateClocks();
}
private void CollapseButton_MouseLeftButtonDown(
object sender,
MouseButtonEventArgs e)
{
e.Handled = true;
SetCollapsed(true);
}
private void ExpandButton_MouseLeftButtonDown(
object sender,
MouseButtonEventArgs e)
{
e.Handled = true;
SetCollapsed(false);
}
private void SetCollapsed(bool collapsed)
{
isCollapsed = collapsed;
// Persisted with the workspace so the panel reopens in the
// same state after a reload.
PanelStartsCollapsed = collapsed;
ApplyCollapsedState();
}
private void ApplyCollapsedState()
{
if (mainPanel == null)
return;
expandedBorder.Visibility = isCollapsed
? Visibility.Collapsed
: Visibility.Visible;
collapseButton.Visibility = isCollapsed
? Visibility.Collapsed
: Visibility.Visible;
expandButton.Visibility = isCollapsed
? Visibility.Visible
: Visibility.Collapsed;
if (clockTimer == null)
return;
// No need to animate hands nobody can see.
if (isCollapsed)
{
clockTimer.Stop();
}
else
{
UpdateClocks();
clockTimer.Start();
}
}
private Border BuildToggleButton(
UIElement icon,
string tooltip)
{
return new Border
{
Width = 26,
Height = 26,
CornerRadius = new CornerRadius(6),
Background = MakeBrush(
activeTheme.PanelBackground,
Math.Max(PanelOpacity, 85)),
BorderBrush =
new SolidColorBrush(activeTheme.PanelBorder),
BorderThickness = new Thickness(1),
Child = icon,
Cursor = Cursors.Hand,
ToolTip = tooltip,
IsHitTestVisible = true
};
}
private UIElement BuildArrowNEIcon()
{
return new System.Windows.Shapes.Path
{
Data = Geometry.Parse(
"M 4,12 L 12,4 M 12,4 L 7,4 M 12,4 L 12,9"),
Stroke =
new SolidColorBrush(activeTheme.Accent),
StrokeThickness = 2,
StrokeStartLineCap = PenLineCap.Round,
StrokeEndLineCap = PenLineCap.Round,
Width = 16,
Height = 16,
HorizontalAlignment =
HorizontalAlignment.Center,
VerticalAlignment =
VerticalAlignment.Center
};
}
private UIElement BuildClockIcon()
{
Canvas canvas = new Canvas
{
Width = 16,
Height = 16,
HorizontalAlignment =
HorizontalAlignment.Center,
VerticalAlignment =
VerticalAlignment.Center
};
Ellipse face = new Ellipse
{
Width = 15,
Height = 15,
Stroke =
new SolidColorBrush(activeTheme.Accent),
StrokeThickness = 1.6,
Fill = Brushes.Transparent
};
Canvas.SetLeft(face, 0.5);
Canvas.SetTop(face, 0.5);
Line hourHandIcon = new Line
{
X1 = 8,
Y1 = 8,
X2 = 8,
Y2 = 4.5,
Stroke =
new SolidColorBrush(activeTheme.HourHand),
StrokeThickness = 1.6,
StrokeEndLineCap = PenLineCap.Round
};
Line minuteHandIcon = new Line
{
X1 = 8,
Y1 = 8,
X2 = 11,
Y2 = 9.5,
Stroke =
new SolidColorBrush(activeTheme.HourHand),
StrokeThickness = 1.6,
StrokeEndLineCap = PenLineCap.Round
};
canvas.Children.Add(face);
canvas.Children.Add(hourHandIcon);
canvas.Children.Add(minuteHandIcon);
return canvas;
}
#endregion
#region BuildPanelContent
private UIElement BuildPanelContent()
{
StackPanel mainStack = new StackPanel
{
Orientation = Orientation.Vertical,
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Top
};
TextBlock title = new TextBlock
{
Text = "WIZARD TRENDS",
Foreground =
new SolidColorBrush(activeTheme.TitleText),
FontSize = GetTitleFontSize(),
FontWeight = FontWeights.Bold,
HorizontalAlignment = HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 0, 0, 8)
};
mainStack.Children.Add(title);
StackPanel clocksRow = new StackPanel
{
Orientation = Orientation.Horizontal,
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top
};
newYorkClock = new AnalogClock(
GetClockLabel(Clock1Label, newYorkZone),
GetZoneShortName(newYorkZone),
activeClockSize,
activeTheme,
ShowSecondHand,
ShowDigitalTime,
ShowDate);
chicagoClock = new AnalogClock(
GetClockLabel(Clock2Label, chicagoZone),
GetZoneShortName(chicagoZone),
activeClockSize,
activeTheme,
ShowSecondHand,
ShowDigitalTime,
ShowDate);
californiaClock = new AnalogClock(
GetClockLabel(Clock3Label, californiaZone),
GetZoneShortName(californiaZone),
activeClockSize,
activeTheme,
ShowSecondHand,
ShowDigitalTime,
ShowDate);
clocksRow.Children.Add(newYorkClock.Root);
clocksRow.Children.Add(chicagoClock.Root);
clocksRow.Children.Add(californiaClock.Root);
mainStack.Children.Add(clocksRow);
if (ShowFooter)
{
Border footerDivider = new Border
{
Height = 1,
Background =
new SolidColorBrush(activeTheme.Divider),
Margin = new Thickness(10, 8, 10, 5)
};
mainStack.Children.Add(footerDivider);
TextBlock footer = new TextBlock
{
Text = "Trading Sessions • Live Market Time",
Foreground =
new SolidColorBrush(
activeTheme.SecondaryText),
FontSize = GetFooterFontSize(),
HorizontalAlignment =
HorizontalAlignment.Center,
TextAlignment = TextAlignment.Center,
Margin = new Thickness(0, 0, 0, 1)
};
mainStack.Children.Add(footer);
}
return mainStack;
}
#endregion
private void ClockTimer_Tick(object sender, EventArgs e)
{
UpdateClocks();
}
#region UpdateClocks
private void UpdateClocks()
{
DateTime utcNow = DateTime.UtcNow;
DateTime newYorkTime =
TimeZoneInfo.ConvertTimeFromUtc(
utcNow,
newYorkZone);
DateTime chicagoTime =
TimeZoneInfo.ConvertTimeFromUtc(
utcNow,
chicagoZone);
DateTime californiaTime =
TimeZoneInfo.ConvertTimeFromUtc(
utcNow,
californiaZone);
if (newYorkClock != null)
newYorkClock.Update(newYorkTime);
if (chicagoClock != null)
chicagoClock.Update(chicagoTime);
if (californiaClock != null)
californiaClock.Update(californiaTime);
}
#endregion
#region RemoveClockPanel
private void RemoveClockPanel()
{
if (clockTimer != null)
{
clockTimer.Stop();
clockTimer.Tick -= ClockTimer_Tick;
clockTimer = null;
}
if (collapseButton != null)
{
collapseButton.MouseLeftButtonDown -=
CollapseButton_MouseLeftButtonDown;
collapseButton = null;
}
if (expandButton != null)
{
expandButton.MouseLeftButtonDown -=
ExpandButton_MouseLeftButtonDown;
expandButton = null;
}
expandedBorder = null;
if (mainPanel != null)
{
if (UserControlCollection.Contains(mainPanel))
UserControlCollection.Remove(mainPanel);
mainPanel = null;
}
newYorkClock = null;
chicagoClock = null;
californiaClock = null;
}
#endregion
#region GetClockSize
private double GetClockSize()
{
switch (SizePreset)
{
case WTClockSizePreset.Small:
return 110;
case WTClockSizePreset.Large:
return 185;
default:
return 145;
}
}
#endregion
private double GetTitleFontSize()
{
switch (SizePreset)
{
case WTClockSizePreset.Small:
return 17;
case WTClockSizePreset.Large:
return 26;
default:
return 21;
}
}
private double GetFooterFontSize()
{
switch (SizePreset)
{
case WTClockSizePreset.Small:
return 9;
case WTClockSizePreset.Large:
return 12;
default:
return 10;
}
}
private SolidColorBrush MakeBrush(
Color color,
int opacityPercent)
{
int clampedOpacity =
Math.Max(0, Math.Min(100, opacityPercent));
byte alpha =
Convert.ToByte(clampedOpacity * 2.55);
return new SolidColorBrush(
Color.FromArgb(
alpha,
color.R,
color.G,
color.B));
}
private ThemePalette GetTheme()
{
switch (ColorTemplate)
{
case WTClockColorTemplate.MatrixGreen:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(4, 12, 7),
PanelBorder =
Color.FromRgb(28, 105, 52),
ClockBackground =
Color.FromRgb(3, 15, 8),
ClockOuterRing =
Color.FromRgb(30, 105, 55),
ClockInnerRing =
Color.FromRgb(18, 65, 35),
Accent =
Color.FromRgb(0, 255, 95),
HourHand =
Color.FromRgb(230, 255, 235),
MinuteHand =
Color.FromRgb(170, 255, 195),
MainText =
Color.FromRgb(235, 255, 240),
SecondaryText =
Color.FromRgb(105, 200, 130),
TitleText =
Color.FromRgb(0, 255, 95),
Divider =
Color.FromRgb(20, 80, 40)
};
case WTClockColorTemplate.ElectricBlue:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(5, 9, 18),
PanelBorder =
Color.FromRgb(35, 95, 175),
ClockBackground =
Color.FromRgb(5, 12, 25),
ClockOuterRing =
Color.FromRgb(40, 105, 190),
ClockInnerRing =
Color.FromRgb(25, 55, 100),
Accent =
Color.FromRgb(0, 170, 255),
HourHand =
Color.FromRgb(235, 245, 255),
MinuteHand =
Color.FromRgb(175, 220, 255),
MainText =
Color.FromRgb(235, 245, 255),
SecondaryText =
Color.FromRgb(105, 170, 225),
TitleText =
Color.FromRgb(45, 180, 255),
Divider =
Color.FromRgb(25, 65, 120)
};
case WTClockColorTemplate.Gold:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(15, 12, 5),
PanelBorder =
Color.FromRgb(145, 105, 25),
ClockBackground =
Color.FromRgb(18, 14, 5),
ClockOuterRing =
Color.FromRgb(155, 115, 30),
ClockInnerRing =
Color.FromRgb(80, 60, 20),
Accent =
Color.FromRgb(255, 185, 35),
HourHand =
Color.FromRgb(255, 250, 225),
MinuteHand =
Color.FromRgb(255, 220, 140),
MainText =
Color.FromRgb(255, 248, 220),
SecondaryText =
Color.FromRgb(200, 160, 75),
TitleText =
Color.FromRgb(255, 190, 45),
Divider =
Color.FromRgb(100, 75, 20)
};
case WTClockColorTemplate.Purple:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(12, 5, 18),
PanelBorder =
Color.FromRgb(105, 45, 155),
ClockBackground =
Color.FromRgb(15, 6, 23),
ClockOuterRing =
Color.FromRgb(120, 55, 175),
ClockInnerRing =
Color.FromRgb(65, 30, 95),
Accent =
Color.FromRgb(200, 75, 255),
HourHand =
Color.FromRgb(250, 235, 255),
MinuteHand =
Color.FromRgb(225, 175, 255),
MainText =
Color.FromRgb(250, 235, 255),
SecondaryText =
Color.FromRgb(175, 105, 210),
TitleText =
Color.FromRgb(215, 95, 255),
Divider =
Color.FromRgb(75, 35, 105)
};
default:
return new ThemePalette
{
PanelBackground =
Color.FromRgb(7, 7, 9),
PanelBorder =
Color.FromRgb(75, 75, 82),
ClockBackground =
Color.FromRgb(14, 14, 17),
ClockOuterRing =
Color.FromRgb(75, 75, 82),
ClockInnerRing =
Color.FromRgb(42, 42, 48),
Accent =
Color.FromRgb(225, 45, 45),
HourHand =
Color.FromRgb(245, 245, 245),
MinuteHand =
Color.FromRgb(220, 220, 225),
MainText =
Color.FromRgb(245, 245, 245),
SecondaryText =
Color.FromRgb(145, 145, 155),
TitleText =
Color.FromRgb(255, 255, 255),
Divider =
Color.FromRgb(55, 55, 62)
};
}
}
}
}
It’s a shame that files can’t be uploaded. I had to split the entire code into two parts because it wouldn’t fit in a single post either.
Yes, I feel the same way, we have to upload in sections lol
Hopefully everyone reading this is old enough to be able to read an analog clock!

