mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-21 20:18:05 +00:00
style patterns
This commit is contained in:
@@ -155,4 +155,4 @@ public class AtrpIndicatorTests
|
||||
var indicator = new AtrpIndicator();
|
||||
Assert.Contains("percentage", indicator.Description, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,4 +48,4 @@ public sealed class AtrpIndicator : Indicator, IWatchlistIndicator
|
||||
|
||||
_series.SetValue(result.Value, _atrp.IsHot, ShowColdValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,10 @@ public class AtrpTests
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(50, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
|
||||
foreach (var bar in bars) atrp.Update(bar);
|
||||
foreach (var bar in bars)
|
||||
{
|
||||
atrp.Update(bar);
|
||||
}
|
||||
|
||||
double lastVal = atrp.Last.Value;
|
||||
Assert.NotEqual(0, lastVal);
|
||||
@@ -449,4 +452,4 @@ public class AtrpTests
|
||||
|
||||
Assert.True(double.IsNaN(result.Value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -347,4 +347,4 @@ public sealed class AtrpValidationTests : IDisposable
|
||||
}
|
||||
_output.WriteLine("ATRP Batch(TSeries) validated successfully against Ooples ATR");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,9 @@ public sealed class Atrp : AbstractBase
|
||||
public Atrp(int period)
|
||||
{
|
||||
if (period <= 0)
|
||||
{
|
||||
throw new ArgumentException("Period must be greater than 0", nameof(period));
|
||||
}
|
||||
|
||||
_alpha = 1.0 / period;
|
||||
_decay = 1.0 - _alpha;
|
||||
@@ -135,18 +137,45 @@ public sealed class Atrp : AbstractBase
|
||||
public TValue Update(TBar input, bool isNew = true)
|
||||
{
|
||||
if (isNew)
|
||||
{
|
||||
_p_state = _state;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state = _p_state;
|
||||
}
|
||||
|
||||
// Get valid values with last-value substitution
|
||||
double high = input.High;
|
||||
double low = input.Low;
|
||||
double close = input.Close;
|
||||
|
||||
if (double.IsFinite(high)) _state.LastValidHigh = high; else high = _state.LastValidHigh;
|
||||
if (double.IsFinite(low)) _state.LastValidLow = low; else low = _state.LastValidLow;
|
||||
if (double.IsFinite(close)) _state.LastValidClose = close; else close = _state.LastValidClose;
|
||||
if (double.IsFinite(high))
|
||||
{
|
||||
_state.LastValidHigh = high;
|
||||
}
|
||||
else
|
||||
{
|
||||
high = _state.LastValidHigh;
|
||||
}
|
||||
|
||||
if (double.IsFinite(low))
|
||||
{
|
||||
_state.LastValidLow = low;
|
||||
}
|
||||
else
|
||||
{
|
||||
low = _state.LastValidLow;
|
||||
}
|
||||
|
||||
if (double.IsFinite(close))
|
||||
{
|
||||
_state.LastValidClose = close;
|
||||
}
|
||||
else
|
||||
{
|
||||
close = _state.LastValidClose;
|
||||
}
|
||||
|
||||
// Handle case where no valid values yet
|
||||
if (double.IsNaN(close))
|
||||
@@ -212,7 +241,10 @@ public sealed class Atrp : AbstractBase
|
||||
/// </summary>
|
||||
public TSeries Update(TBarSeries source)
|
||||
{
|
||||
if (source.Count == 0) return [];
|
||||
if (source.Count == 0)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
var t = new List<long>(source.Count);
|
||||
var v = new List<double>(source.Count);
|
||||
@@ -249,4 +281,4 @@ public sealed class Atrp : AbstractBase
|
||||
var atrp = new Atrp(period);
|
||||
return atrp.Update(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user