INVITE-ONLY SCRIPT

Scalp Sense AI

177
# Scalp Sense AI (No Repaint)

**Adaptive trend & reversal detector with an AI-driven score, multi-timeframe confirmations, robust volume filters, and a purpose-built Scalping Mode.**
Signals are generated **only on bar close** (no repaint), include structured alert payloads for webhooks, and come with optional ATR-based TP/SL visualization for study and validation.

---

## What it is (in one paragraph)

**Scalp Sense AI** combines classic market structure (DI/ADX, EMA, SMA, Keltner, ATR) with a continuous **AI Score** that fuses RSI normalization, EMA distance (in ATR units), and DI edge into a single, volatility-aware signal. It adaptively gates **trend** and **reversal** entries, applies **HTF confirmation** without lookahead, and enforces **guard rails** (e.g., strong-trend reversal blocking) unless a high-confidence AI override and volume confirmation are present. **Scalping Mode** compresses reaction times and adds micro price-action cues (wick rejections, micro-EMA crosses, small engulfing) to surface more—but disciplined—opportunities.

---

## Non-Repainting Design

* All signals, markers, state, and alerts are computed **after bar close** using `barstate.isconfirmed`.
* HTF data are requested with `lookahead_off`.
* No “future-peeking” constructs are used.
* Result: signals do **not** change after the candle closes.

---

## How the engine works (pipeline overview)

1. **Base metrics**

* **RSI**, **EMA**, **ATR** (+ ATR SMA for regime/volatility), **SMA long & short**, **Keltner** (EMA ± ATR×mult).
* **Manual DI/ADX** for fine control (DM+, DM−, true range smoothing).
2. **Volatility regime**

* Compares ATR to its SMA and scales thresholds by √(ATR/ATR\_SMA) → robust “high\_vol” gating.
3. **Volume & flow**

* **Volume Z-score**, **OBV slope**, and **MFI** (all computed manually) to confirm impulses and filter weak reversals.
4. **Higher-Timeframe confirmation (optional)**

* Imports HTF **PDI/MDI/ADX** and **SMA** (no lookahead) to require alignment when enabled.
5. **AI Score**

* Weighted fusion of **RSI (normalized around 0)**, **EMA distance (in ATR)**, and **DI edge**.
* Smoothed; then its **mean (μ)** and **volatility (σ)** are estimated to form **adaptive bands** (hi/lo), with optional **hysteresis**.
* **Debounce** (M in N bars) avoids flicker; **bias state** persists until truly invalidated.
6. **Signal logic**

* **Trend entries** require AI bias + trend confirmations (DI/ADX/SMA, HTF if enabled), volatility OK, and **anti-breakout** filter.
* **Reversal entries** come in **core**, **early**, and **scalp** flavors (progressively more frequent), guarded by strong-trend blocks that an **AI+volume+ADX-cooling override** can bypass.
7. **Scalping Mode**

* Adaptive parameter contraction (shorter lengths), gentler guards, micro-patterns (wick/engulf/micro-EMA cross), and reduced cooldown to increase high-quality opportunities.
8. **Cooldown & state**

* One signal per side after a configurable spacing in bars; internal “last direction” avoids clustering.
9. **Visualization & alerts**

* **Triangles** for trend, **circles** for reversals (offset by ATR to avoid overlap).
* **Single-line alert payload** (BUY/SELL, reason, AI, volZ, ADX) ready for webhooks.

---

## Signals & visualization

* **Trend Long/Short** → triangle markers (above/below) when:

* AI bias aligns with trend confirmations (DI edge, ADX above threshold, price vs long SMA, optional HTF alignment).
* Volatility regime agrees; **anti-breakout** prevents entries exactly at lookback highs/lows.
* **Reversal Long/Short** → circular markers when:

* **Core**: AI near “loose” band, OBV/MFI/volZ supportive, ADX cooling, DI spread relaxed, PA confirms (crosses/div).
* **Early**: anticipatory patterns (Keltner exhaustion, simple RSI “quasi-divergence”).
* **Scalp**: micro-EMA cross, wick rejection, mini-engulfing, with relaxed guards but AI/volume still in the loop.
* **Markers appear only on the bar that actually emitted the signal** (no repaint); offsets use ATR so shapes don’t overlap.

---

## Alerts (ready for webhooks)

Enable “**Any alert() function call**” and you’ll receive compact, single-line payloads once per bar:

```
action=BUY;reason=reversal-early;ai=0.1375;volZ=0.82;adx=27.5
action=SELL;reason=trend;ai=-0.2210;volZ=0.43;adx=31.9
```

* `action`: BUY / SELL
* `reason`: `trend` | `reversal-core` | `reversal-early` | `reversal-scalp`
* `ai`: current smoothed AI Score at signal bar
* `volZ`: volume Z-score
* `adx`: current ADX

---

## Inputs (exhaustive)

### 1) Core Inputs

