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
+36 -8
View File
@@ -110,18 +110,39 @@ public class FramaValidationTests
lv = lastLow;
}
if (hv > maxFull) maxFull = hv;
if (lv < minFull) minFull = lv;
if (hv > maxFull)
{
maxFull = hv;
}
if (lv < minFull)
{
minFull = lv;
}
if (j >= startRecent)
{
if (hv > maxRecent) maxRecent = hv;
if (lv < minRecent) minRecent = lv;
if (hv > maxRecent)
{
maxRecent = hv;
}
if (lv < minRecent)
{
minRecent = lv;
}
}
else
{
if (hv > maxPrev) maxPrev = hv;
if (lv < minPrev) minPrev = lv;
if (hv > maxPrev)
{
maxPrev = hv;
}
if (lv < minPrev)
{
minPrev = lv;
}
}
}
@@ -134,8 +155,15 @@ public class FramaValidationTests
{
double dimen = (Math.Log(n1 + n2) - Math.Log(n3)) / 0.693147180559945309417232121458176568;
alpha = Math.Exp(-4.6 * (dimen - 1.0));
if (alpha < 0.01) alpha = 0.01;
if (alpha > 1.0) alpha = 1.0;
if (alpha < 0.01)
{
alpha = 0.01;
}
if (alpha > 1.0)
{
alpha = 1.0;
}
}
double price = (highVal + lowVal) * 0.5;
+40 -6
View File
@@ -147,8 +147,15 @@ public sealed class Frama : ITValuePublisher
{
double dimen = (Math.Log(n1 + n2) - Math.Log(n3)) / Log2;
alpha = Math.Exp(-4.6 * (dimen - 1.0));
if (alpha < AlphaFloor) alpha = AlphaFloor;
if (alpha > AlphaCeil) alpha = AlphaCeil;
if (alpha < AlphaFloor)
{
alpha = AlphaFloor;
}
if (alpha > AlphaCeil)
{
alpha = AlphaCeil;
}
}
double prev = _state.HasValue && double.IsFinite(_state.Frama) ? _state.Frama : price;
@@ -170,7 +177,10 @@ public sealed class Frama : ITValuePublisher
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];
@@ -195,7 +205,10 @@ public sealed class Frama : ITValuePublisher
public TSeries Update(TSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
int len = source.Count;
var t = new List<long>(len);
@@ -224,7 +237,9 @@ public sealed class Frama : ITValuePublisher
public static void Calculate(ReadOnlySpan<double> high, ReadOnlySpan<double> low, int period, Span<double> output)
{
if (high.Length != low.Length || high.Length != output.Length)
{
throw new ArgumentException("Input spans must have the same length.", nameof(output));
}
ArgumentOutOfRangeException.ThrowIfLessThan(period, 2);
@@ -240,7 +255,9 @@ public sealed class Frama : ITValuePublisher
public static void Calculate(ReadOnlySpan<double> source, Span<double> output, int period)
{
if (source.Length != output.Length)
{
throw new ArgumentException("Source and output must have the same length.", nameof(output));
}
ArgumentOutOfRangeException.ThrowIfLessThan(period, 2);
@@ -254,7 +271,10 @@ public sealed class Frama : ITValuePublisher
public static TSeries Batch(TBarSeries source, int period)
{
if (source.Count == 0) return new TSeries([], []);
if (source.Count == 0)
{
return new TSeries([], []);
}
int len = source.Count;
var v = new double[len];
@@ -275,7 +295,9 @@ public sealed class Frama : ITValuePublisher
{
int count = buffer.Count;
if (count == 0 || length <= 0)
{
return double.NaN;
}
int capacity = buffer.Capacity;
int start = buffer.StartIndex;
@@ -288,10 +310,15 @@ public sealed class Frama : ITValuePublisher
{
int idx = start + offset + i;
if (idx >= capacity)
{
idx -= capacity;
}
double v = data[idx];
if (v > max)
{
max = v;
}
}
return max;
@@ -302,7 +329,9 @@ public sealed class Frama : ITValuePublisher
{
int count = buffer.Count;
if (count == 0 || length <= 0)
{
return double.NaN;
}
int capacity = buffer.Capacity;
int start = buffer.StartIndex;
@@ -315,12 +344,17 @@ public sealed class Frama : ITValuePublisher
{
int idx = start + offset + i;
if (idx >= capacity)
{
idx -= capacity;
}
double v = data[idx];
if (v < min)
{
min = v;
}
}
return min;
}
}
}