Skip to content

Commit

Permalink
harden KVO volume force calculation (#451)
Browse files Browse the repository at this point in the history
better handling of bad data or rare data scenarios
  • Loading branch information
DaveSkender authored May 25, 2021
1 parent b65df19 commit 2c5467e
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions indicators/Kvo/Kvo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ public static IEnumerable<KvoResult> GetKvo<TQuote>(
(cm[i - 1] + dm[i]) : (dm[i - 1] + dm[i]);

// volume force (VF)
vf[i] = cm[i] != 0 ?
h.Volume * Math.Abs(2 * (dm[i] / cm[i] - 1)) * t[i] * 100m
: null;
vf[i] = (dm[i] == cm[i] || h.Volume == 0) ? 0
: (dm[i] == 0) ? h.Volume * 2 * t[i] * 100m
: (cm[i] != 0) ? h.Volume * Math.Abs(2 * (dm[i] / cm[i] - 1)) * t[i] * 100m
: vf[i - 1];

// fast-period EMA of VF
if (index > fastPeriod + 2)
{
// lastEma + k * (h.Value - lastEma);
vfFastEma[i] = vf[i] * kFast + vfFastEma[i - 1] * (1 - kFast);
}
else if (index == fastPeriod + 2)
Expand Down

0 comments on commit 2c5467e

Please sign in to comment.