* **RSI Length (Base)** (`rsi_length_base`, int)
Base RSI lookback. Shorter = more reactive; longer = smoother.
* **RSI Overbought Threshold** (`rsi_overbought`, int)
Informational for context; RSI is used normalized in the AI fusion.
* **RSI Oversold Threshold** (`rsi_oversold`, int)
Informational; complements visual context.
* **EMA Length (Base)** (`ema_length_base`, int)
Primary adaptive mean; also used for Keltner mid and distance metric.
* **ATR Length (Base)** (`atr_length_base`, int)
Volatility unit for Keltner, SL/TP (debug), and regime detection.
* **ATR SMA Length** (`atr_sma_len`, int)
Smooth baseline for ATR regime; supports “high\_vol” logic.
* **ATR Multiplier Base** (`atr_mult_base`, float)
Scales volatility gating (sqrt-scaled); higher = tighter high-vol requirement.
* **Disable Volatility Filter** (`disable_volatility_check`, bool)
Bypass volatility gating if true.
* **Price Change Period (bars)** (`price_change_period_base`, int)
Simple momentum check (+/−% over N bars) used in trend validation.
* **Base Cooldown Bars Between Signals** (`signal_cooldown_base`, int ≥ 0)
Minimum bars to wait between signals (per side).
* **Trend Confirmation Bars** (`trend_confirm_bars`, int ≥ 1)
Require persistence above/below long SMA for this many bars.
* **Use Higher Timeframe Confirmation** (`use_higher_tf`, bool)
Turn on/off HTF alignment (no repaint).
* **Higher Timeframe for Confirmation** (`higher_tf`, timeframe)
E.g., “60” to confirm M15 with H1; used for HTF PDI/MDI/ADX and SMA.
* **TP as ATR Multiple** (`tp_atr_mult`, float)
For **visual debug** only (drawn after entries); not an order manager.
* **SL as ATR Multiple** (`sl_atr_mult`, float)
For visual debug only.
* **Enable Scalping Mode** (`scalping_mode`, bool)
Compresses lengths/thresholds, unlocks micro-PA modules, reduces cooldown.
* **Show Debug Lines** (`show_debug`, bool)
Plots AI bands, DI/ADX, EMA/SMA, Keltner, vol metrics, and TP/SL (debug).

### 2) AI Score & Thresholds

* **AI Score Smooth Len** (`ai_len`, int)
EMA smoothing over the raw fusion.
* **AI Volatility Window** (`ai_sigma_len`, int)
Window to estimate AI mean (μ) and standard deviation (σ).
* **K High (sigma)** (`ai_k_hi`, float)
Upper band width (σ multiplier) for strong threshold.
* **K Low (sigma)** (`ai_k_lo`, float)
Lower band width (σ multiplier) for loose threshold.
* **Debounce Window (bars)** (`ai_debounce_m`, int ≥ 1)
Rolling window length used by the confirm counter.
* **Min Bars>Thr in Window** (`ai_debounce_n`, int ≥ 1)
Minimum confirmations inside the debounce window to validate a state.
* **Use Hysteresis Thresholds** (`ai_hysteresis`, bool)
Requires crossing back past a looser band to exit bias → fewer whipsaws.
* **Weight DI Edge (0–1)** (`ai_weight_di`, float)
Importance of DI edge within the fusion.
* **Weight EMA Dist (0–1)** (`ai_weight_ema`, float)
Importance of EMA distance (in ATR units).
* **Weight RSI Norm (0–1)** (`ai_weight_rsi`, float)
Importance of normalized RSI.
* **Sensitivity (0–1)** (`sensitivity`, float)
Contracts/expands bands (higher = more sensitive).

### 3) Volume Filters

* **Volume MA Length** (`vol_ma_len`, int)
Baseline for volume Z-score.
* **Volume Z-Score Window** (`vol_z_len`, int)
Std-dev window for Z-score; larger = fewer volume “spikes”.
* **Reversal: Min Volume Z for confirm** (`vol_rev_min_z`, float)
Minimum Z required to validate reversals (adaptively relaxed in scalping).
* **OBV Slope Lookback** (`obv_slope_len`, int)
Rising/falling OBV over this window supports bull/bear confirmations.
* **MFI Length** (`mfi_len`, int)
Money Flow Index lookback (manual calculation).

### 4) Filters (Breakout / ADX / Reversal)

* **Enable Breakout Filter** (`enable_breakout_fil`, bool)
Avoid trend entries at lookback highs/lows.
* **Breakout Lookback Bars** (`breakout_lookback`, int ≥ 1)
Window for the anti-breakout guard.
* **Base ADX Length** (`adx_length_base`, int)
Lookback for DI/ADX smoothing (also adapted in Scalping Mode).
* **Base ADX Threshold** (`adx_threshold_base`, float)
Minimum ADX to validate trend context (scaled in Scalping Mode).
* **Enable Reversal Filter** (`enable_rev_filter`, bool)
Master switch for reversal logic.
* **Max ADX for Reversal** (`rev_adx_max`, float)
Hard cap: above this ADX, reversals are blocked (unless overridden by AI if allowed in Guards).

### 5) Reversal Guard (regime protection & overrides)

