mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 05:28:05 +00:00
Refactor trend indicators to use record structs for state management
This commit is contained in:
+1
-20
@@ -26,28 +26,9 @@ namespace QuanTAlib;
|
||||
[SkipLocalsInit]
|
||||
public sealed class Tema : ITValuePublisher
|
||||
{
|
||||
private struct EmaState : IEquatable<EmaState>
|
||||
private record struct EmaState(double Ema, double E, bool IsHot, bool IsCompensated)
|
||||
{
|
||||
public double Ema;
|
||||
public double E;
|
||||
public bool IsHot;
|
||||
public bool IsCompensated;
|
||||
|
||||
public static EmaState New() => new() { Ema = 0, E = 1.0, IsHot = false, IsCompensated = false };
|
||||
|
||||
public override bool Equals(object? obj) => obj is EmaState other && Equals(other);
|
||||
|
||||
public bool Equals(EmaState other) =>
|
||||
Ema == other.Ema &&
|
||||
E == other.E &&
|
||||
IsHot == other.IsHot &&
|
||||
IsCompensated == other.IsCompensated;
|
||||
|
||||
public override int GetHashCode() => HashCode.Combine(Ema, E, IsHot, IsCompensated);
|
||||
|
||||
public static bool operator ==(EmaState left, EmaState right) => left.Equals(right);
|
||||
|
||||
public static bool operator !=(EmaState left, EmaState right) => !left.Equals(right);
|
||||
}
|
||||
|
||||
private readonly double _alpha;
|
||||
|
||||
Reference in New Issue
Block a user