mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-25 05:48:06 +00:00
style patterns
This commit is contained in:
@@ -48,7 +48,9 @@ public sealed class StarchannelIndicator : Indicator, IWatchlistIndicator
|
||||
protected override void OnUpdate(UpdateArgs args)
|
||||
{
|
||||
if (_indicator is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = HistoricalData[0, SeekOriginHistory.End];
|
||||
bool isNew = args.IsNewBar();
|
||||
|
||||
@@ -49,9 +49,14 @@ public sealed class Starchannel : ITValuePublisher
|
||||
public Starchannel(int period = 20, double multiplier = 2.0)
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be >= 1.");
|
||||
}
|
||||
|
||||
if (multiplier <= 0.0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(multiplier), "Multiplier must be > 0.");
|
||||
}
|
||||
|
||||
_period = period;
|
||||
_multiplier = multiplier;
|
||||
@@ -93,19 +98,31 @@ public sealed class Starchannel : ITValuePublisher
|
||||
private (double close, double high, double low) GetValid(double close, double high, double low)
|
||||
{
|
||||
if (double.IsFinite(close))
|
||||
{
|
||||
_state = _state with { LastValidClose = close };
|
||||
}
|
||||
else
|
||||
{
|
||||
close = _state.LastValidClose;
|
||||
}
|
||||
|
||||
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 (close, high, low);
|
||||
}
|
||||
@@ -147,7 +164,9 @@ public sealed class Starchannel : ITValuePublisher
|
||||
}
|
||||
|
||||
if (isNew)
|
||||
{
|
||||
_state = _state with { Bars = _state.Bars + 1 };
|
||||
}
|
||||
|
||||
// SMA: use RingBuffer's running sum
|
||||
_smaBuffer.Add(close);
|
||||
@@ -179,7 +198,9 @@ public sealed class Starchannel : ITValuePublisher
|
||||
double lower = smaValue - width;
|
||||
|
||||
if (!_state.IsHot && _state.Bars >= WarmupPeriod)
|
||||
{
|
||||
_state = _state with { IsHot = true };
|
||||
}
|
||||
|
||||
Last = new TValue(input.Time, smaValue);
|
||||
Upper = new TValue(input.Time, upper);
|
||||
@@ -192,7 +213,9 @@ public sealed class Starchannel : 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);
|
||||
@@ -237,7 +260,9 @@ public sealed class Starchannel : ITValuePublisher
|
||||
Reset();
|
||||
|
||||
if (source.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < source.Count; i++)
|
||||
{
|
||||
@@ -259,16 +284,30 @@ public sealed class Starchannel : ITValuePublisher
|
||||
double multiplier = 2.0)
|
||||
{
|
||||
if (period < 1)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(period), "Period must be >= 1.");
|
||||
}
|
||||
|
||||
if (multiplier <= 0.0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(multiplier), "Multiplier must be > 0.");
|
||||
}
|
||||
|
||||
if (high.Length != low.Length || high.Length != close.Length)
|
||||
{
|
||||
throw new ArgumentException("High, Low, and Close 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 atrAlpha = 1.0 / period;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user