style patterns

This commit is contained in:
Miha Kralj
2026-01-25 16:01:45 -08:00
parent 2836f253c4
commit e59665c8f0
399 changed files with 6892 additions and 1323 deletions
+37 -5
View File
@@ -52,7 +52,9 @@ public sealed class Atrp : AbstractBase
public Atrp(int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
_alpha = 1.0 / period;
_decay = 1.0 - _alpha;
@@ -135,18 +137,45 @@ public sealed class Atrp : AbstractBase
public TValue Update(TBar input, bool isNew = true)
{
if (isNew)
{
_p_state = _state;
}
else
{
_state = _p_state;
}
// Get valid values with last-value substitution
double high = input.High;
double low = input.Low;
double close = input.Close;
if (double.IsFinite(high)) _state.LastValidHigh = high; else high = _state.LastValidHigh;
if (double.IsFinite(low)) _state.LastValidLow = low; else low = _state.LastValidLow;
if (double.IsFinite(close)) _state.LastValidClose = close; else close = _state.LastValidClose;
if (double.IsFinite(high))
{
_state.LastValidHigh = high;
}
else
{
high = _state.LastValidHigh;
}
if (double.IsFinite(low))
{
_state.LastValidLow = low;
}
else
{
low = _state.LastValidLow;
}
if (double.IsFinite(close))
{
_state.LastValidClose = close;
}
else
{
close = _state.LastValidClose;
}
// Handle case where no valid values yet
if (double.IsNaN(close))
@@ -212,7 +241,10 @@ public sealed class Atrp : AbstractBase
/// </summary>
public TSeries Update(TBarSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
var t = new List<long>(source.Count);
var v = new List<double>(source.Count);
@@ -249,4 +281,4 @@ public sealed class Atrp : AbstractBase
var atrp = new Atrp(period);
return atrp.Update(source);
}
}
}