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.
סקריפט להזמנה בלבד
רק משתמשים שאושרו על ידי המחבר יכולים לגשת לסקריפט הזה. תצטרך לבקש ולקבל אישור להשתמש בו. אישור זה ניתן בדרך כלל לאחר תשלום. לפרטים נוספים, בצע את ההוראות של המחבר למטה או צור קשר ישירות עם codyxbustamante.
TradingView לא ממליצה לשלם עבור סקריפט או להשתמש בו, אלא אם כן אתה סומך לחלוטין על המחבר שלו ומבין איך הוא עובד. ייתכן שתמצא גם אלטרנטיבות חינמיות בקוד פתוח בסקריפטים של הקהילה שלנו.
הוראות המחבר
אזהרה: אנא קרא את המדריך שלנו לסקריפטים להזמנה בלבד לפני שתבקש גישה.
כתב ויתור
סקריפט להזמנה בלבד
רק משתמשים שאושרו על ידי המחבר יכולים לגשת לסקריפט הזה. תצטרך לבקש ולקבל אישור להשתמש בו. אישור זה ניתן בדרך כלל לאחר תשלום. לפרטים נוספים, בצע את ההוראות של המחבר למטה או צור קשר ישירות עם codyxbustamante.
TradingView לא ממליצה לשלם עבור סקריפט או להשתמש בו, אלא אם כן אתה סומך לחלוטין על המחבר שלו ומבין איך הוא עובד. ייתכן שתמצא גם אלטרנטיבות חינמיות בקוד פתוח בסקריפטים של הקהילה שלנו.
הוראות המחבר
אזהרה: אנא קרא את המדריך שלנו לסקריפטים להזמנה בלבד לפני שתבקש גישה.