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
+1 -1
View File
@@ -155,4 +155,4 @@ public class AtrpIndicatorTests
var indicator = new AtrpIndicator();
Assert.Contains("percentage", indicator.Description, StringComparison.OrdinalIgnoreCase);
}
}
}
+1 -1
View File
@@ -48,4 +48,4 @@ public sealed class AtrpIndicator : Indicator, IWatchlistIndicator
_series.SetValue(result.Value, _atrp.IsHot, ShowColdValues);
}
}
}
+5 -2
View File
@@ -180,7 +180,10 @@ public class AtrpTests
var gbm = new GBM();
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
foreach (var bar in bars) atrp.Update(bar);
foreach (var bar in bars)
{
atrp.Update(bar);
}
double lastVal = atrp.Last.Value;
Assert.NotEqual(0, lastVal);
@@ -449,4 +452,4 @@ public class AtrpTests
Assert.True(double.IsNaN(result.Value));
}
}
}
+1 -1
View File
@@ -347,4 +347,4 @@ public sealed class AtrpValidationTests : IDisposable
}
_output.WriteLine("ATRP Batch(TSeries) validated successfully against Ooples ATR");
}
}
}
+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);
}
}
}