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
@@ -206,4 +206,4 @@ public class AdlTests
Assert.Equal((i + 1) * 10, output[i]);
}
}
}
}
+7 -2
View File
@@ -129,7 +129,10 @@ public sealed class Adl : ITValuePublisher
public static TSeries Calculate(TBarSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
var t = source.Open.Times.ToArray(); // Times are same for all series
var v = new double[source.Count];
@@ -143,7 +146,9 @@ public sealed class Adl : ITValuePublisher
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output)
{
if (high.Length != low.Length || high.Length != close.Length || high.Length != volume.Length || high.Length != output.Length)
{
throw new ArgumentException("All spans must be of the same length", nameof(output));
}
int len = high.Length;
int i = 0;
@@ -196,4 +201,4 @@ public sealed class Adl : ITValuePublisher
output[i] = sum;
}
}
}
}
+12 -1
View File
@@ -57,11 +57,19 @@ public sealed class Adosc : ITValuePublisher
public Adosc(int fastPeriod = 3, int slowPeriod = 10)
{
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));
}
_adl = new Adl();
_emaFast = new Ema(fastPeriod);
@@ -181,7 +189,10 @@ public sealed class Adosc : ITValuePublisher
}
int len = high.Length;
if (len == 0) return;
if (len == 0)
{
return;
}
// EMA parameters (same formula as Ema.cs: alpha = 2 / (period + 1))
double alphaFast = 2.0 / (fastPeriod + 1);
+20 -1
View File
@@ -67,7 +67,9 @@ public sealed class Cmf : ITValuePublisher
public Cmf(int period = 20)
{
if (period < 1)
{
throw new ArgumentException("Period must be >= 1", nameof(period));
}
_period = period;
_mfvBuffer = new RingBuffer(period);
@@ -183,7 +185,10 @@ public sealed class Cmf : ITValuePublisher
public static TSeries Calculate(TBarSeries source, int period = 20)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
var t = source.Open.Times.ToArray();
var v = new double[source.Count];
@@ -197,15 +202,29 @@ public sealed class Cmf : ITValuePublisher
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low, ReadOnlySpan<double> close, ReadOnlySpan<double> volume, Span<double> output, int period = 20)
{
if (high.Length != low.Length)
{
throw new ArgumentException("High and Low spans must be of the same length", nameof(low));
}
if (high.Length != close.Length)
{
throw new ArgumentException("High and Close spans must be of the same length", nameof(close));
}
if (high.Length != volume.Length)
{
throw new ArgumentException("High and Volume spans must be of the same length", nameof(volume));
}
if (high.Length != output.Length)
{
throw new ArgumentException("Output span must be of the same length as input", nameof(output));
}
if (period < 1)
{
throw new ArgumentException("Period must be >= 1", nameof(period));
}
int len = high.Length;