fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
using TradingPlatform.BusinessLayer;
|
|
|
|
|
|
|
|
|
|
namespace QuanTAlib.Tests;
|
|
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
public class MaxindexIndicatorTests
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_Constructor_SetsDefaults()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator();
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
Assert.Equal(14, indicator.Period);
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
Assert.Equal(SourceType.Close, indicator.Source);
|
|
|
|
|
Assert.True(indicator.ShowColdValues);
|
2026-03-12 12:34:16 -07:00
|
|
|
Assert.Equal("MAXINDEX - Rolling Maximum Index", indicator.Name);
|
|
|
|
|
Assert.True(indicator.SeparateWindow);
|
|
|
|
|
Assert.False(indicator.OnBackGround);
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_MinHistoryDepths_EqualsPeriod()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 20 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
Assert.Equal(20, indicator.MinHistoryDepths);
|
|
|
|
|
Assert.Equal(20, ((IWatchlistIndicator)indicator).MinHistoryDepths);
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_ShortName_IncludesPeriod()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 10 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
Assert.Equal("MAXINDEX(10)", indicator.ShortName);
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_Initialize_CreatesLineSeries()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 5 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
Assert.Single(indicator.LinesSeries);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_ProcessUpdate_HistoricalBar_ComputesValue()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 5 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
|
|
|
|
|
|
|
|
|
|
var args = new UpdateArgs(UpdateReason.HistoricalBar);
|
|
|
|
|
indicator.ProcessUpdate(args);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(1, indicator.LinesSeries[0].Count);
|
|
|
|
|
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_ProcessUpdate_NewBar_ComputesValue()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 5 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
|
|
|
|
|
indicator.HistoricalData.AddBar(now.AddMinutes(1), 102, 108, 100, 106);
|
|
|
|
|
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewBar));
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, indicator.LinesSeries[0].Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_ProcessUpdate_NewTick_ProcessesWithoutError()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 5 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
|
|
|
|
|
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.NewTick));
|
|
|
|
|
|
|
|
|
|
Assert.Equal(2, indicator.LinesSeries[0].Count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_MultipleUpdates_ProducesCorrectSequence()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 5 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
|
{
|
|
|
|
|
indicator.HistoricalData.AddBar(
|
|
|
|
|
now.AddMinutes(i),
|
2026-03-11 03:35:12 +00:00
|
|
|
100 + (i * 2),
|
|
|
|
|
105 + (i * 2),
|
|
|
|
|
95 + (i * 2),
|
|
|
|
|
102 + (i * 2));
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Assert.Equal(20, indicator.LinesSeries[0].Count);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
|
{
|
|
|
|
|
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(i)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_DifferentSourceTypes_Work()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
|
|
|
|
var sources = new[] { SourceType.Open, SourceType.High, SourceType.Low, SourceType.Close, SourceType.HL2, SourceType.HLC3 };
|
|
|
|
|
|
|
|
|
|
foreach (var source in sources)
|
|
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 5, Source = source };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
indicator.HistoricalData.AddBar(now, 100, 110, 90, 105);
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
|
|
|
|
|
Assert.True(double.IsFinite(indicator.LinesSeries[0].GetValue(0)),
|
|
|
|
|
$"Source {source} should produce finite value");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_Period_CanBeChanged()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 10 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
Assert.Equal(10, indicator.Period);
|
|
|
|
|
|
|
|
|
|
indicator.Period = 20;
|
|
|
|
|
Assert.Equal(20, indicator.Period);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_Uptrend_MaxAtCurrentBar()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
// In a monotonic uptrend, the max is always the current bar (bars-ago = 0)
|
|
|
|
|
var indicator = new MaxindexIndicator { Period = 5 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 10; i++)
|
|
|
|
|
{
|
2026-03-11 03:35:12 +00:00
|
|
|
double price = 100 + (i * 5);
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price);
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
double lastIndex = indicator.LinesSeries[0].GetValue(0);
|
|
|
|
|
Assert.Equal(0, lastIndex); // Max is at current bar → bars-ago = 0
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_Downtrend_MaxAtOldestBar()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
// In a monotonic downtrend, the max is the oldest bar (bars-ago = period-1)
|
|
|
|
|
var indicator = new MaxindexIndicator { Period = 5 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
for (int i = 0; i < 10; i++)
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
double price = 200 - (i * 5);
|
|
|
|
|
indicator.HistoricalData.AddBar(now.AddMinutes(i), price, price + 2, price - 2, price);
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
double lastIndex = indicator.LinesSeries[0].GetValue(0);
|
|
|
|
|
Assert.Equal(4, lastIndex); // Max is at oldest bar → bars-ago = period-1 = 4
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2026-03-12 12:34:16 -07:00
|
|
|
public void MaxindexIndicator_ShowColdValues_False_SetsNaN()
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = 10, ShowColdValues = false };
|
|
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
indicator.HistoricalData.AddBar(now, 100, 105, 95, 102);
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
|
|
|
|
|
Assert.True(double.IsNaN(indicator.LinesSeries[0].GetValue(0)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void MaxindexIndicator_DifferentPeriods_Work()
|
|
|
|
|
{
|
|
|
|
|
var periods = new[] { 2, 5, 10, 20 };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
|
|
|
|
|
foreach (var period in periods)
|
|
|
|
|
{
|
2026-03-12 12:34:16 -07:00
|
|
|
var indicator = new MaxindexIndicator { Period = period };
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
indicator.Initialize();
|
|
|
|
|
|
|
|
|
|
var now = DateTime.UtcNow;
|
|
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
for (int i = 0; i < period + 5; i++)
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
{
|
|
|
|
|
indicator.HistoricalData.AddBar(now.AddMinutes(i), 100 + i, 102 + i, 98 + i, 101 + i);
|
|
|
|
|
indicator.ProcessUpdate(new UpdateArgs(UpdateReason.HistoricalBar));
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-12 12:34:16 -07:00
|
|
|
Assert.Equal(period + 5, indicator.LinesSeries[0].Count);
|
fix(docs): correct .md documentation across errors, dynamics, filters, forecasts, momentum, numerics, oscillators, reversals, statistics, trends, volatility, volume
2026-03-10 18:38:23 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|