mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings
This commit is contained in:
@@ -91,6 +91,78 @@ public sealed class AdxValidationTests : IDisposable
|
||||
ValidationHelper.VerifyData(results, tulipResults, lookback: offset);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DiPlus_MatchesTalib()
|
||||
{
|
||||
var adx = new Adx(14);
|
||||
var diPlusResults = new List<double>();
|
||||
|
||||
for (int i = 0; i < _data.Bars.Count; i++)
|
||||
{
|
||||
adx.Update(_data.Bars[i]);
|
||||
diPlusResults.Add(adx.DiPlus.Value);
|
||||
}
|
||||
|
||||
double[] hData = _data.Bars.High.Select(x => x.Value).ToArray();
|
||||
double[] lData = _data.Bars.Low.Select(x => x.Value).ToArray();
|
||||
double[] cData = _data.Bars.Close.Select(x => x.Value).ToArray();
|
||||
double[] outReal = new double[_data.Bars.Count];
|
||||
|
||||
var retCode = Functions.PlusDI(hData, lData, cData, 0..^0, outReal, out var outRange, 14);
|
||||
Assert.Equal(TALib.Core.RetCode.Success, retCode);
|
||||
|
||||
int lookback = Functions.PlusDILookback(14);
|
||||
ValidationHelper.VerifyData(diPlusResults, outReal, outRange, lookback);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DiMinus_MatchesTalib()
|
||||
{
|
||||
var adx = new Adx(14);
|
||||
var diMinusResults = new List<double>();
|
||||
|
||||
for (int i = 0; i < _data.Bars.Count; i++)
|
||||
{
|
||||
adx.Update(_data.Bars[i]);
|
||||
diMinusResults.Add(adx.DiMinus.Value);
|
||||
}
|
||||
|
||||
double[] hData = _data.Bars.High.Select(x => x.Value).ToArray();
|
||||
double[] lData = _data.Bars.Low.Select(x => x.Value).ToArray();
|
||||
double[] cData = _data.Bars.Close.Select(x => x.Value).ToArray();
|
||||
double[] outReal = new double[_data.Bars.Count];
|
||||
|
||||
var retCode = Functions.MinusDI(hData, lData, cData, 0..^0, outReal, out var outRange, 14);
|
||||
Assert.Equal(TALib.Core.RetCode.Success, retCode);
|
||||
|
||||
int lookback = Functions.MinusDILookback(14);
|
||||
ValidationHelper.VerifyData(diMinusResults, outReal, outRange, lookback);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatchesSkender_DiValues()
|
||||
{
|
||||
var adx = new Adx(14);
|
||||
var diPlusResults = new List<double>();
|
||||
var diMinusResults = new List<double>();
|
||||
|
||||
for (int i = 0; i < _data.Bars.Count; i++)
|
||||
{
|
||||
adx.Update(_data.Bars[i]);
|
||||
diPlusResults.Add(adx.DiPlus.Value);
|
||||
diMinusResults.Add(adx.DiMinus.Value);
|
||||
}
|
||||
|
||||
// Skender's GetAdx returns ADX with +DI and -DI values
|
||||
var skenderResults = _data.SkenderQuotes.GetAdx(14).ToList();
|
||||
|
||||
// Verify +DI
|
||||
ValidationHelper.VerifyData(diPlusResults, skenderResults, x => x.Pdi);
|
||||
|
||||
// Verify -DI
|
||||
ValidationHelper.VerifyData(diMinusResults, skenderResults, x => x.Mdi);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void MatchesOoples()
|
||||
{
|
||||
|
||||
@@ -62,6 +62,16 @@ public sealed class Adx : ITValuePublisher
|
||||
/// </summary>
|
||||
public TValue DiMinus { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current smoothed +DM value (RMA-smoothed raw plus directional movement, before TR normalization).
|
||||
/// </summary>
|
||||
public TValue DmPlus { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Current smoothed -DM value (RMA-smoothed raw minus directional movement, before TR normalization).
|
||||
/// </summary>
|
||||
public TValue DmMinus { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// True if the ADX has warmed up and is providing valid results.
|
||||
/// </summary>
|
||||
@@ -116,6 +126,8 @@ public sealed class Adx : ITValuePublisher
|
||||
Last = default;
|
||||
DiPlus = default;
|
||||
DiMinus = default;
|
||||
DmPlus = default;
|
||||
DmMinus = default;
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
@@ -325,6 +337,8 @@ public sealed class Adx : ITValuePublisher
|
||||
|
||||
DiPlus = new TValue(input.Time, diPlus);
|
||||
DiMinus = new TValue(input.Time, diMinus);
|
||||
DmPlus = new TValue(input.Time, _samples >= _period ? _dmPlusSmooth : 0);
|
||||
DmMinus = new TValue(input.Time, _samples >= _period ? _dmMinusSmooth : 0);
|
||||
Last = new TValue(input.Time, finalAdx);
|
||||
|
||||
Pub?.Invoke(this, new TValueEventArgs { Value = Last, IsNew = isNew });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// The MIT License (MIT)
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Average Directional Movement Index (ADX)", "ADX", overlay=false)
|
||||
|
||||
Reference in New Issue
Block a user