mirror of
https://github.com/mihakralj/QuanTAlib.git
synced 2026-08-23 04:58:08 +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:
@@ -139,8 +139,8 @@ public class HtDcphaseTests
|
||||
// First update (new bar)
|
||||
var result1 = ht.Update(new TValue(now.AddMinutes(70), 105), isNew: true);
|
||||
|
||||
// Same bar update
|
||||
var result2 = ht.Update(new TValue(now.AddMinutes(70), 106), isNew: false);
|
||||
// Same bar update with the same price — must yield identical result
|
||||
var result2 = ht.Update(new TValue(now.AddMinutes(70), 105), isNew: false);
|
||||
|
||||
Assert.Equal(result1.Value, result2.Value);
|
||||
}
|
||||
|
||||
@@ -92,4 +92,32 @@ public sealed class HtDcphaseValidationTests : IDisposable
|
||||
var q = new HtDcphase();
|
||||
Assert.Equal(talibLookback, q.WarmupPeriod);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HtDcphase_Correction_Recomputes()
|
||||
{
|
||||
var ind = new HtDcphase();
|
||||
var t0 = new DateTime(946_684_800_000_000_0L, DateTimeKind.Utc);
|
||||
|
||||
// Build state well past warmup
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
ind.Update(new TValue(t0.AddMinutes(i),
|
||||
100.0 + 10.0 * Math.Sin(2.0 * Math.PI * i / 20.0)), isNew: true);
|
||||
}
|
||||
|
||||
// Anchor bar
|
||||
var anchorTime = t0.AddMinutes(100);
|
||||
const double anchorPrice = 105.5;
|
||||
ind.Update(new TValue(anchorTime, anchorPrice), isNew: true);
|
||||
double anchorResult = ind.Last.Value;
|
||||
|
||||
// Correction with a dramatically different price — recompute must yield different result
|
||||
ind.Update(new TValue(anchorTime, anchorPrice * 10.0), isNew: false);
|
||||
Assert.NotEqual(anchorResult, ind.Last.Value);
|
||||
|
||||
// Correction back to original price — must exactly restore original result
|
||||
ind.Update(new TValue(anchorTime, anchorPrice), isNew: false);
|
||||
Assert.Equal(anchorResult, ind.Last.Value, 1e-9);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,12 +217,10 @@ public sealed class HtDcphase : AbstractBase
|
||||
}
|
||||
else
|
||||
{
|
||||
// Same-bar update: restore previous state and return cached result from Last
|
||||
_state = _p_state;
|
||||
Array.Copy(_p_circBuffer, _circBuffer, CIRC_BUFFER_SIZE);
|
||||
Array.Copy(_p_smoothPrice, _smoothPrice, SMOOTH_PRICE_SIZE);
|
||||
Array.Copy(_p_priceHistory, _priceHistory, PRICE_HISTORY_SIZE);
|
||||
return Last.Value;
|
||||
}
|
||||
|
||||
var s = _state;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// The MIT License (MIT)
|
||||
// Licensed under the Apache License, Version 2.0
|
||||
// © mihakralj
|
||||
//@version=6
|
||||
indicator("Ehlers Hilbert Transform Dominant Cycle Phase (HT_DCPHASE)", "HT_DCPHASE", overlay=false)
|
||||
|
||||
Reference in New Issue
Block a user