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
@@ -217,4 +217,4 @@ public class ApchannelIndicatorTests
double expectedMiddle = (upper + lower) / 2.0;
Assert.Equal(expectedMiddle, middle, 6); // 6 decimal precision
}
}
}
@@ -48,7 +48,10 @@ public sealed class ApchannelIndicator : Indicator, IWatchlistIndicator
protected override void OnUpdate(UpdateArgs args)
{
if (_apchannel == null) return;
if (_apchannel == null)
{
return;
}
var item = HistoricalData[0, SeekOriginHistory.End];
bool isNew = args.IsNewBar();
@@ -75,4 +78,4 @@ public sealed class ApchannelIndicator : Indicator, IWatchlistIndicator
// Lower band
LinesSeries[2].SetValue(_apchannel.LowerBand, isHot, ShowColdValues);
}
}
}
@@ -22,9 +22,16 @@ public sealed class ApchannelValidationTests : IDisposable
private void Dispose(bool disposing)
{
if (_disposed) return;
if (_disposed)
{
return;
}
_disposed = true;
if (disposing) _testData?.Dispose();
if (disposing)
{
_testData?.Dispose();
}
}
/// <summary>
+35 -6
View File
@@ -83,7 +83,11 @@ public sealed class Apchannel : AbstractBase
/// </summary>
protected override void Dispose(bool disposing)
{
if (_disposed) return;
if (_disposed)
{
return;
}
_disposed = true;
if (disposing && _source != null)
@@ -174,7 +178,10 @@ public sealed class Apchannel : AbstractBase
[MethodImpl(MethodImplOptions.AggressiveInlining)]
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);
@@ -207,7 +214,10 @@ public sealed class Apchannel : AbstractBase
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override TSeries Update(TSeries source)
{
if (source.Count == 0) return [];
if (source.Count == 0)
{
return [];
}
int len = source.Count;
var t = new List<long>(len);
@@ -234,7 +244,9 @@ public sealed class Apchannel : AbstractBase
{
Init();
if (source.Length == 0)
{
return;
}
long time = DateTime.UtcNow.Ticks;
long dt = step?.Ticks ?? TimeSpan.TicksPerMinute;
@@ -281,9 +293,15 @@ public sealed class Apchannel : AbstractBase
int length = sourceHigh.Length;
if (sourceLow.Length != length)
{
throw new ArgumentException("Source arrays must have the same length.", nameof(sourceLow));
}
if (upperBand.Length != length)
{
throw new ArgumentException("Upper band array must match source length.", nameof(upperBand));
}
if (lowerBand.Length != length)
{
throw new ArgumentException("Lower band array must match source length.", nameof(lowerBand));
@@ -295,7 +313,9 @@ public sealed class Apchannel : AbstractBase
}
if (length == 0)
{
return;
}
double decay = 1.0 - alpha;
@@ -324,7 +344,9 @@ public sealed class Apchannel : AbstractBase
// Early return for single-element arrays
if (length == 1)
{
return;
}
for (int i = 1; i < length; i++)
{
@@ -332,8 +354,15 @@ public sealed class Apchannel : AbstractBase
double low = sourceLow[i];
// Handle NaN/Infinity
if (!double.IsFinite(high)) high = lastValidHigh;
if (!double.IsFinite(low)) low = lastValidLow;
if (!double.IsFinite(high))
{
high = lastValidHigh;
}
if (!double.IsFinite(low))
{
low = lastValidLow;
}
// Use FMA for optimal performance and precision
highEma = Math.FusedMultiplyAdd(decay, highEma, alpha * high);
@@ -346,4 +375,4 @@ public sealed class Apchannel : AbstractBase
lastValidLow = low;
}
}
}
}