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
@@ -42,7 +42,9 @@ public sealed class PchannelIndicator : Indicator, IWatchlistIndicator
protected override void OnUpdate(UpdateArgs args)
{
if (_indicator is null)
{
return;
}
var item = HistoricalData[0, SeekOriginHistory.End];
bool isNew = args.IsNewBar();
@@ -18,9 +18,16 @@ public sealed class PchannelValidationTests : IDisposable
private void Dispose(bool disposing)
{
if (_disposed) return;
if (_disposed)
{
return;
}
_disposed = true;
if (disposing) _testData?.Dispose();
if (disposing)
{
_testData?.Dispose();
}
}
[Fact]
+36 -1
View File
@@ -49,7 +49,9 @@ public sealed class Pchannel : ITValuePublisher
public Pchannel(int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
_period = period;
_hBuf = new double[_period];
@@ -85,14 +87,22 @@ public sealed class Pchannel : ITValuePublisher
private (double high, double low) GetValid(double high, double low)
{
if (double.IsFinite(high))
{
_state = _state with { LastValidHigh = high };
}
else
{
high = _state.LastValidHigh;
}
if (double.IsFinite(low))
{
_state = _state with { LastValidLow = low };
}
else
{
low = _state.LastValidLow;
}
return (high, low);
}
@@ -165,7 +175,9 @@ public sealed class Pchannel : ITValuePublisher
_lCount = 0;
if (_count == 0)
{
return;
}
long startLogical = _index - _count + 1;
for (int i = 0; i < _count; i++)
@@ -183,15 +195,21 @@ public sealed class Pchannel : ITValuePublisher
public TValue Update(TBar input, bool isNew = true)
{
if (isNew)
{
_p_state = _state;
}
else
{
_state = _p_state;
}
if (isNew)
{
_index++;
if (_count < _period)
{
_count++;
}
}
int bufIdx = (int)(_index % _period);
@@ -224,7 +242,9 @@ public sealed class Pchannel : ITValuePublisher
double mid = (top + bot) * 0.5;
if (!IsHot && _count >= _period)
{
_state = _state with { IsHot = true };
}
Last = new TValue(input.Time, mid);
Upper = new TValue(input.Time, top);
@@ -237,7 +257,9 @@ public sealed class Pchannel : ITValuePublisher
public (TSeries Middle, TSeries Upper, TSeries Lower) Update(TBarSeries source)
{
if (source.Count == 0)
{
return (new TSeries([], []), new TSeries([], []), new TSeries([], []));
}
int len = source.Count;
var tMiddle = new List<long>(len);
@@ -280,7 +302,9 @@ public sealed class Pchannel : ITValuePublisher
Reset();
if (source.Count == 0)
{
return;
}
for (int i = 0; i < source.Count; i++)
{
@@ -317,14 +341,25 @@ public sealed class Pchannel : ITValuePublisher
int period)
{
if (period <= 0)
{
throw new ArgumentException("Period must be greater than 0", nameof(period));
}
if (high.Length != low.Length)
{
throw new ArgumentException("High and Low spans must have the same length", nameof(high));
}
if (middle.Length < high.Length || upper.Length < high.Length || lower.Length < high.Length)
{
throw new ArgumentException("Output spans must be at least as long as inputs", nameof(middle));
}
int len = high.Length;
if (len == 0) return;
if (len == 0)
{
return;
}
double[] top = ArrayPool<double>.Shared.Rent(len);
double[] bot = ArrayPool<double>.Shared.Rent(len);