feat: add new indicators (Decay, Edecay, MinusDi, MinusDm, PlusDi, PlusDm, Maxindex, Minindex, Sarext) and update pine scripts, core libs, validation tests, and python bindings

This commit is contained in:
Miha Kralj
2026-03-09 13:45:46 -07:00
parent 8e43d62cbb
commit 031f1b5fe6
491 changed files with 6156 additions and 5590 deletions
+28
View File
@@ -233,4 +233,32 @@ public class FftValidationTests
$"Output at {i} must be finite, got {dst[i]}");
}
}
[Fact]
public void Fft_Correction_StateRestores()
{
// The Hanning window maps idx=0 to the newest bar and _hanning[0]=0, so
// corrections to the anchor bar carry zero spectral weight. isNew=false
// determinism is still correct: restoring the original value reproduces the
// original result exactly regardless of any intermediate correction.
var ind = new Fft(windowSize: 32, maxPeriod: 16);
var t0 = DateTime.MinValue;
for (int i = 0; i < 50; i++)
{
ind.Update(new TValue(t0.AddSeconds(i), 100.0 + 10.0 * Math.Sin(2 * Math.PI * i / 8.0)));
}
var anchorTime = t0.AddSeconds(50);
const double anchorPrice = 100.0;
ind.Update(new TValue(anchorTime, anchorPrice), isNew: true);
double anchorResult = ind.Last.Value;
// Apply an arbitrary correction — spectral output is unchanged due to zero Hanning weight
ind.Update(new TValue(anchorTime, anchorPrice * 100), isNew: false);
// Restoring to original must exactly reproduce the original result
ind.Update(new TValue(anchorTime, anchorPrice), isNew: false);
Assert.Equal(anchorResult, ind.Last.Value, 1e-9);
}
}
+8
View File
@@ -212,6 +212,14 @@ public sealed class Fft : AbstractBase
return result;
}
/// <summary>
/// Primes the indicator with historical values.
/// </summary>
/// <remarks>
/// Synthetic timestamps are generated by subtracting <c>step × source.Length</c>
/// from <see cref="DateTime.UtcNow"/>. For deterministic or replay-safe pipelines
/// use <see cref="Update(TValue, bool)"/> directly with explicit timestamps.
/// </remarks>
public override void Prime(ReadOnlySpan<double> source, TimeSpan? step = null)
{
TimeSpan interval = step ?? TimeSpan.FromSeconds(1);
+1 -1
View File
@@ -1,4 +1,4 @@
// The MIT License (MIT)
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("FFT Dominant Cycle (Radix-2 FFT)", "FFT-DC", overlay=false, precision=2)