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
@@ -186,4 +186,4 @@ public class AdrIndicatorTests
Assert.Contains("github.com", indicator.SourceCodeLink, StringComparison.Ordinal);
Assert.Contains("Adr.Quantower.cs", indicator.SourceCodeLink, StringComparison.Ordinal);
}
}
}
+1 -1
View File
@@ -55,4 +55,4 @@ public sealed class AdrIndicator : Indicator, IWatchlistIndicator
_series.SetValue(result.Value, _adr.IsHot, ShowColdValues);
}
}
}
+5 -2
View File
@@ -279,7 +279,10 @@ public class AdrTests
var gbm = new GBM();
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
foreach (var bar in bars) adr.Update(bar);
foreach (var bar in bars)
{
adr.Update(bar);
}
double lastVal = adr.Last.Value;
Assert.NotEqual(0, lastVal);
@@ -553,4 +556,4 @@ public class AdrTests
// Negative range should be treated as 0
Assert.Equal(0.0, result.Value, 1e-10);
}
}
}
+1 -1
View File
@@ -306,4 +306,4 @@ public sealed class AdrValidationTests : IDisposable
_output.WriteLine($"ADR: {adr.Last.Value:F4}, ATR: {atr.Last.Value:F4}");
_output.WriteLine("ADR and ATR validated: both produce valid results");
}
}
}
+7 -2
View File
@@ -33,7 +33,9 @@ public sealed class Adr : AbstractBase
public Adr(int period, AdrMethod method = AdrMethod.Sma)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
_ma = method switch
{
@@ -137,7 +139,10 @@ public sealed class Adr : AbstractBase
/// </summary>
public TSeries Update(TBarSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
// Calculate range series
TSeries rangeSeries = CalculateRanges(source);
@@ -223,4 +228,4 @@ public enum AdrMethod
Ema = 2,
/// <summary>Weighted Moving Average</summary>
Wma = 3
}
}
+1 -1
View File
@@ -148,4 +148,4 @@ public class AtrIndicatorTests
Assert.Contains("github.com", indicator.SourceCodeLink, StringComparison.Ordinal);
Assert.Contains("Atr.Quantower.cs", indicator.SourceCodeLink, StringComparison.Ordinal);
}
}
}
+4 -1
View File
@@ -179,7 +179,10 @@ public class AtrTests
var gbm = new GBM();
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
foreach (var bar in bars) atr.Update(bar);
foreach (var bar in bars)
{
atr.Update(bar);
}
double lastVal = atr.Last.Value;
Assert.NotEqual(0, lastVal);
+11 -3
View File
@@ -34,7 +34,9 @@ public sealed class Atr : AbstractBase
public Atr(int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
_rma = new Rma(period);
Name = $"Atr({period})";
@@ -165,7 +167,10 @@ public sealed class Atr : AbstractBase
public TSeries Update(TBarSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
// 1. Calculate TR series
TSeries trSeries = CalculateTrueRange(source);
@@ -193,7 +198,10 @@ public sealed class Atr : AbstractBase
var t = new List<long>(source.Count);
var v = new List<double>(source.Count);
if (source.Count == 0) return new TSeries(t, v);
if (source.Count == 0)
{
return new TSeries(t, v);
}
// First bar TR = H - L
t.Add(source[0].Time);
@@ -223,4 +231,4 @@ public sealed class Atr : AbstractBase
var atr = new Atr(period);
return atr.Update(source);
}
}
}
+1 -1
View File
@@ -181,4 +181,4 @@ public class AtrnIndicatorTests
Assert.Contains("github.com", indicator.SourceCodeLink, StringComparison.Ordinal);
Assert.Contains("Atrn.Quantower.cs", indicator.SourceCodeLink, StringComparison.Ordinal);
}
}
}
+1 -1
View File
@@ -48,4 +48,4 @@ public sealed class AtrnIndicator : Indicator, IWatchlistIndicator
_series.SetValue(result.Value, _atrn.IsHot, ShowColdValues);
}
}
}
+10 -3
View File
@@ -123,8 +123,15 @@ public sealed class AtrnValidationTests : IDisposable
for (int j = startIdx; j < atrValues.Count; j++)
{
if (atrValues[j] < minAtr) minAtr = atrValues[j];
if (atrValues[j] > maxAtr) maxAtr = atrValues[j];
if (atrValues[j] < minAtr)
{
minAtr = atrValues[j];
}
if (atrValues[j] > maxAtr)
{
maxAtr = atrValues[j];
}
}
double currentAtr = atrValues[^1];
@@ -336,4 +343,4 @@ public sealed class AtrnValidationTests : IDisposable
}
#endregion
}
}
+26 -6
View File
@@ -43,7 +43,9 @@ public sealed class Atrn : AbstractBase
public Atrn(int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
_lookbackWindow = 10 * period;
_rma = new Rma(period);
@@ -239,7 +241,10 @@ public sealed class Atrn : 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);
@@ -259,7 +264,10 @@ public sealed class Atrn : AbstractBase
/// </summary>
public override TSeries Update(TSeries 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);
@@ -287,12 +295,18 @@ public sealed class Atrn : AbstractBase
private double GetMax()
{
ReadOnlySpan<double> span = _atrBuffer.GetSpan();
if (span.IsEmpty) return 0;
if (span.IsEmpty)
{
return 0;
}
double max = double.MinValue;
for (int i = 0; i < span.Length; i++)
{
if (span[i] > max) max = span[i];
if (span[i] > max)
{
max = span[i];
}
}
return max;
}
@@ -301,12 +315,18 @@ public sealed class Atrn : AbstractBase
private double GetMin()
{
ReadOnlySpan<double> span = _atrBuffer.GetSpan();
if (span.IsEmpty) return 0;
if (span.IsEmpty)
{
return 0;
}
double min = double.MaxValue;
for (int i = 0; i < span.Length; i++)
{
if (span[i] < min) min = span[i];
if (span[i] < min)
{
min = span[i];
}
}
return min;
}
+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);
}
}
}