* **Strong Trend: ADX add-above Thr** (`guard_adx_add`, float)
Extra ADX above `adx_threshold` to mark “strong” trend.
* **Strong Trend: min DI spread** (`guard_spread_min`, float)
Minimum DI separation to consider a trend “dominant”.
* **Require ADX drop from window max (%)** (`guard_adx_drop_min_pct`, float 0–1)
ADX must drop at least this fraction from its window maximum to consider “cooling”.
* **Regime Window (bars)** (`guard_regime_len`, int ≥ 10)
Window over which ADX max is measured for the “cooling” check.
* **EMA Slope Lookback** (`guard_slope_len`, int ≥ 2)
EMA slope horizon used alongside Keltner for strong-trend identification.
* **Keltner Mult (ATR)** (`guard_kc_mult`, float)
Keltner width for strong trend bands and exhaustion checks.
* **HTF Reversal Block Mode** (`htf_block_mode`, string: `Off` | `On` | `AI-controlled`)

* `Off`: never block by HTF.
* `On`: block reversals whenever HTF is strong.
* `AI-controlled`: block **unless** AI+volume+ADX-cooling override criteria are met.
* **AI-controlled: allow AI override** (`ai_htf_override`, bool)
Enables the override mechanism in `AI-controlled` mode.
* **AI override multiplier (vs band\_hi)** (`ai_override_mult`, float)
Strength needed beyond the high band to count as “strong AI”.
* **AI override: min bars beyond strong thr** (`ai_override_min_bars`, int ≥ 1)
Debounce on the override itself.

### 6) Markers

* **Reversal Circle ATR Offset** (`rev_marker_offset_atr`, float ≥ 0)
Vertical offset for reversal circles; trend triangles use a separate (internal) offset.

### 7) Scalping Mode Tuning

* **Reversal aggressiveness (0–1)** (`scalp_rev_aggr`, float)
Higher = looser guards and stronger AI sensitivity.
* **Wick: body multiple (bull/bear)** (`scalp_wick_body_mult`, float)
Wick must be at least this multiple of body to count as rejection.
* **Wick: ATR multiple (min)** (`scalp_wick_atr_mult`, float)
Minimal wick length in ATR units.
* **Micro EMA factor (vs EMA base)** (`scalp_ema_fast_factor`, float 0.2–0.9)
Fast EMA length = base EMA × factor (rounded/int).
* **Relax breakout filter in scalping** (`scalp_breakout_relax`, bool)
Lets more trend entries through in scalping context.

### 8) ICT-style SMA (bases)

* **ICT SMA Long Length (Base)** (`sma_long_len_base`, int)
Long-term baseline for regime/trend.
* **ICT SMA Short1 Length (Base)** (`sma_short1_len_base`, int)
Short baseline for price-action crosses.
* **ICT SMA Short2 Length (Base)** (`sma_short2_len_base`, int)
Companion short baseline used in PA cross checks.

> **Adaptive “effective” values:** When **Scalping Mode** is ON, the script internally shortens multiple lengths (RSI/EMA/ATR/ADX/μσ windows, SMAs) and gently relaxes guards (ADX drop %, DI spread, volume Z, override thresholds), reduces cooldown/confirm bars, and optionally relaxes the breakout filter—so you get **more frequent but still curated** signals.

---

## Plots & debug (optional)

* DI+/DI−, ADX (curr + HTF), EMA, long SMA, Keltner up/down (when strong), AI Score, AI mean, AI bands (hi/lo; low plots only when hysteresis is on), Volume MA and Z-score, and ATR-based TP/SL guide (after entries).
* These are **study aids**; the indicator does not manage trades.

---

## Recommended use

* **Timeframes**:

* Scalping Mode: M1–M15.
* Standard Mode: M15–H1 (or higher).
* **Markets**: Designed for liquid FX, indices, metals, and large-cap crypto.
* **Chart type**: Standard candles recommended (Heikin-Ashi alters inputs and hence signals).
* **Alerts**: Use “Any alert() function call”. Parse the key/value payloads server-side.

---

## Good to know

* **Why some alerts don’t draw shapes retroactively**: markers are drawn **only on** the bar that emitted the signal (no repaint by design).
* **Why a reversal didn’t fire**: strong-trend guards + HTF block may have been active; check ADX, DI spread, Keltner position, EMA slope, and whether AI override criteria were met.
* **Too many / too few signals**: tune **Scalping Mode**, `signal_cooldown_base`, AI bands (`ai_k_hi/lo`, `sensitivity`), volume Z (`vol_rev_min_z`), and guards (`rev_adx_max`, `guard_*`).

---

## Disclaimer

This is an **indicator**, not a strategy or an execution system. It does not place, modify, or manage orders. Markets carry risk—validate on historical data and demo before any live decisions. No performance claims are made.

---

### Version

**Scalp Sense AI v11.5** — Adaptive AI bands with hysteresis/debounce, HTF no-lookahead confirmations, guarded reversal logic with AI override, full volume suite (Z, OBV slope, MFI), anti-breakout filter, and a dedicated Scalping Mode with micro-PA cues.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.