OPEN-SOURCE SCRIPT

Zero Lag Trend Strategy (MTF)

223
🧠 Strategy Overview

The Zero Lag Trend Signals Strategy (MTF) is a high-precision, multi-timeframe trend-following system designed for traders seeking early trend entries and intelligent exits. Built around ZLEMA-based signal detection, based on the original indicator Zero Lag Trend Signals (MTF) from AlgoAlpha, now built as a strategy with several improvements for Exit Criteria include RR, ATR Stop Loss, Trailing stop loss, etc. See below.

This momentum strategy works much better for higher timeframes, typically 4 hours or higher. This particular combination only contains 57 trades because this captures larger trend moves. The dataset contains realistic commission and slippage. You can try to run this on a smaller timeframe, but you will need to try different combinations of length, band multiplier, risk-reward ratios, and other stop loss criteria.

🔍 Key Components
1️⃣ ZLEMA Trend Engine
ZLEMA (Zero-Lag EMA) forms the foundation of the trend signal system.
Detects bullish and bearish momentum by analyzing price action crossing custom ZLEMA bands.
Optional confirmation using 5-bar ZLEMA slope filters (up/down trends) ensures high-conviction entries.

2️⃣ Volatility-Based Signal Bands
Dynamic bands are calculated using ATR (volatility) stretched over 3× period length.
These bands define entry zones (outside the bands) and trend strength.
Price crossing above/below the bands triggers trend change detection.

3️⃣ Entry Logic
Primary long entries occur when price crosses above the upper ZLEMA band.
Short entries (optional) trigger on downside cross under the lower band.
Re-entry logic allows continuation trades during strong trends.
Filters include date range, ZLEMA confirmation, and previous position state.

4️⃣ Exit Logic & Risk Management
Supports multiple customizable exit mechanisms:
🔺 Stop-Loss & Take-Profit
ATR-Based SL/TP: Uses ATR multipliers to dynamically set levels based on volatility.
Fixed Risk-Reward TP: Targets profit based on predefined RR ratios.
Break-Even Logic: Automatically moves SL to entry once a threshold RR is hit.
EMA Exit: Optional trailing exit based on price vs. short EMA.

🔀 Trailing Stop
Follows price action using a trailing ATR-based buffer that tightens with trend movement.

🔁 Trend-Based Exit
Automatically closes positions when the detected trend reverses.

5️⃣ Multi-Option Trade Filtering
Enable/disable short trades, ZLEMA confirmations, re-entries, etc.
Time-based backtesting filters for isolating performance within custom periods.

6️⃣ Visual Feedback & Annotations
Trend shading overlays: Green for bullish, red for bearish zones.
Up/Down triangle markers show when ZLEMA is rising/falling for 5 bars.
Stop-loss, TP, trailing lines drawn dynamically on the chart.
Floating stats table displays live performance (PnL, win %, GOA, drawdown, etc.).
Trade log labels annotate closed trades with entry/exit, duration, and reason.

7️⃣ CSV Export Integration
Seamless export of trade data including:
Entry/exit prices
Bars held
Encoded exit reasons
Enables post-processing or integration with external optimizers.

⚙️ Configurable Parameters
All key elements are customizable:
Entry band length and multiplier
ATR lengths, multipliers, TP/SL, trailing stop, break-even
Profit target RR ratio
Toggle switches for confirmations, trade types, and exit methods

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.