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
+2
View File
@@ -53,7 +53,9 @@ public sealed class AoIndicator : Indicator, IWatchlistIndicator
TValue result = _ao.Update(this.GetInputBar(args), args.IsNewBar());
if (!_ao.IsHot && !ShowColdValues)
{
return;
}
double prevAo = double.NaN;
if (Count > 1)
+4 -1
View File
@@ -109,7 +109,10 @@ public sealed class AoValidationTests : IDisposable
for (int i = 0; i < _data.Bars.Count; i++)
{
// Ooples might return 0 for warmup
if (i < 33) continue; // Skip warmup
if (i < 33)
{
continue; // Skip warmup
}
Assert.Equal(oValues[i], results[i], ValidationHelper.OoplesTolerance);
}
+23 -4
View File
@@ -60,11 +60,19 @@ public sealed class Ao : ITValuePublisher
public Ao(int fastPeriod = 5, int slowPeriod = 34)
{
if (fastPeriod <= 0)
{
throw new ArgumentException("Fast period must be greater than 0", nameof(fastPeriod));
}
if (slowPeriod <= 0)
{
throw new ArgumentException("Slow period must be greater than 0", nameof(slowPeriod));
}
if (fastPeriod >= slowPeriod)
{
throw new ArgumentException("Fast period must be less than slow period", nameof(fastPeriod));
}
_fastPeriod = fastPeriod;
_slowPeriod = slowPeriod;
@@ -163,7 +171,10 @@ public sealed class Ao : ITValuePublisher
/// <returns>The AO series</returns>
public TSeries Update(TBarSeries source)
{
if (source.Count == 0) return new TSeries([], []);
if (source.Count == 0)
{
return new TSeries([], []);
}
int len = source.Count;
var v = new double[len];
@@ -204,10 +215,15 @@ public sealed class Ao : ITValuePublisher
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low, Span<double> destination, int fastPeriod = 5, int slowPeriod = 34)
{
if (high.Length != low.Length || high.Length != destination.Length)
{
throw new ArgumentException("High, low, and destination spans must have the same length.", nameof(destination));
}
int len = high.Length;
if (len == 0) return;
if (len == 0)
{
return;
}
// Always use pooled buffer to avoid CS8353 stackalloc escape issues
// For small sizes, ArrayPool overhead is minimal
@@ -243,7 +259,10 @@ public sealed class Ao : ITValuePublisher
/// <returns>AO series</returns>
public static TSeries Batch(TBarSeries source, int fastPeriod = 5, int slowPeriod = 34)
{
if (source.Count == 0) return new TSeries([], []);
if (source.Count == 0)
{
return new TSeries([], []);
}
int len = source.Count;
var v = new double[len];
@@ -264,4 +283,4 @@ public sealed class Ao : ITValuePublisher
return new TSeries(tList, vList);
}
}
}
+10
View File
@@ -58,11 +58,19 @@ public sealed class Apo : ITValuePublisher
public Apo(int fastPeriod = 12, int slowPeriod = 26)
{
if (fastPeriod <= 0)
{
throw new ArgumentException("Fast period must be greater than 0", nameof(fastPeriod));
}
if (slowPeriod <= 0)
{
throw new ArgumentException("Slow period must be greater than 0", nameof(slowPeriod));
}
if (fastPeriod >= slowPeriod)
{
throw new ArgumentException("Fast period must be less than slow period", nameof(fastPeriod));
}
_emaFast = new Ema(fastPeriod);
_emaSlow = new Ema(slowPeriod);
@@ -174,7 +182,9 @@ public sealed class Apo : ITValuePublisher
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int fastPeriod = 12, int slowPeriod = 26)
{
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output spans must be of the same length.", nameof(output));
}
Span<double> fastEma = source.Length <= 1024 ? stackalloc double[source.Length] : new double[source.Length];
Span<double> slowEma = source.Length <= 1024 ? stackalloc double[source.Length] : new double[source.Length];
+4 -1
View File
@@ -217,7 +217,10 @@ public class UltoscTests
var gbm = new GBM();
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
foreach (var bar in bars) ultosc.Update(bar);
foreach (var bar in bars)
{
ultosc.Update(bar);
}
double lastVal = ultosc.Last.Value;
Assert.NotEqual(0, lastVal);
+54 -14
View File
@@ -64,15 +64,29 @@ public sealed class Ultosc : AbstractBase
public Ultosc(int period1 = 7, int period2 = 14, int period3 = 28)
{
if (period1 <= 0)
{
throw new ArgumentException("Period1 must be greater than 0", nameof(period1));
}
if (period2 <= 0)
{
throw new ArgumentException("Period2 must be greater than 0", nameof(period2));
}
if (period3 <= 0)
{
throw new ArgumentException("Period3 must be greater than 0", nameof(period3));
}
if (period1 >= period2)
{
throw new ArgumentException("Period1 must be less than Period2", nameof(period1));
}
if (period2 >= period3)
{
throw new ArgumentException("Period2 must be less than Period3", nameof(period2));
}
_period1 = period1;
_period2 = period2;
@@ -212,7 +226,10 @@ public sealed class Ultosc : AbstractBase
public TSeries Update(TBarSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
int len = source.Count;
var t = new List<long>(len);
@@ -243,7 +260,10 @@ public sealed class Ultosc : AbstractBase
{
// Cannot properly calculate Ultimate Oscillator from single-value series
// Return series of neutral values
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
var t = new List<long>(source.Count);
var v = new List<double>(source.Count);
@@ -281,19 +301,39 @@ public sealed class Ultosc : AbstractBase
{
int len = high.Length;
if (len != low.Length || len != close.Length || len != output.Length)
{
throw new ArgumentException("All arrays must have the same length", nameof(output));
if (period1 <= 0)
throw new ArgumentException("Period1 must be greater than 0", nameof(period1));
if (period2 <= 0)
throw new ArgumentException("Period2 must be greater than 0", nameof(period2));
if (period3 <= 0)
throw new ArgumentException("Period3 must be greater than 0", nameof(period3));
if (period1 >= period2)
throw new ArgumentException("Period1 must be less than Period2", nameof(period1));
if (period2 >= period3)
throw new ArgumentException("Period2 must be less than Period3", nameof(period2));
}
if (len == 0) return;
if (period1 <= 0)
{
throw new ArgumentException("Period1 must be greater than 0", nameof(period1));
}
if (period2 <= 0)
{
throw new ArgumentException("Period2 must be greater than 0", nameof(period2));
}
if (period3 <= 0)
{
throw new ArgumentException("Period3 must be greater than 0", nameof(period3));
}
if (period1 >= period2)
{
throw new ArgumentException("Period1 must be less than Period2", nameof(period1));
}
if (period2 >= period3)
{
throw new ArgumentException("Period2 must be less than Period3", nameof(period2));
}
if (len == 0)
{
return;
}
// Allocate buffers for BP and TR
double[] bpArray = System.Buffers.ArrayPool<double>.Shared.Rent(len);
@@ -386,4 +426,4 @@ public sealed class Ultosc : AbstractBase
_p_index = 0;
Last = default;
}
}
}