mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-22 20:48:04 +00:00
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:
@@ -215,4 +215,35 @@ public sealed class SqueezeValidationTests
|
||||
Assert.Equal(sqStream.Momentum, sqBatch.Momentum, precision: 8);
|
||||
Assert.Equal(sqStream.SqueezeOn, sqBatch.SqueezeOn);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Squeeze_Correction_Recomputes()
|
||||
{
|
||||
var ind = new Squeeze(period: 20);
|
||||
long t0 = TimeSpan.TicksPerSecond;
|
||||
|
||||
// Build state well past warmup (WarmupPeriod = 20)
|
||||
for (int i = 0; i < 50; i++)
|
||||
{
|
||||
double p = 100.0 + i * 0.5;
|
||||
ind.Update(new TBar(t0 + i * TimeSpan.TicksPerSecond, p, p + 1, p - 1, p, 1000), isNew: true);
|
||||
}
|
||||
|
||||
// Anchor bar
|
||||
long anchorTime = t0 + 50 * TimeSpan.TicksPerSecond;
|
||||
var anchorBar = new TBar(anchorTime, 125.0, 126.0, 124.0, 125.0, 1000);
|
||||
ind.Update(anchorBar, isNew: true);
|
||||
double anchorMomentum = ind.Momentum;
|
||||
bool anchorSqueezeOn = ind.SqueezeOn;
|
||||
|
||||
// Correction with dramatically different values — Momentum must change
|
||||
var corruptBar = new TBar(anchorTime, 1250.0, 1260.0, 1240.0, 1250.0, 1000);
|
||||
ind.Update(corruptBar, isNew: false);
|
||||
Assert.NotEqual(anchorMomentum, ind.Momentum);
|
||||
|
||||
// Correction back to original — both outputs must restore exactly
|
||||
ind.Update(anchorBar, isNew: false);
|
||||
Assert.Equal(anchorMomentum, ind.Momentum, 1e-9);
|
||||
Assert.Equal(anchorSqueezeOn, ind.SqueezeOn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,6 +369,11 @@ public sealed class Squeeze : ITValuePublisher
|
||||
SqueezeOn = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Span-based batch Squeeze calculation. Populates both the momentum and squeeze-state output spans.
|
||||
/// </summary>
|
||||
/// <param name="momOut">Output span for Squeeze momentum values (linear regression of detrended price).</param>
|
||||
/// <param name="sqOut">Output span for squeeze-state values (positive when Bollinger Bands are inside Keltner Channel).</param>
|
||||
public static void Batch(
|
||||
ReadOnlySpan<double> high,
|
||||
ReadOnlySpan<double> low,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// The MIT License (MIT)
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Squeeze Momentum (SQUEEZE)", "SQUEEZE", overlay=false)
|
||||
|
||||
Reference in New Issue
Block a user