OPEN-SOURCE SCRIPT

Projection Forecaster - Confluences

358
Projection Forecaster - Confluences

What it is

Projection Forecaster reads five independent market factors, combines them into a single
directional **bias score** from −100 to +100, and then draws a forward-looking
**projection cone** on the chart. The cone shows the *direction* price is currently
leaning and — through its width — *how much confidence* that lean deserves. When the
market is ranging rather than trending, the tool switches to a distinct **orange
"sideways" state** instead of forcing a green/red read.

This is a **probabilistic context tool, not a prediction of the future and not a
buy/sell signal generator.** The cone is a visualization of present-bar conditions
projected forward under a simple drift-and-uncertainty model; it does not claim to know
where price will actually go.

---

### The idea

Most "direction" tools collapse everything into one oscillator, which double-counts the
same edge (e.g. three momentum inputs that all say the same thing). Projection Forecaster
instead deliberately samples **five different dimensions** of the market — trend, momentum,
higher-timeframe context, order flow, and mean-reversion pressure — so each factor adds
*new* information. Those are blended with user weights into one bias, and the bias is then
expressed as a geometric cone so the trader can read direction and conviction at a glance.

---

### The five factors and how each is calculated

Each factor is normalized to roughly the −1 … +1 range (−1 = fully bearish, +1 = fully
bullish) before weighting.

**1. Trend Slope** — the underlying tide.
Uses the EMA stack (EMA-20, EMA-50, EMA-200):
`+0.5 if EMA20 > EMA50 else −0.5`, plus `+0.5 if EMA50 > EMA200 else −0.5`.
Range −1 (fully stacked down) to +1 (fully stacked up).

**2. Momentum** — the push behind the move.
Combines RSI position and the MACD histogram:
`clamp( 0.7 × (RSI−50)/25 + 0.3 × (MACD_histogram / ATR) )`.
RSI is centered on 50; the MACD histogram is normalized by ATR so it scales across
instruments. `clamp` limits the result to −1 … +1.

**3. Higher-Timeframe Bias** — bigger-picture agreement.
Pulls the close and a 50-period EMA from a higher timeframe (4× the current intraday
timeframe; same timeframe on non-intraday charts) using `request.security` with
**lookahead disabled** to avoid future leak. Returns +1 if HTF close > HTF EMA, else −1.

**4. Volume Flow** — who is in control.
Builds a signed-volume series: `sign(close−open) × volume`, smoothed with a 14-period EMA,
then divided by 20-period average volume and clamped to −1 … +1. Positive = net buying
pressure, negative = net selling pressure.

**5. Mean-Reversion** — a deliberate contrarian counterweight.
Measures how stretched price is from the rolling VWAP:
`clamp( −(close − VWAP) / (2 × ATR) )`.
Note the negative sign: when price is far **above** VWAP this factor leans **down**
(over-extension pressure), and vice-versa. It is weighted lightly so it tempers, rather
than overrides, the trend.

**Volatility regime** (`ATR / SMA(ATR, 20)`) is **not** a directional vote. It is used only
to widen the cone when volatility is expanding.

---

### How the bias is combined

```
bias = ( wTrend·Trend + wMom·Momentum + wHTF·HTF + wFlow·Flow + wMR·MeanRev )
/ (wTrend + wMom + wHTF + wFlow + wMR)
```

Weights are user inputs (defaults 0.30 / 0.25 / 0.20 / 0.15 / 0.10) and are
**auto-normalized**, so any combination you choose still produces a bias in −1 … +1.
The result is smoothed with a short EMA (default length 3) to stop bar-to-bar flicker.
`bias × 100` is shown on the dashboard; `50 + bias × 50` is shown as an approximate
"% up" reading purely to make the lean human-readable.

---

### How the projection cone is drawn

The cone is anchored at the current bar's price and extends `Projection Length` bars into
the future (a fixed, user-set horizon — it is a drawn projection, not a forecast of actual
candles).

- **Center / drift line:** `driftPerBar = bias × DriftStrength × ATR`, accumulated over the
projection length. Stronger, more one-sided bias → steeper center line. In a sideways
market the drift is cut to 25 % so the line reads flat.
- **Cone width (uncertainty):** `halfWidth = ATR × WidthStrength × bars × (0.35 + (1 − |bias|) × volRegime)`.
The key idea: width grows when conviction is **low** (`1 − |bias|`) and when volatility is
expanding. **A confident read produces a narrow cone; an unsure read produces a wide one.**

So the cone's *slope* encodes direction and the cone's *spread* encodes how much to trust it.

---

### The sideways (orange) state

A trending model is misleading in a range, so the script detects ranging conditions two ways:
- **Weak bias:** `|bias|` inside the user "Neutral Dead-Zone", or
- **Low ADX:** standard 14-period ADX below the user threshold (default 20).

When either is true, the cone, center line, read-out, dashboard and an optional background
region all turn **orange** and the label reads "SIDEWAYS — ranging / no clear lean." This
keeps the tool honest in chop instead of painting a false green/red bias.

---

### What it draws on the chart

- The forward projection cone (toggle) and center drift line (toggle).
- A floating plain-English read at the cone tip, e.g. "▲ Leaning UP • Strong conviction (≈72% up)".
- A compact dashboard showing each of the five factors as a mini bar, plus overall bias,
conviction and direction.
- An optional background tint for the sideways state.

---

### Alerts

Built-in alerts (both as classic `alertcondition` dropdown entries and rich `alert()`
messages that include symbol, timeframe, direction, conviction and the % read):
bias flips **UP** / **DOWN**, conviction turns **Strong+**, and market turns **Sideways**.
All alert logic evaluates on bar close (`alert.freq_once_per_bar_close`) to avoid intrabar
flicker.

---

### How to use it

- Treat the cone as **directional context**, not an entry trigger. Use it to bias your own
setups: take longs more seriously when the cone is green and narrow; stand aside or expect
rotation when it is orange.
- A **narrow** cone = factors agree (higher conviction). A **wide** cone = mixed signals or
high volatility (lower conviction).
- Combine it with your existing levels, structure or strategy — it is designed to *inform* a
decision, not make it for you.
- Tune the factor weights and the ADX threshold to suit the instrument and timeframe you trade.

---

### Repainting & calculation notes

- All factors are standard closed-bar calculations; higher-timeframe data uses
`lookahead = barmerge.lookahead_off`, so no future information is used.
- The projection cone is drawn only on the most recent bar and is **recomputed live** as the
current bar develops — this is expected behaviour for a forward projection and does **not**
repaint historical bars (no past cones are stored or restated).
- Alerts fire on bar close.

---

### Originality

This script is my own original work. It is not a copy of an existing indicator. The
component techniques it uses (EMA stack, RSI, MACD, VWAP, ADX, ATR) are standard public
concepts; the original contribution is the **specific multi-factor blending into a single
normalized bias and its expression as a drift-and-uncertainty projection cone with an
explicit ADX-based sideways state.** No code from other authors is included.

---

### Disclaimer

This indicator is provided for **educational and informational purposes only**. It does not
constitute financial advice and makes **no guarantee of future results**. Markets involve
risk; past behaviour does not predict future outcomes. Always do your own analysis and manage
your risk. You are solely responsible for your trading decisions.

Clause de non-responsabilité

Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.