using System.Drawing; using System.Runtime.CompilerServices; using TradingPlatform.BusinessLayer; namespace QuanTAlib; [SkipLocalsInit] public sealed class UiIndicator : Indicator, IWatchlistIndicator { [InputParameter("Period", sortIndex: 1, 1, 200, 1, 0)] public int Period { get; set; } = 14; [InputParameter("Show cold values", sortIndex: 21)] public bool ShowColdValues { get; set; } = true; private Ui _ui = null!; private readonly LineSeries _series; public static int MinHistoryDepths => 0; int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths; public override string ShortName => $"UI({Period})"; public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/volatility/ui/Ui.Quantower.cs"; public UiIndicator() { OnBackGround = true; SeparateWindow = true; Name = "UI - Ulcer Index"; Description = "Ulcer Index measures downside volatility by calculating the root mean square of percentage drawdowns from recent highs"; _series = new LineSeries(name: "UI", color: IndicatorExtensions.Volatility, width: 2, style: LineStyle.Solid); AddLineSeries(_series); } protected override void OnInit() { _ui = new Ui(Period); base.OnInit(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override void OnUpdate(UpdateArgs args) { TBar bar = this.GetInputBar(args); TValue result = _ui.Update(bar, isNew: args.IsNewBar()); _series.SetValue(result.Value, _ui.IsHot, ShowColdValues); } }