Skip to content

Commit

Permalink
add DMI output to ADX #1262
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender committed Nov 11, 2024
1 parent 54b391b commit b9c127e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/a-d/Adx/Adx.Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Skender.Stock.Indicators;
/// <param name="Timestamp">Gets the timestamp of the result.</param>
/// <param name="Pdi">Gets the Positive Directional Indicator (PDI) value.</param>
/// <param name="Mdi">Gets the Negative Directional Indicator (MDI) value.</param>
/// <param name="Dx">Gets the Directional Index (DX) value.</param>
/// <param name="Adx">Gets the Average Directional Index (ADX) value.</param>
/// <param name="Adxr">Gets the Average Directional Movement Rating (ADXR) value.</param>
[Serializable]
Expand All @@ -14,6 +15,7 @@ public record AdxResult
DateTime Timestamp,
double? Pdi = null,
double? Mdi = null,
double? Dx = null,
double? Adx = null,
double? Adxr = null
) : IReusable
Expand Down
1 change: 1 addition & 0 deletions src/a-d/Adx/Adx.StaticSeries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ private static List<AdxResult> CalcAdx(
Timestamp: q.Timestamp,
Pdi: pdi,
Mdi: mdi,
Dx: dx.NaN2Null(),
Adx: adx.NaN2Null(),
Adxr: adxr.NaN2Null());

Expand Down
Binary file modified tests/indicators/a-d/Adx/Adx.Calc.xlsx
Binary file not shown.
23 changes: 23 additions & 0 deletions tests/indicators/a-d/Adx/Adx.StaticSeries.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,39 @@ public override void Standard()

// proper quantities
Assert.AreEqual(502, results.Count);
Assert.AreEqual(488, results.Count(x => x.Dx != null));
Assert.AreEqual(475, results.Count(x => x.Adx != null));
Assert.AreEqual(462, results.Count(x => x.Adxr != null));

// sample values
AdxResult r13 = results[13];
Assert.AreEqual(null, r13.Pdi);
Assert.AreEqual(null, r13.Mdi);
Assert.AreEqual(null, r13.Dx);
Assert.AreEqual(null, r13.Adx);

AdxResult r14 = results[14];
Assert.AreEqual(21.9669, r14.Pdi.Round(4));
Assert.AreEqual(18.5462, r14.Mdi.Round(4));
Assert.AreEqual(8.4433, r14.Dx.Round(4));
Assert.AreEqual(null, r14.Adx);

AdxResult r19 = results[19];
Assert.AreEqual(21.0361, r19.Pdi.Round(4));
Assert.AreEqual(25.0124, r19.Mdi.Round(4));
Assert.AreEqual(8.6351, r19.Dx.Round(4));
Assert.AreEqual(null, r19.Adx);

AdxResult r26 = results[26];
Assert.AreEqual(null, r26.Adx);

AdxResult r27 = results[27];
Assert.AreEqual(15.9459, r27.Adx.Round(4));

AdxResult r29 = results[29];
Assert.AreEqual(37.9719, r29.Pdi.Round(4));
Assert.AreEqual(14.1658, r29.Mdi.Round(4));
Assert.AreEqual(45.6600, r29.Dx.Round(4));
Assert.AreEqual(19.7949, r29.Adx.Round(4));

AdxResult r39 = results[39];
Expand All @@ -33,12 +54,14 @@ public override void Standard()
AdxResult r248 = results[248];
Assert.AreEqual(32.3167, r248.Pdi.Round(4));
Assert.AreEqual(18.2471, r248.Mdi.Round(4));
Assert.AreEqual(27.8255, r248.Dx.Round(4));
Assert.AreEqual(30.5903, r248.Adx.Round(4));
Assert.AreEqual(29.1252, r248.Adxr.Round(4));

AdxResult r501 = results[501];
Assert.AreEqual(17.7565, r501.Pdi.Round(4));
Assert.AreEqual(31.1510, r501.Mdi.Round(4));
Assert.AreEqual(27.3873, r501.Dx.Round(4));
Assert.AreEqual(34.2987, r501.Adx.Round(4));
}

Expand Down

0 comments on commit b9c127e

Please sign in to comment.