Files
Miha Kralj aec3a64e4e feat(dynamics): add PTA - Ehlers Precision Trend Analysis
TASC Sep 2024. Dual 2-pole Butterworth highpass bandpass for
near-zero-lag trend extraction. HP(long) - HP(short) preserves
cycles between shortPeriod and longPeriod.

- Core: Pta.cs with O(1) streaming, Span batch, state rollback
- Quantower: PtaIndicator adapter with LineSeries + SetValue
- Tests: 31 lib + 11 Quantower (all passing)
- Pine: pta.pine PineScript v6 reference
- Docs: Pta.md canonical template v3
- Python: Exports.Generated.cs + _bridge.py + dynamics.py
- Indexes: _sidebar.md, lib/_index.md, dynamics/_index.md,
  docs/indicators.md, docs/pinescript.md
2026-03-17 17:25:17 -07:00

38 lines
1.9 KiB
Plaintext

// PTA: Ehlers Precision Trend Analysis
// Category: Dynamics
// Based on: John F. Ehlers, "Precision Trend Analysis," TASC September 2024
//
// Dual highpass filter bandpass approach for near-zero-lag trend extraction.
// Trend = HP(longPeriod) - HP(shortPeriod)
// where HP is a 2-pole Butterworth highpass filter.
// Preserves cyclic components between shortPeriod and longPeriod.
// Output: zero-centered, positive = uptrend, negative = downtrend.
//@version=6
indicator("PTA - Ehlers Precision Trend Analysis", shorttitle="PTA", overlay=false)
// ── Inputs ──────────────────────────────────────────────────────
int longPeriod = input.int(250, "Long Period", minval=3)
int shortPeriod = input.int(40, "Short Period", minval=2)
// ── Highpass Filter Function ────────────────────────────────────
highpass(float src, float period) =>
float a1 = math.exp(-1.414 * math.pi / period)
float b1 = 2.0 * a1 * math.cos(1.414 * math.pi / period)
float c2 = b1
float c3 = -a1 * a1
float c1 = (1.0 + c2 - c3) * 0.25
float hp = 0.0
if bar_index >= 2
hp := c1 * (src - 2.0 * src[1] + src[2]) + c2 * nz(hp[1]) + c3 * nz(hp[2])
hp
// ── Calculations ────────────────────────────────────────────────
float hp1 = highpass(close, longPeriod)
float hp2 = highpass(close, shortPeriod)
float trend = hp1 - hp2
// ── Plots ───────────────────────────────────────────────────────
plot(trend, "PTA", color.red, 2)
hline(0, "Zero", color.gray, hline.style_dotted)