using System.Drawing; using System.Runtime.CompilerServices; using TradingPlatform.BusinessLayer; namespace QuanTAlib; [SkipLocalsInit] public sealed class CtiIndicator : Indicator, IWatchlistIndicator { [InputParameter("Period", sortIndex: 1, 2, 1000, 1, 0)] public int Period { get; set; } = 20; [IndicatorExtensions.DataSourceInput(sortIndex: 2)] public SourceType Source { get; set; } = SourceType.Close; [InputParameter("Show cold values", sortIndex: 21)] public bool ShowColdValues { get; set; } = true; private Cti _cti = null!; private readonly LineSeries _series; public static int MinHistoryDepths => 0; int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths; public override string ShortName => $"CTI ({Period})"; public override string SourceCodeLink => "https://github.com/mihakralj/QuanTAlib/blob/main/lib/oscillators/cti/Cti.Quantower.cs"; public CtiIndicator() { OnBackGround = true; SeparateWindow = true; Name = "CTI - Ehlers Correlation Trend Indicator"; Description = "Pearson correlation between price and a perfect linear time index"; _series = new LineSeries("CTI", Color.Yellow, 2, LineStyle.Solid); AddLineSeries(_series); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override void OnInit() { _cti = new Cti(Period); base.OnInit(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] protected override void OnUpdate(UpdateArgs args) { var priceSelector = Source.GetPriceSelector(); var item = HistoricalData[0, SeekOriginHistory.End]; double price = priceSelector(item); TValue input = new(item.TimeLeft, price); TValue result = _cti.Update(input, args.IsNewBar()); if (!_cti.IsHot && !ShowColdValues) { return; } _series.SetValue(result.Value); } }