mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-24 13:38:05 +00:00
refactoring
This commit is contained in:
@@ -58,7 +58,7 @@ public class SuperIndicatorTests
|
||||
indicator.Initialize();
|
||||
|
||||
// After init, line series should exist (Up and Down)
|
||||
Assert.Equal(2, indicator.LinesSeries.Length);
|
||||
Assert.Equal(2, indicator.LinesSeries.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -73,7 +73,7 @@ public class SuperIndicatorTests
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i);
|
||||
|
||||
|
||||
// Process update for each bar to simulate history loading
|
||||
var args = new UpdateArgs(UpdateReason.HistoricalBar);
|
||||
indicator.ProcessUpdate(args);
|
||||
@@ -83,7 +83,7 @@ public class SuperIndicatorTests
|
||||
// One should be NaN, other should be value, or both NaN if cold
|
||||
double up = indicator.LinesSeries[0].GetValue(0);
|
||||
double down = indicator.LinesSeries[1].GetValue(0);
|
||||
|
||||
|
||||
Assert.True(double.IsFinite(up) || double.IsFinite(down));
|
||||
}
|
||||
|
||||
@@ -100,7 +100,7 @@ public class SuperIndicatorTests
|
||||
}
|
||||
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
||||
|
||||
|
||||
// Add new bar
|
||||
indicator.HistoricalData.AddBar(now.AddMinutes(20), 120, 130, 110, 125);
|
||||
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
|
||||
|
||||
@@ -30,10 +30,10 @@ public class SuperIndicator : Indicator, IWatchlistIndicator
|
||||
SeparateWindow = false;
|
||||
Name = "SuperTrend";
|
||||
Description = "Trend-following indicator using ATR";
|
||||
|
||||
|
||||
UpSeries = new(name: "SuperTrend Up", color: Color.Green, width: 2, style: LineStyle.Solid);
|
||||
DownSeries = new(name: "SuperTrend Down", color: Color.Red, width: 2, style: LineStyle.Solid);
|
||||
|
||||
|
||||
AddLineSeries(UpSeries);
|
||||
AddLineSeries(DownSeries);
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class SuperIndicator : Indicator, IWatchlistIndicator
|
||||
TBar bar = this.GetInputBar(args);
|
||||
|
||||
TValue result = _super!.Update(bar, isNew);
|
||||
|
||||
|
||||
if (!_super.IsHot && !ShowColdValues)
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -142,7 +142,7 @@ public class SuperTests
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StaticCalculate_Matches_Streaming()
|
||||
public void StaticBatch_Matches_Streaming()
|
||||
{
|
||||
var gbm = new GBM();
|
||||
var bars = gbm.Fetch(200, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
|
||||
@@ -154,7 +154,7 @@ public class SuperTests
|
||||
streamingResults.Add(super.Update(bars[i]).Value);
|
||||
}
|
||||
|
||||
var staticResults = Super.Calculate(bars, 10, 3.0);
|
||||
var staticResults = Super.Batch(bars, 10, 3.0);
|
||||
|
||||
Assert.Equal(streamingResults.Count, staticResults.Count);
|
||||
for (int i = 0; i < staticResults.Count; i++)
|
||||
|
||||
@@ -60,6 +60,8 @@ public sealed class Super : ITValuePublisher
|
||||
/// </summary>
|
||||
public bool IsHot => _sampleCount > _period;
|
||||
|
||||
public int WarmupPeriod => _period + 1;
|
||||
|
||||
public Super(int period = 10, double multiplier = 3.0)
|
||||
{
|
||||
if (period <= 0)
|
||||
@@ -196,7 +198,7 @@ public sealed class Super : ITValuePublisher
|
||||
Last = new TValue(input.Time, superTrend);
|
||||
UpperBand = new TValue(input.Time, upperBand);
|
||||
LowerBand = new TValue(input.Time, lowerBand);
|
||||
|
||||
|
||||
Pub?.Invoke(Last);
|
||||
return Last;
|
||||
}
|
||||
@@ -218,7 +220,7 @@ public sealed class Super : ITValuePublisher
|
||||
return new TSeries(t, v);
|
||||
}
|
||||
|
||||
public static TSeries Calculate(TBarSeries source, int period = 10, double multiplier = 3.0)
|
||||
public static TSeries Batch(TBarSeries source, int period = 10, double multiplier = 3.0)
|
||||
{
|
||||
var indicator = new Super(period, multiplier);
|
||||
return indicator.Update(source);
|
||||
|
||||
@@ -51,6 +51,14 @@ Console.WriteLine($"Lower Band: {super.LowerBand.Value}");
|
||||
Console.WriteLine($"Is Bullish: {super.IsBullish}");
|
||||
```
|
||||
|
||||
### Batch Calculation
|
||||
|
||||
```csharp
|
||||
// Calculate SuperTrend for an entire series
|
||||
TBarSeries bars = ...;
|
||||
TSeries result = Super.Batch(bars, period: 10, multiplier: 3.0);
|
||||
```
|
||||
|
||||
### Bar Correction (isNew)
|
||||
|
||||
```csharp
|
||||
|
||||
Reference in New Issue
Block a user