OPEN-SOURCE SCRIPT

Empirical Mode Decomposition Trend Helix [forexobroker]

330
Empirical Mode Decomposition Trend Helix [forexobroker] applies a simplified EMD sift to separate price into a trend residual and a high-frequency intrinsic mode (IMF1). Rather than relying on a fixed-length moving average, the trend is built from the mean of local upper and lower envelopes, then re-sifted for smoothness. Trade signals fire only when the high-frequency component crosses zero in the direction of the larger trend slope. The unique angle is bringing a Huang-style adaptive decomposition concept into Pine using rolling extrema as a tractable envelope proxy.

🔶 ALGORITHM

1. Take rolling local maxima and minima of close over the extrema window (default 10) using highest/lowest.
2. Smooth each into an upper envelope and a lower envelope by SMA of the envelope smoothing length (default 5).
3. Mean envelope m_t = (upper + lower) / 2 is the trend residual for this iteration.
4. Repeat the sift the configured number of iterations (default 2), using the previous m_t as the input each round.
5. IMF1 (high-frequency component) = close minus the final trend.
6. Slope of the trend over the slope lookback (default 5 bars) defines direction; bullish if slope greater than zero (plus min-slope threshold), bearish if less than minus the threshold.
7. Signals: IMF1 zero-crossings aligned with trend direction.

🔶 SIGNAL LOGIC

- Buy: IMF1 crosses above zero AND trend slope is positive AND position is not already long AND session filter passes AND cooldown bars elapsed AND barstate.isconfirmed.
- Sell: IMF1 crosses below zero AND trend slope is negative AND position is not already short AND session filter passes AND cooldown bars elapsed AND barstate.isconfirmed.

Cross-direction confirmation prevents trading mean-reversion bounces against the underlying trend residual.

🔶 INPUTS

- EMD Sift group: extrema window default 10, envelope smooth default 5, sift iterations default 2, slope lookback default 5.
- Signal Logic group: cooldown bars default 15, min slope (price units) default 0.
- Filters group: session restriction default 0000-2400.
- Visual group: show trend helix, dashboard, 3-layer glow, helix gradient colors, buy/sell colors, dashboard background.

🔶 ALERTS

EMD Buy, EMD Sell, EMD Any Signal, EMD IMF1 Up, EMD IMF1 Down, EMD Trend Turn Up, EMD Trend Turn Dn, EMD Big Excursion, EMD Close Over, EMD Close Under, EMD Webhook JSON.

🔶 LIMITATIONS

- This is a simplified EMD: rolling extrema and SMA envelopes are not the cubic-spline envelopes of formal Huang EMD; expect smoother but less curvature-aware decomposition.
- The sift uses fixed iterations rather than a stoppage criterion, so it does not guarantee a true zero-mean IMF.
- Trend slope is a local linear estimate; long pauses or gaps can flip the slope sign transiently.
- The envelope smoothing introduces lag of roughly half the envelope window into the trend output.
- Signals require simultaneous IMF zero-cross and slope alignment, so during sideways markets the indicator will be quiet by design.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.