PROTECTED SOURCE SCRIPT

Rapid Impulse Leg Mapping

23
Raid Trend Detector (Rapid Impulse Leg Mapping) [v5.0]

SHORT DESCRIPTION (1–2 lines)
Impulse-leg + reversal-gate engine that maps directional legs and stamps confirmed leg extremes, designed to track “raid-to-raid” behavior with clean structure anchors.

WHAT THIS SCRIPT DOES
This code is the “Impulse Leg Detector” foundation of the full system. It has one job: identify directional impulse legs, manage an active IC (internal containment) range, and stamp the prior leg’s extreme when a true reversal is confirmed. The output is a clean set of structure levels you can use as a directional map and as reference points for higher logic (trend, confirmations, FVG windows, etc.).

CORE CONCEPTS USED

1) IC (Internal Containment) Range
After the first valid impulse candle appears, the script initializes an IC range using that candle’s high/low. The IC acts like a “control box” for the current leg.

If price closes inside the IC, the IC is allowed to expand to include new wicks.

If price closes outside (breaks IC), the engine attempts to “reset” the IC (continuation or reversal).

2) Reversal Gate (Filter Line)
The reversal gate is a directional filter that prevents weak flips.

If the current direction is bearish and price breaks up, the script only flips bullish if the close also clears the gate.

Same logic for bullish → bearish.
This avoids treating simple noise as a legitimate change of leg direction.

3) Impulse Leg Extremes (HYBRID tracker)
While an IC is active, the script separately tracks the true wick extreme of the running leg:

Bull leg tracks legHighExt = highest wick high during the bull leg

Bear leg tracks legLowExt = lowest wick low during the bear leg
This is intentionally separate from IC boundaries, because IC can expand while the leg extreme remains the meaningful “raid point”.

4) Confirmed Leg Stamping (Black Lines)
A black line is printed only on a confirmed reversal (direction flip).
What it prints: the prior leg’s extreme (wick-based) tracked by the HYBRID tracker.
This ensures the black level represents the “true leg raid point” of the completed impulse.

HOW THE MECHANISM WORKS (STEP BY STEP)

A) First Impulse Detection (FIRST IC)
A first IC is created when the close breaks above the previous high (bull impulse) or below the previous low (bear impulse).
Once detected, the script:

Sets icDir (direction)

Sets icHigh / icLow to that candle’s range

Initializes legHighExt / legLowExt from that candle

Draws optional IC lines (blue)

Draws the reversal gate (orange) based on IC direction

B) After the first IC (Active Leg Management)
Every confirmed candle checks:

brkUp: close > icHigh

brkDn: close < icLow

If a break happens, the script decides if it’s:

continuation reset (same direction) or

reversal reset (direction flip) using the gate filter

C) Reversal confirmed → stamp the leg
When a true reversal is detected:

Bull leg stamps legHighExt (prior bull extreme)

Bear leg stamps legLowExt (prior bear extreme)
Black line printing is limited to the last 2 lines (legPrev, legLast) to keep chart clean.

D) No reset → IC expansion logic
If price closes inside the IC, the IC can expand to include new wicks (icHigh/icLow update).
Separately, the leg extreme tracker continues updating the active leg extreme.

USER CONTROLS
Show IC Lines: toggles IC high/low lines (blue).
Show Reversal Gate: toggles the gate line (orange).
Show Leg Lines: toggles black confirmed leg stamping.

IMPORTANT NOTES / DESIGN INTENT

This is not a signal script. It’s a structure engine.

Black lines only print on confirmed reversals. That’s deliberate: legs are only “confirmed” when the engine accepts a direction flip.

IC can expand while the market is compressing/ranging. The leg extreme tracker remains the “truth” for the leg’s raid point.

The reversal gate is the key filter that keeps the engine from flipping too easily.

RECOMMENDED USAGE
Use this on HTF (1H / 4H / Daily) to build a clean structural map of legs and raid points. Then drop to LTF (5m / 15m) for execution using your separate entry indicator. This solves the classic problem: “where exactly should I look for entries?” by defining structure first, then execution second.

CHANGELOG (for publish notes)
v5.0

Added line visibility controls (IC, gate, leg lines)

Stabilized impulse-leg detection and confirmed leg stamping logic

Positioned as the foundation for the updated Raid Trend Detector build

DISCLAIMER
This script is for educational and analytical use only. It does not provide financial advice. Trading involves risk. You are responsible for your own decisions, risk management, and execution.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.