OPEN-SOURCE SCRIPT

Session Raid Stats

4 140
This indicator combines two ideas into one tool: it plots fixed-point projection levels above and below up to three configurable session ranges, and it tracks a **raid statistics table** that measures how often price breaks beyond each of those levels and closes back inside the range — a confirmed "raid" — across hundreds of historical sessions.

The result is a probability-based view of where price tends to reach and reverse after a session closes, expressed as a percentage drawn from real historical data on your current chart and timeframe.

---

**What is a Raid?**

A raid occurs when price breaks beyond a session's high or low by at least a user-defined minimum amount, then closes back inside the range. This is distinct from a simple breakout — a raid requires the close to return, confirming the move was a liquidity sweep rather than a sustained break.

The indicator tracks raids separately for the high side (upward sweeps above the range high) and the low side (downward sweeps below the range low).

---

**Features**

- Up to **3 independent session ranges**, each with configurable time windows (in NY timezone)
- **Range boxes** drawn during the session using wick high/low
- **Projection lines** drawn at fixed-point intervals beyond the range high and low when the session closes — all three ranges share the same level configuration so the lines are directly comparable
- **Raid detection** begins the moment each session range closes and runs for a user-configurable cutoff window
- **Raid statistics table** showing cumulative confirmed raid counts and probabilities at each level, for both the high and low side, for all three ranges
- **Cutoff line** drawn on the chart when each range's detection window expires, with configurable colour, style and label size
- Title row of each table panel is colour-matched to that range's box colour for instant visual identification

---

**How the Levels Work**

All projection lines and statistics table rows are driven by a single pair of inputs: **Level Start** and **Level Step**. If you set Level Start to 20pts and Level Step to 10pts, the six levels will be placed at 20, 30, 40, 50, 60 and 70 points beyond the range high and low. The same thresholds define the bucket boundaries in the statistics table — so the "≥ 20 pts" row in the table directly corresponds to the "+20pts" line on the chart.

This means the table is answering a precise question: *"Of all historical sessions on this chart, what percentage had a confirmed high-side raid that reached at least the +20pts line?"*

---

**Statistics Table — How to Read It**

The table shows one panel per range (or just the active range if "Show All 3 Panels" is turned off). Each panel contains:

| Column | Meaning |
|---|---|
| **Level** | The point threshold beyond the range high/low |
| **^ Cnt** | Number of historical sessions with a confirmed high-side raid reaching at least this level |
| **^ Prob** | That count as a percentage of total sessions tracked |
| **v Cnt** | Same for low-side raids |
| **v Prob** | Low-side probability |

The probabilities are **cumulative** — the "≥ 20pts" row counts all sessions where the confirmed raid reached *at least* 20pts beyond the range, including any that went further. This means probabilities always decrease as you move down the table to higher levels.

A **→** arrow next to a level indicates the current session's confirmed raid has been sized into that bucket.

The **STATUS** row at the bottom shows the live state of the current session:
- **WATCHING** — range has closed, cutoff window is open, no raid confirmed yet
- **CONFIRMED** — a raid has been confirmed this session, with the extension in points shown
- **WINDOW CLOSED** — the cutoff window has expired without a confirmation

The title row of each panel shows the session time string and total number of historical sessions used for the statistics.

---

**Raid Detection Logic**

Detection begins on the first bar after the session range closes and continues until the cutoff window expires:

1. A **touch** is registered when price wicks beyond the range high or low by more than the minimum raid size (configurable per range)
2. A **confirmation** is registered when, after a touch, price closes back inside the range
3. At the moment the cutoff window expires, the session is recorded — confirmed raids are bucketed by their extension size, sessions without a confirmation are recorded as no-raid and counted toward the denominator

Raids that touch outside the range but never close back inside are not recorded as confirmed raids, but they do count toward the session total used to calculate probabilities.

---

**Settings**

**Range Extension / Raid Levels** *(shared across all ranges)*
- **Level Start (pts)** — distance in points of the first level beyond the range high/low. This becomes the first line on the chart and the first row in the table.
- **Level Step (pts)** — distance between each subsequent level. With Start=20 and Step=10, levels are at 20, 30, 40, 50, 60, 70pts.
- **Level 1–6** — enable/disable individual levels. Disabling a level removes both the chart line and the corresponding table row.

**Range 1 / 2 / 3 Settings** *(per range)*
- **Session** — the time window in NY timezone (e.g. `0200-0215` for 2:00–2:15am ET). The range high and low are built from the wicks during this window.
- **Show Range Extension Lines** — toggle the projection lines on/off for this range
- **Show Range Box** — toggle the session range box on/off
- **Box colour** — colour of the range box (also tints the table title row for this range)
- **Line colour / Line style** — appearance of the projection lines

**Range 1 / 2 / 3 — Raid Detection** *(per range)*
- **Min Raid Size (pts)** — minimum distance price must wick beyond the range before a touch is registered. Filters out minor noise near the range boundary. Set this to match a reasonable minimum for the volatility of the session you are analysing.
- **Cutoff (mins after range close)** — how many minutes after the session closes the indicator will continue watching for raids. Set to 0 to watch indefinitely until the next session start. A cutoff line is drawn on the chart when this window expires.

**Raid Statistics — Table**
- **Position** — where the table appears on the chart
- **Text Size** — size of table text
- **Show All 3 Panels** — when on, all three range panels are shown side by side. When off, only the most recently active range is shown.
- **Max Historical Sessions** — caps the number of sessions used to build the statistics. Higher values give more statistically robust numbers; lower values weight recent history more heavily.

**Cutoff Line Display**
- **Cutoff Label Size / Colour** — appearance of the "R1 cutoff" label drawn on the chart
- **Cutoff Line Colour / Style** — appearance of the vertical dashed line drawn when the cutoff window expires

---

**Usage Notes**

- The indicator works on any **intraday timeframe**. The statistics accumulate over the chart history loaded by TradingView — longer histories and lower timeframes generally produce more sessions and more reliable probabilities. For sessions shorter than 30 minutes, a 1–5 minute chart is recommended.
- The session times are evaluated in the **America/New_York timezone** regardless of your chart's timezone setting.
- Statistics reset if you change the session times or the level configuration, as the historical data will no longer match the current settings.
- For futures markets with overnight sessions (e.g. NQ, ES), set the session window to match the specific range period you want to analyse — for example the London open range, the Asia session high/low, or the NY open range.
- The **minimum raid size** should be calibrated to the instrument's typical noise level near range boundaries. Too low a value will register false touches on every minor wick; too high will miss genuine raids. A starting point is roughly half the average range size.

---

**Disclaimer**

This indicator is a statistical tool based on historical price data. Past probabilities do not guarantee future outcomes. It is intended as a research aid and does not constitute financial advice.

---

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。