Refactor IndicatorExtensions: Remove unused methods and optimize price retrieval

This commit is contained in:
Miha Kralj
2025-12-24 13:50:19 -08:00
parent c47b106597
commit 8917575994
101 changed files with 1311 additions and 450292 deletions
+11 -14
View File
@@ -1,9 +1,11 @@
using System.Drawing;
using System.Runtime.CompilerServices;
using TradingPlatform.BusinessLayer;
namespace QuanTAlib;
public class AdoscIndicator : Indicator, IWatchlistIndicator
[SkipLocalsInit]
public sealed class AdoscIndicator : Indicator, IWatchlistIndicator
{
[InputParameter("Fast Period", sortIndex: 1, 1, 1000, 1, 0)]
public int FastPeriod { get; set; } = 3;
@@ -15,9 +17,9 @@ public class AdoscIndicator : Indicator, IWatchlistIndicator
public bool ShowColdValues { get; set; } = true;
private Adosc? _adosc;
protected LineSeries? Series;
private readonly LineSeries? _series;
public int MinHistoryDepths => SlowPeriod;
public static int MinHistoryDepths => 0;
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
public override string ShortName => $"ADOSC {FastPeriod}:{SlowPeriod}";
@@ -30,28 +32,23 @@ public class AdoscIndicator : Indicator, IWatchlistIndicator
Name = "ADOSC - Accumulation/Distribution Oscillator";
Description = "Momentum indicator for the Accumulation/Distribution Line";
Series = new(name: "ADOSC", color: Color.Orange, width: 2, style: LineStyle.Solid);
AddLineSeries(Series);
_series = new(name: "ADOSC", color: Color.Orange, width: 2, style: LineStyle.Solid);
AddLineSeries(_series);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnInit()
{
_adosc = new Adosc(FastPeriod, SlowPeriod);
base.OnInit();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected override void OnUpdate(UpdateArgs args)
{
bool isNew = args.Reason == UpdateReason.NewBar || args.Reason == UpdateReason.HistoricalBar;
TBar bar = this.GetInputBar(args);
TValue result = _adosc!.Update(bar, isNew);
TValue result = _adosc!.Update(bar, args.IsNewBar());
if (!_adosc.IsHot && !ShowColdValues)
{
return;
}
Series!.SetValue(result.Value);
_series!.SetValue(result.Value, _adosc.IsHot, ShowColdValues);
}
}