feat: Refactor TBar and TValue to record structs; improve readability and performance

fix: Update condition checks in Htit and Mgdi for better numerical stability
refactor: Simplify parameter struct in T3 and enhance Vidya state management
This commit is contained in:
Miha Kralj
2025-12-17 07:27:45 -08:00
parent d277e08056
commit 8cec2fec8d
6 changed files with 20 additions and 100 deletions
+10 -5
View File
@@ -33,7 +33,7 @@ public sealed class Mgdi : AbstractBase
public Mgdi(int period = 14, double k = 0.6)
{
if (period < 1) throw new ArgumentOutOfRangeException(nameof(period));
ArgumentOutOfRangeException.ThrowIfLessThan(period, 1);
if (double.IsNaN(k) || double.IsInfinity(k) || k <= 0) throw new ArgumentOutOfRangeException(nameof(k), "k must be a finite value greater than 0");
_period = period;
_k = k;
@@ -57,10 +57,15 @@ public sealed class Mgdi : AbstractBase
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override TValue Update(TValue input, bool isNew = true)
{
if (isNew) _p_state = _state;
else _state = _p_state;
if (isNew) _state.Count++;
if (isNew)
{
_p_state = _state;
_state.Count++;
}
else
{
_state = _p_state;
}
double price = input.Value;
if (!double.IsFinite(price))