Refactor event handling and improve argument validation across indicators

- Updated event handler signatures to use TValueEventArgs for consistency in Mama, Mgdi, Pwma, Rma, Sma, Ssf, Super, T3, Tema, Trima, Usf, Vidya, Wma, and Atr classes.
- Enhanced argument validation by specifying parameter names in exceptions for clarity.
- Adjusted tests to align with new event handler signatures.
- Improved code readability and maintainability by using structured records and lambda expressions.
This commit is contained in:
Miha Kralj
2025-12-27 15:46:28 -08:00
parent 4750c2b1e8
commit d7dbd7078a
73 changed files with 502 additions and 300 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ public class VidyaValidationTests
_output.WriteLine("VIDYA Batch validated successfully against reference implementation");
}
private static List<double> CalculateVidyaReference(TSeries data, int period)
private static IReadOnlyList<double> CalculateVidyaReference(TSeries data, int period)
{
var results = new List<double>();
var prices = data.Select(x => x.Value).ToList();
+6 -3
View File
@@ -33,8 +33,9 @@ public sealed class Vidya : AbstractBase, IDisposable
private readonly RingBuffer _ups;
private readonly RingBuffer _downs;
private readonly ITValuePublisher? _source;
private readonly Action<TValue>? _pubHandler;
private readonly TValuePublishedHandler? _pubHandler;
[StructLayout(LayoutKind.Auto)]
private record struct State(
double PrevClose, double LastVidya,
double CurrentClose, double CurrentVidya,
@@ -59,7 +60,7 @@ public sealed class Vidya : AbstractBase, IDisposable
public Vidya(ITValuePublisher source, int period) : this(period)
{
_source = source;
_pubHandler = (item) => Update(item);
_pubHandler = Handle;
source.Pub += _pubHandler;
}
@@ -71,6 +72,8 @@ public sealed class Vidya : AbstractBase, IDisposable
}
}
private void Handle(object? sender, TValueEventArgs e) => Update(e.Value, e.IsNew);
public override bool IsHot => _state.BarCount >= _period;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -277,7 +280,7 @@ public sealed class Vidya : AbstractBase, IDisposable
if (period <= 0)
throw new ArgumentException("Period must be greater than 0", nameof(period));
if (source.Length != output.Length)
throw new ArgumentException("Source and output must have the same length");
throw new ArgumentException("Source and output must have the same length", nameof(output));
if (source.Length == 0) return;