docs: remove C# Implementation Considerations sections, clean up temp scripts, reorganize test files

- Remove 'C# Implementation Considerations' sections from 34 indicator .md files
- Delete 29 temp PowerShell scripts (_fix_mojibake.ps1, _hex_scan.ps1, etc.)
- Move test files into tests/ subdirectories for consistent project structure
- Add trader-focused bullet points to indicator documentation
This commit is contained in:
Miha Kralj
2026-03-12 12:34:16 -07:00
parent 8937b0c0fa
commit 060649192f
1149 changed files with 1780 additions and 3316 deletions
@@ -0,0 +1,123 @@
using TradingPlatform.BusinessLayer;
using QuanTAlib;
namespace QuanTAlib.Tests;
public class SuperIndicatorTests
{
[Fact]
public void SuperIndicator_Constructor_SetsDefaults()
{
var indicator = new SuperIndicator();
Assert.Equal(10, indicator.Period);
Assert.Equal(3.0, indicator.Multiplier);
Assert.True(indicator.ShowColdValues);
Assert.Equal("SuperTrend", indicator.Name);
Assert.False(indicator.SeparateWindow);
Assert.True(indicator.OnBackGround);
}
[Fact]
public void SuperIndicator_MinHistoryDepths_EqualsZero()
{
var indicator = new SuperIndicator { Period = 20 };
Assert.Equal(0, SuperIndicator.MinHistoryDepths);
IWatchlistIndicator watchlistIndicator = indicator;
Assert.Equal(0, watchlistIndicator.MinHistoryDepths);
}
[Fact]
public void SuperIndicator_ShortName_IncludesParameters()
{
var indicator = new SuperIndicator { Period = 20, Multiplier = 2.5 };
indicator.Initialize();
Assert.Contains("Super", indicator.ShortName, StringComparison.Ordinal);
Assert.Contains("20", indicator.ShortName, StringComparison.Ordinal);
Assert.Contains("2.5", indicator.ShortName, StringComparison.Ordinal);
}
[Fact]
public void SuperIndicator_SourceCodeLink_IsValid()
{
var indicator = new SuperIndicator();
Assert.Contains("github.com", indicator.SourceCodeLink, StringComparison.Ordinal);
Assert.Contains("Super.Quantower.cs", indicator.SourceCodeLink, StringComparison.Ordinal);
}
[Fact]
public void SuperIndicator_Initialize_CreatesInternalSuper()
{
var indicator = new SuperIndicator { Period = 14 };
// Initialize should not throw
indicator.Initialize();
// After init, line series should exist (SuperTrend, Upper, Lower)
Assert.Equal(3, indicator.LinesSeries.Count);
}
[Fact]
public void SuperIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
{
var indicator = new SuperIndicator { Period = 5 };
indicator.Initialize();
// Add historical data
var now = DateTime.UtcNow;
// Need enough bars for Period
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);
}
// Line series should have a value (either Up or Down)
// 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));
}
[Fact]
public void SuperIndicator_ProcessUpdate_NewBar_ComputesValue()
{
var indicator = new SuperIndicator { Period = 5 };
indicator.Initialize();
var now = DateTime.UtcNow;
for (int i = 0; i < 20; i++)
{
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 110 + i, 90 + i, 105 + i);
}
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));
Assert.Equal(2, indicator.LinesSeries[0].Count);
}
[Fact]
public void SuperIndicator_Parameters_CanBeChanged()
{
var indicator = new SuperIndicator { Period = 14 };
Assert.Equal(14, indicator.Period);
indicator.Period = 20;
indicator.Multiplier = 4.0;
Assert.Equal(20, indicator.Period);
Assert.Equal(4.0, indicator.Multiplier);
Assert.Equal(0, SuperIndicator.MinHistoryDepths);
}
}
+186
View File
@@ -0,0 +1,186 @@
namespace QuanTAlib;
public class SuperTests
{
[Fact]
public void BasicCalculation_DoesNotCrash()
{
var super = new Super(10, 3.0);
var gbm = new GBM();
var bars = gbm.Fetch(1000, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
for (int i = 0; i < bars.Count; i++)
{
super.Update(bars[i]);
}
Assert.True(double.IsFinite(super.Last.Value));
}
[Fact]
public void IsNew_Consistency()
{
var super = new Super(10, 3.0);
var gbm = new GBM();
var bars = gbm.Fetch(100, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
// Feed first 99
for (int i = 0; i < 99; i++)
{
super.Update(bars[i]);
}
// Update with 100th point (isNew=true)
super.Update(bars[99], true);
// Update with modified 100th point (isNew=false)
var modifiedBar = new TBar(bars[99].Time, bars[99].Open, bars[99].High + 1.0, bars[99].Low - 1.0, bars[99].Close, bars[99].Volume);
var val2 = super.Update(modifiedBar, false);
// Create new instance and feed up to modified
var super2 = new Super(10, 3.0);
for (int i = 0; i < 99; i++)
{
super2.Update(bars[i]);
}
var val3 = super2.Update(modifiedBar, true);
Assert.Equal(val3.Value, val2.Value, 1e-9);
Assert.Equal(super2.UpperBand.Value, super.UpperBand.Value, 1e-9);
Assert.Equal(super2.LowerBand.Value, super.LowerBand.Value, 1e-9);
Assert.Equal(super2.IsBullish, super.IsBullish);
}
[Fact]
public void Reset_Works()
{
var super = new Super(10, 3.0);
var gbm = new GBM();
var bars = gbm.Fetch(100, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
for (int i = 0; i < bars.Count; i++)
{
super.Update(bars[i]);
}
super.Reset();
Assert.Equal(0, super.Last.Value);
Assert.False(super.IsHot);
// Feed again
for (int i = 0; i < bars.Count; i++)
{
super.Update(bars[i]);
}
Assert.True(double.IsFinite(super.Last.Value));
}
[Fact]
public void TBarSeries_Update_Matches_Streaming()
{
var super = new Super(10, 3.0);
var gbm = new GBM();
var bars = gbm.Fetch(200, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
var streamingResults = new List<double>();
for (int i = 0; i < bars.Count; i++)
{
streamingResults.Add(super.Update(bars[i]).Value);
}
var super2 = new Super(10, 3.0);
var seriesResults = super2.Update(bars);
Assert.Equal(streamingResults.Count, seriesResults.Count);
for (int i = 0; i < seriesResults.Count; i++)
{
// Handle NaN comparison
if (double.IsNaN(streamingResults[i]))
{
Assert.True(double.IsNaN(seriesResults.Values[i]));
}
else
{
Assert.Equal(streamingResults[i], seriesResults.Values[i], 1e-9);
}
}
}
[Fact]
public void Warmup_Handling()
{
var super = new Super(10, 3.0);
var gbm = new GBM();
var bars = gbm.Fetch(20, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
// First 10 bars should be NaN
for (int i = 0; i < 10; i++)
{
var result = super.Update(bars[i]);
Assert.True(double.IsNaN(result.Value), $"Bar {i} should be NaN");
Assert.False(super.IsHot);
}
// 11th bar (index 10) should be valid
var result11 = super.Update(bars[10]);
Assert.True(double.IsFinite(result11.Value), "Bar 10 should be finite");
Assert.True(super.IsHot);
}
[Fact]
public void Constructor_InvalidParameters_ThrowsArgumentOutOfRangeException()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Super(0, 3.0));
Assert.Throws<ArgumentOutOfRangeException>(() => new Super(-1, 3.0));
Assert.Throws<ArgumentOutOfRangeException>(() => new Super(10, 0));
Assert.Throws<ArgumentOutOfRangeException>(() => new Super(10, -1.0));
}
[Fact]
public void StaticBatch_Matches_Streaming()
{
var gbm = new GBM();
var bars = gbm.Fetch(200, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
var super = new Super(10, 3.0);
var streamingResults = new List<double>();
for (int i = 0; i < bars.Count; i++)
{
streamingResults.Add(super.Update(bars[i]).Value);
}
var staticResults = Super.Batch(bars, 10, 3.0);
Assert.Equal(streamingResults.Count, staticResults.Count);
for (int i = 0; i < staticResults.Count; i++)
{
if (double.IsNaN(streamingResults[i]))
{
Assert.True(double.IsNaN(staticResults.Values[i]));
}
else
{
Assert.Equal(streamingResults[i], staticResults.Values[i], 1e-9);
}
}
}
[Fact]
public void Chainability_Works()
{
var super = new Super(10, 3.0);
var gbm = new GBM();
var bars = gbm.Fetch(10, DateTime.UtcNow.Ticks, TimeSpan.FromMinutes(1));
// Test TBarSeries chain
var result = super.Update(bars);
Assert.NotNull(result);
Assert.IsType<TSeries>(result);
// Test TBar chain (returns TValue)
var result2 = super.Update(bars[0]);
Assert.IsType<TValue>(result2);
}
}
@@ -0,0 +1,67 @@
using Skender.Stock.Indicators;
using QuanTAlib.Tests;
namespace QuanTAlib;
public sealed class SuperValidationTests : IDisposable
{
private readonly ValidationTestData _data;
public SuperValidationTests()
{
_data = new ValidationTestData();
}
public void Dispose()
{
_data.Dispose();
}
[Fact]
public void MatchesSkender()
{
var super = new Super(10, 3.0);
var results = new List<double>();
var upper = new List<double>();
var lower = new List<double>();
for (int i = 0; i < _data.Bars.Count; i++)
{
var res = super.Update(_data.Bars[i]);
results.Add(res.Value);
upper.Add(super.UpperBand.Value);
lower.Add(super.LowerBand.Value);
}
// Skender uses GetSuperTrend
var skenderResults = _data.SkenderQuotes.GetSuperTrend(10, 3.0).ToList();
Assert.Equal(_data.Bars.Count, skenderResults.Count);
for (int i = 0; i < _data.Bars.Count; i++)
{
// Skender returns null for warmup
if (skenderResults[i].SuperTrend == null)
{
Assert.True(double.IsNaN(results[i]));
continue;
}
Assert.Equal((double)skenderResults[i].SuperTrend!, results[i], ValidationHelper.SkenderTolerance);
if (skenderResults[i].UpperBand != null)
{
Assert.Equal((double)skenderResults[i].UpperBand!, upper[i], ValidationHelper.SkenderTolerance);
}
if (skenderResults[i].LowerBand != null)
{
Assert.Equal((double)skenderResults[i].LowerBand!, lower[i], ValidationHelper.SkenderTolerance);
}
}
}
// Note: OoplesFinance implementation of SuperTrend diverges significantly from Skender and QuanTAlib.
// This is likely due to different initialization logic for ATR or the SuperTrend state itself.
// Therefore, we do not validate against Ooples for SuperTrend.
}