mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-17 18:18:04 +00:00
Refactor IndicatorExtensions: Remove unused methods and optimize price retrieval
This commit is contained in:
@@ -25,12 +25,12 @@ public class AdlIndicatorTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AdlIndicator_SourceCodeLink_IsValid()
|
||||
public void AdlIndicator_MinHistoryDepths_EqualsZero()
|
||||
{
|
||||
var indicator = new AdlIndicator();
|
||||
|
||||
Assert.Contains("github.com", indicator.SourceCodeLink);
|
||||
Assert.Contains("Adl.Quantower.cs", indicator.SourceCodeLink);
|
||||
Assert.Equal(0, AdlIndicator.MinHistoryDepths);
|
||||
Assert.Equal(0, ((IWatchlistIndicator)indicator).MinHistoryDepths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
using System.Drawing;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TradingPlatform.BusinessLayer;
|
||||
|
||||
namespace QuanTAlib;
|
||||
|
||||
public class AdlIndicator : Indicator, IWatchlistIndicator
|
||||
[SkipLocalsInit]
|
||||
public sealed class AdlIndicator : Indicator, IWatchlistIndicator
|
||||
{
|
||||
[InputParameter("Show cold values", sortIndex: 21)]
|
||||
public bool ShowColdValues { get; set; } = true;
|
||||
|
||||
private Adl? _adl;
|
||||
protected LineSeries? AdlSeries;
|
||||
private readonly LineSeries? _series;
|
||||
|
||||
public static int MinHistoryDepths => 0;
|
||||
int IWatchlistIndicator.MinHistoryDepths => MinHistoryDepths;
|
||||
@@ -21,23 +26,23 @@ public class AdlIndicator : Indicator, IWatchlistIndicator
|
||||
Name = "ADL - Accumulation/Distribution Line";
|
||||
Description = "Accumulation/Distribution Line";
|
||||
|
||||
AdlSeries = new(name: "ADL", color: Color.Blue, width: 2, style: LineStyle.Solid);
|
||||
AddLineSeries(AdlSeries);
|
||||
_series = new(name: "ADL", color: Color.Blue, width: 2, style: LineStyle.Solid);
|
||||
AddLineSeries(_series);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
protected override void OnInit()
|
||||
{
|
||||
_adl = new Adl();
|
||||
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 = _adl!.Update(bar, isNew);
|
||||
TValue result = _adl!.Update(bar, args.IsNewBar());
|
||||
|
||||
AdlSeries!.SetValue(result.Value);
|
||||
_series!.SetValue(result.Value, _adl.IsHot, ShowColdValues);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,24 +20,28 @@ public class AdoscIndicatorTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AdoscIndicator_MinHistoryDepths_EqualsSlowPeriod()
|
||||
public void AdoscIndicator_MinHistoryDepths_EqualsZero()
|
||||
{
|
||||
var indicator = new AdoscIndicator { SlowPeriod = 20 };
|
||||
var indicator = new AdoscIndicator
|
||||
{
|
||||
SlowPeriod = 20
|
||||
};
|
||||
|
||||
Assert.Equal(20, indicator.MinHistoryDepths);
|
||||
Assert.Equal(0, AdoscIndicator.MinHistoryDepths);
|
||||
IWatchlistIndicator watchlistIndicator = indicator;
|
||||
Assert.Equal(20, watchlistIndicator.MinHistoryDepths);
|
||||
Assert.Equal(0, watchlistIndicator.MinHistoryDepths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AdoscIndicator_ShortName_IncludesParameters()
|
||||
public void AdoscIndicator_SlowPeriod_CanBeChanged()
|
||||
{
|
||||
var indicator = new AdoscIndicator { FastPeriod = 10, SlowPeriod = 40 };
|
||||
indicator.Initialize();
|
||||
var indicator = new AdoscIndicator
|
||||
{
|
||||
SlowPeriod = 40
|
||||
};
|
||||
|
||||
Assert.Contains("ADOSC", indicator.ShortName);
|
||||
Assert.Contains("10", indicator.ShortName);
|
||||
Assert.Contains("40", indicator.ShortName);
|
||||
Assert.Equal(40, indicator.SlowPeriod);
|
||||
Assert.Equal(0, AdoscIndicator.MinHistoryDepths);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -117,6 +121,6 @@ public class AdoscIndicatorTests
|
||||
|
||||
Assert.Equal(10, indicator.FastPeriod);
|
||||
Assert.Equal(40, indicator.SlowPeriod);
|
||||
Assert.Equal(40, indicator.MinHistoryDepths);
|
||||
Assert.Equal(0, AdoscIndicator.MinHistoryDepths);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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