Skip to content

Commit

Permalink
fix: Zig Zag retrace conditions (#633)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveSkender authored Nov 20, 2021
1 parent cdb86be commit e0cd978
Show file tree
Hide file tree
Showing 4 changed files with 163 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/s-z/ZigZag/ZigZag.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,11 @@ private static void DrawRetraceLine(
lastLowPoint.Value = nextPoint.Value;
}

// nothing to do if first line or no-span case
if (priorPoint.Index == 1 || nextPoint.Index == priorPoint.Index)
// nothing to draw cases
if (
lastDirection == "U" // first line skipped, single line
|| priorPoint.Index == 1 // first line skipped, normal case
|| nextPoint.Index == priorPoint.Index) // no span
{
return;
}
Expand Down
3 changes: 3 additions & 0 deletions tests/indicators/Tests.Indicators.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<None Update="s-z\ZigZag\data.ethusdt.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="s-z\ZigZag\data.issue632.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="s-z\ZigZag\data.schrodinger.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
17 changes: 17 additions & 0 deletions tests/indicators/s-z/ZigZag/ZigZag.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ public void NoEntry()
Assert.AreEqual(0, results.Count(x => x.PointType != null));
}

[TestMethod]
public void Issue632()
{
// thresholds are never met
string json = File.ReadAllText("./s-z/ZigZag/data.issue632.json");

List<Quote> quotesList = JsonConvert
.DeserializeObject<IReadOnlyCollection<Quote>>(json)
.ToList();

List<ZigZagResult> resultsList = quotesList
.GetZigZag(EndType.Close, 5m)
.ToList();

Assert.AreEqual(17, resultsList.Count);
}

[TestMethod]
public void BadData()
{
Expand Down
138 changes: 138 additions & 0 deletions tests/indicators/s-z/ZigZag/data.issue632.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
[
{
"Date": "2021-10-20T00:00:00",
"Open": 23.59800,
"High": 24.42100,
"Low": 23.57500,
"Close": 24.29000,
"Volume": 91.0
},
{
"Date": "2021-10-21T00:00:00",
"Open": 24.29400,
"High": 24.48700,
"Low": 24.00800,
"Close": 24.15400,
"Volume": 89.0
},
{
"Date": "2021-10-22T00:00:00",
"Open": 24.15200,
"High": 24.82600,
"Low": 24.12300,
"Close": 24.27900,
"Volume": 84.0
},
{
"Date": "2021-10-25T00:00:00",
"Open": 24.39800,
"High": 24.61800,
"Low": 24.30600,
"Close": 24.55600,
"Volume": 92.0
},
{
"Date": "2021-10-26T00:00:00",
"Open": 24.55600,
"High": 24.55800,
"Low": 23.87900,
"Close": 24.14500,
"Volume": 92.0
},
{
"Date": "2021-10-27T00:00:00",
"Open": 24.14500,
"High": 24.25400,
"Low": 23.83700,
"Close": 24.04000,
"Volume": 92.0
},
{
"Date": "2021-10-28T00:00:00",
"Open": 24.03800,
"High": 24.24600,
"Low": 23.96300,
"Close": 24.06600,
"Volume": 92.0
},
{
"Date": "2021-10-29T00:00:00",
"Open": 24.06600,
"High": 24.08100,
"Low": 23.66100,
"Close": 23.88900,
"Volume": 84.0
},
{
"Date": "2021-11-01T00:00:00",
"Open": 23.77900,
"High": 24.10200,
"Low": 23.74900,
"Close": 24.02300,
"Volume": 92.0
},
{
"Date": "2021-11-02T00:00:00",
"Open": 24.02300,
"High": 24.06700,
"Low": 23.39200,
"Close": 23.52700,
"Volume": 92.0
},
{
"Date": "2021-11-03T00:00:00",
"Open": 23.52700,
"High": 23.72400,
"Low": 23.02000,
"Close": 23.72200,
"Volume": 92.0
},
{
"Date": "2021-11-04T00:00:00",
"Open": 23.72100,
"High": 24.04100,
"Low": 23.44300,
"Close": 23.77700,
"Volume": 92.0
},
{
"Date": "2021-11-05T00:00:00",
"Open": 23.77300,
"High": 24.17800,
"Low": 23.62700,
"Close": 24.16700,
"Volume": 84.0
},
{
"Date": "2021-11-08T00:00:00",
"Open": 24.13100,
"High": 24.51300,
"Low": 24.05800,
"Close": 24.44800,
"Volume": 92.0
},
{
"Date": "2021-11-09T00:00:00",
"Open": 24.44700,
"High": 24.47700,
"Low": 24.02900,
"Close": 24.30900,
"Volume": 92.0
},
{
"Date": "2021-11-10T00:00:00",
"Open": 24.30800,
"High": 25.13000,
"Low": 24.06500,
"Close": 24.64800,
"Volume": 92.0
},
{
"Date": "2021-11-11T00:00:00",
"Open": 24.64500,
"High": 25.01200,
"Low": 24.59000,
"Close": 24.97400,
"Volume": 36.0
}
]

0 comments on commit e0cd978

Please sign in to comment.