OPEN-SOURCE SCRIPT

Confluence Engine Strategy [JOAT]

1 264
Confluence Engine Strategy [JOAT]

Overview

Confluence Engine Strategy is a fully automated Pine Script v6 strategy that combines four independent signal layers into a single numeric confluence score (0–100) before executing any trade. Entries require genuine agreement between linear regression momentum, dual EMA trend regime, ATR volatility state, and higher-timeframe bias. All exits are ATR-proportional with configurable take-profit and stop-loss multiples, plus a bar-based timeout and a trend-flip emergency exit. Commission (0.05% per side) and slippage (2 ticks) are configured for realistic backtesting.

Why Require Confluence?

Single-condition strategies (e.g., "go long when RSI crosses 50") produce entries in every conceivable market environment — ranging, trending, low-volatility, high-volatility — most of which are statistically unfavourable for that signal type. Requiring multiple independent conditions to agree simultaneously filters the entry universe down to the high-probability subset where each individual indicator is operating in its most favourable context. The Confluence Engine makes this filtering explicit and auditable through a numeric score.

תמונת-בזק

Signal Layer 1 — Linear Regression Crossover

The primary entry trigger mirrors the Regression Flux Candles logic: a 21-bar linear regression of close (LR close) crossing above/below an 8-bar SMA of itself. The LR approach de-noises price before computing the crossover, significantly reducing the whipsaw rate compared to raw close-based SMA crossovers.

Signal Layer 2 — Dual EMA Trend Regime

Two exponential moving averages (fast: 21-period, slow: 55-period) define the trend regime. Long entries are only considered when the fast EMA is above the slow EMA; short entries only when fast is below slow. This prevents the LR crossover from triggering counter-trend entries in established trends — one of the most common sources of false signals in momentum strategies.

Signal Layer 3 — ATR Volatility State

The current 14-bar ATR is compared to a 50-bar ATR. Entries are only accepted when the current ATR is above a configurable fraction of the slow ATR (default 0.7). This volatility gate blocks trades during compression phases — low-volatility periods where breakouts frequently fail. The strategy only participates when directional energy is present.

Signal Layer 4 — Higher-Timeframe Bias

A higher-timeframe linear regression direction is fetched via request.security() with lookahead_off. The HTF LR close vs. HTF LR open comparison gives a single bullish/bearish vote from the higher timeframe. Long entries receive a confluence bonus when the HTF agrees; short entries receive a bonus when the HTF is bearish. This aligns trade direction with the prevailing macro bias.

Confluence Score and Threshold

Each of the four layers contributes points to the confluence score:
- LR crossover in direction: +30
- Dual EMA alignment: +25
- ATR volatility expansion: +20
- HTF bias alignment: +25

Maximum score: 100. The minimum required score to execute an entry (default 60) filters out entries where fewer than three layers agree. This threshold is adjustable — lower it for more signals, raise it for higher selectivity.

Entry Logic

Long: LR crossover up AND the accumulated confluence score >= minimum AND the signal is on a confirmed bar AND warmup has elapsed AND no position is currently open AND no cooldown bars remain.

Short: LR crossover down AND confluence >= minimum AND same guards.

A configurable cooldown period (default 5 bars) prevents re-entering the same direction immediately after an exit, avoiding overtrading in choppy conditions.

Exit Logic — Four Exit Conditions

1. ATR Take-Profit: Long exits when close >= entry + ATR × TP multiplier (default 2.0). Short exits below entry - ATR × TP.
2. ATR Stop-Loss: Long exits when close <= entry - ATR × SL multiplier (default 1.2). Short exits above entry + ATR × SL.
3. Bar Timeout: If neither TP nor SL is hit within a configurable number of bars (default 20), the trade exits at market — preventing capital from being locked in stalled trades.
4. Trend Flip Exit: If the dual EMA regime flips against the trade direction (fast EMA crosses slow EMA), the trade exits immediately — recognising that the structural basis for the entry has been invalidated.

Strategy Properties

- Initial capital: $10,000
- Order size: 10% of equity per trade (sustainable risk allocation)
- Commission: 0.05% per side (representative of major exchange fees)
- Slippage: 2 ticks (accounts for spread and execution delay)
- Currency: USD
- Pyramiding: disabled (one position at a time)

These settings are designed to produce realistic backtesting results. Risk per trade is capped well below the 5–10% equity guideline. Commission and slippage are included to prevent overstating performance.

Inputs Reference

Signal Layers
- LR Length (21) — linear regression period
- Signal SMA Length (8) — crossover trigger SMA
- Fast EMA (21) / Slow EMA (55) — trend regime definition
- ATR Length (14) / ATR Slow Length (50) / ATR Threshold (0.70)
- HTF Timeframe — higher-timeframe bias source (default "D")

Confluence & Filters
- Min Confluence Score (60) — minimum sum of layer scores required for entry
- Cooldown Bars (5) — bars to wait after exit before re-entering
- Max Bars in Trade (20) — timeout exit

Risk Management
- TP ATR Multiple (2.0) — take-profit distance in ATR units
- SL ATR Multiple (1.2) — stop-loss distance in ATR units

How to Read the Results

Apply the strategy to a liquid instrument on a 1H or 4H chart with sufficient history to generate 100+ trades. Evaluate:
- Net profit relative to max drawdown (seek ratio > 2:1)
- Win rate in context of average win vs. average loss
- Profit factor (total gross profit / total gross loss, seek > 1.3)
- Number of trades (sufficient sample size for statistical inference)

Adjust the confluence minimum score to trade off signal frequency against quality: 50 produces more trades, 75 produces fewer but higher-quality entries.

Non-Repainting Design

All entries fire on strategy.entry() within barstate.isconfirmed blocks. HTF bias uses lookahead_off. No future bar data is accessed. Historical signals do not shift position.

Limitations

- The strategy is designed as a general-purpose framework. It is not optimised for any specific instrument or session. Optimal parameters vary significantly across markets and timeframes.
- ATR-based exits are approximate. In gap markets (equities overnight, weekend gaps on crypto), the stop-loss may be exceeded significantly before the exit executes.
- Backtesting results are computed on historical data only and do not account for execution quality, broker-specific fees, or market impact. Past backtesting performance does not guarantee future live results.
- The bar timeout exit may prematurely close positions that would have eventually reached TP. This is a deliberate conservative design choice to limit capital lock-up, not a flaw.

Disclaimer

This strategy is provided for educational and informational purposes only. Backtesting results presented in the strategy tester represent historical simulation and do not guarantee any future trading outcome. Past performance is not indicative of future results. Never risk capital you cannot afford to lose. Always use proper risk management and conduct independent analysis before making any trading decisions.

Made with passion by officialjackofalltrades

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.