Break & Retest of ORB (Backtesting)

Goal: Trade a single “break + retest” of the configurable Opening Range (OR) during a specific time window, with clean risk/return control and optional volume and side filters.
1) Define today’s Opening Range
- You choose the OR start time (Eastern Time) and the OR length in minutes (e.g., 9:30–9:45 ET).
- At the first bar of that OR window (on the chosen OR resolution), the script captures:
- Range High (ORH) and Range Low (ORL).
- The OR is drawn with configurable line and fill colors.
2) Detect the first clean break
- After the OR is set, the script waits for the first breakout past ORH or ORL.
- The break must move at least minBreakPts and at most maxBreakPts beyond the boundary (keeps out tiny pokes and runaway moves).
- If price first breaks above ORH, we mark a bullish break.
- If price first breaks below ORL, we mark a bearish break.
3) Wait for the retest (entry signal)
- From the breakout bar, a retest window opens for a fixed number of 1-minute bars: between minRetestBars and maxRetestBars.
Inside that window:
- Long setup (after bullish break): we require a bar whose low trades back into the range (between ORL and ORH). That is the “retest”.
- Short setup (after bearish break): we require a bar whose high trades back into the range.
- Entries can be restricted to a custom entry time window (ET) and optionally gated by a minimum volume.
- You can enable/disable longs or shorts independently.
4) Invalidation (one-time alert)
- If a bullish break later sees price dip below ORL, or a bearish break later sees price pop above ORH, the script flags a “First Invalidation” and prints a label once (with the reason).
- This is informational; it doesn’t auto-lock the system, but it’s a strong “structure broken” signal.
5) Risk & reward
- Stop loss (points) can be:
- Default: (ORH − ORL) + 1 point, capped at stopLossCap, or
- Custom fixed number of points.
- Take profit (points) can be:
- Default: RR × SL (not less than minTPpts), or
- Custom fixed (capped by maxTPpts logic in the input).
- When a trade fires, the script draws risk/reward boxes from the entry candle forward and (optionally) shows live R:R labels updating over time.
6) Limits and session management
- Daily entry cap: At most maxRetestsPerDay retest entries per day.
- Forced exit: Close any open position at a custom ET time (e.g., 12:00 ET).
- Daily reset: At 00:00 ET, the strategy resets its internal state for the new session (drawings remain on the chart).
7) Visuals & alerts
- OR high/low lines and the fill are color-configurable.
- Risk/Reward boxes and their transparency are configurable.
- A one-time alert fires on the first invalidation of the day.
- TL;DR workflow
- Build the OR at your chosen time and length.
- Wait for the first valid break (not too small/large).
- Look for a timely retest back into the range (long: bar low inside range; short: bar high inside range), within your entry window and volume filter.
- Enter with your chosen SL/TP scheme; track boxes and (optionally) live R:R labels.
- Respect the daily cap and force-exit time; reset at midnight ET.
Skrypt tylko na zaproszenie
Tylko użytkownicy zatwierdzeni przez autora mogą uzyskać dostęp do tego skryptu. Musisz złożyć prośbę i uzyskać zgodę na jego użycie. Zazwyczaj jest ona udzielana po dokonaniu płatności. Aby uzyskać więcej informacji, postępuj zgodnie z instrukcjami autora poniżej lub skontaktuj się bezpośrednio z codyxbustamante.
TradingView NIE zaleca płacenia za skrypt ani jego używania, jeśli nie masz pełnego zaufania do jego autora i nie rozumiesz, jak działa. Możesz także znaleźć darmowe, open-source'owe alternatywy w naszej sekcji skryptów społecznościowych.
Instrukcje autora
Ostrzeżenie: przed złożeniem prośby o dostęp przeczytaj nasz przewodnik dotyczący skryptów dostępnych tylko na zaproszenie.
Wyłączenie odpowiedzialności
Skrypt tylko na zaproszenie
Tylko użytkownicy zatwierdzeni przez autora mogą uzyskać dostęp do tego skryptu. Musisz złożyć prośbę i uzyskać zgodę na jego użycie. Zazwyczaj jest ona udzielana po dokonaniu płatności. Aby uzyskać więcej informacji, postępuj zgodnie z instrukcjami autora poniżej lub skontaktuj się bezpośrednio z codyxbustamante.
TradingView NIE zaleca płacenia za skrypt ani jego używania, jeśli nie masz pełnego zaufania do jego autora i nie rozumiesz, jak działa. Możesz także znaleźć darmowe, open-source'owe alternatywy w naszej sekcji skryptów społecznościowych.
Instrukcje autora
Ostrzeżenie: przed złożeniem prośby o dostęp przeczytaj nasz przewodnik dotyczący skryptów dostępnych tylko na zaproszenie.