mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-26 06:18:05 +00:00
style patterns
This commit is contained in:
@@ -41,7 +41,9 @@ public sealed class MmchannelIndicator : Indicator, IWatchlistIndicator
|
||||
protected override void OnUpdate(UpdateArgs args)
|
||||
{
|
||||
if (_indicator is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var item = HistoricalData[0, SeekOriginHistory.End];
|
||||
bool isNew = args.IsNewBar();
|
||||
|
||||
@@ -41,7 +41,9 @@ public sealed class Mmchannel : ITValuePublisher
|
||||
public Mmchannel(int period)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
}
|
||||
|
||||
_period = period;
|
||||
_hBuf = new double[_period];
|
||||
@@ -73,14 +75,22 @@ public sealed class Mmchannel : 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);
|
||||
}
|
||||
@@ -89,15 +99,21 @@ public sealed class Mmchannel : 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);
|
||||
@@ -132,7 +148,9 @@ public sealed class Mmchannel : ITValuePublisher
|
||||
double bot = _minDeque.GetExtremum(_lBuf);
|
||||
|
||||
if (!IsHot && _count >= _period)
|
||||
{
|
||||
_state = _state with { IsHot = true };
|
||||
}
|
||||
|
||||
// Last returns Upper by default for single-value compatibility
|
||||
Last = new TValue(input.Time, top);
|
||||
@@ -146,7 +164,9 @@ public sealed class Mmchannel : ITValuePublisher
|
||||
public (TSeries Upper, TSeries Lower) Update(TBarSeries source)
|
||||
{
|
||||
if (source.Count == 0)
|
||||
{
|
||||
return (new TSeries([], []), new TSeries([], []));
|
||||
}
|
||||
|
||||
int len = source.Count;
|
||||
var tUpper = new List<long>(len);
|
||||
@@ -184,7 +204,9 @@ public sealed class Mmchannel : ITValuePublisher
|
||||
Reset();
|
||||
|
||||
if (source.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < source.Count; i++)
|
||||
{
|
||||
@@ -218,14 +240,25 @@ public sealed class Mmchannel : 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 (upper.Length < high.Length || lower.Length < high.Length)
|
||||
{
|
||||
throw new ArgumentException("Output spans must be at least as long as inputs", nameof(upper));
|
||||
}
|
||||
|
||||
int len = high.Length;
|
||||
if (len == 0) return;
|
||||
if (len == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Highest.Calculate(high, upper, period);
|
||||
Lowest.Calculate(low, lower, period);
|
||||
@@ -261,4 +294,4 @@ public sealed class Mmchannel : ITValuePublisher
|
||||
var results = indicator.Update(source);
|
||||
return (results, indicator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user