mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-20 19:48:05 +00:00
Refactor IndicatorExtensions: Remove unused methods and optimize price retrieval
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user