PROTECTED SOURCE SCRIPT
4h First Candle Reversion – Strategy (5m Exec)

4h First Candle Reversion – Strategy (5m, NY Session)
This strategy is based on the well-known “first 4-hour candle of the day” concept, using the opening range of the New York session to fade failed breakouts on lower timeframes (5m).
It is the strategy version of my indicator with the same name and logic.
________________________________________
🔧 Core Idea
1. Session & Box
o A session “day” is defined in a chosen timezone (default: America/New_York).
o From blockStartHour to blockStartHour + blockLengthHrs (by default 00:00–04:00 NY time), the strategy:
Tracks the highest high and lowest low of this 4h window.
After the window closes, this becomes the daily range box (first 4h high & low), which is used for the rest of that session day.
2. Reversion Setup (Failed Breakouts) – 5m execution
o The strategy works best on a 5-minute chart.
o After the box is ready:
Short signal:
o Previous 5m candle closes above the box high.
o Current 5m candle closes back inside the box.
o → Enter short at the close of the current candle.
Long signal:
o Previous 5m candle closes below the box low.
o Current 5m candle closes back inside the box.
o → Enter long at the close of the current candle.
Only the close is used to decide outside/inside – wicks alone do not trigger trades.
________________________________________
📏 Risk Management (Important Limitation)
The original discretionary concept is usually traded with:
• Stop Loss at the last meaningful swing high/low outside the box before price returns inside.
• Take Profit at a fixed R:R, typically 2:1, based on that actual swing-based risk.
However, in this Pine strategy the SL/TP must be simplified to something static and mechanical:
• SL = the high/low of the breakout candle (the candle that closed outside the box):
o Long: SL at the low of the outside candle.
o Short: SL at the high of the outside candle.
• TP = a fixed multiple of that risk:
o TP = entry ± (risk × tpRR)
o Default tpRR = 2.0 (2R).
⚠ Because of this simplification, the backtest does not perfectly represent how a skilled manual trader would trade this setup.
In live trading you can choose swing highs/lows, adjust R:R more dynamically, skip marginal setups, etc. The script can’t replicate that discretion, so the historical results are approximate, not exact.
Please treat the backtest as a rough performance proxy and as a tool to compare markets/timeframes and tweak rules – not as a precise replication of manual trade management.
________________________________________
⚙️ Inputs & Controls
• Session TZ (int selector)
0 = Exchange, 1 = America/New_York, 2 = Asia/Bangkok, 3 = UTC.
• Block start hour / length
Default: 0 and 4 → first 4h of the NY session day.
• TP (R multiple)
tpRR – default 2.0.
• Enable Longs / Shorts toggles.
• Visual options
o Show/hide box lines
o Show only the latest box or all historical boxes
o Shade the first 4h build window
o Show/hide signal markers (LONG/SHORT triangles)
________________________________________
📝 Usage Notes
• Designed for 5m charts on:
o XAUUSD (Gold)
o BTC/ETH
o Major FX pairs (EURUSD, GBPUSD, USDJPY, etc.)
o Index CFDs/Futures (US100, US500, etc.)
• Best used as:
o A framework for your playbook,
o A way to study how often this setup appears on different markets,
o And a starting point to add your own filters (trend, time filters, news filters, volatility filters, etc.).
Manual trading with dynamic swing-based stops and discretionary filters will always differ from this mechanical version – keep that in mind when interpreting the equity curve and statistics.
This strategy is based on the well-known “first 4-hour candle of the day” concept, using the opening range of the New York session to fade failed breakouts on lower timeframes (5m).
It is the strategy version of my indicator with the same name and logic.
________________________________________
🔧 Core Idea
1. Session & Box
o A session “day” is defined in a chosen timezone (default: America/New_York).
o From blockStartHour to blockStartHour + blockLengthHrs (by default 00:00–04:00 NY time), the strategy:
Tracks the highest high and lowest low of this 4h window.
After the window closes, this becomes the daily range box (first 4h high & low), which is used for the rest of that session day.
2. Reversion Setup (Failed Breakouts) – 5m execution
o The strategy works best on a 5-minute chart.
o After the box is ready:
Short signal:
o Previous 5m candle closes above the box high.
o Current 5m candle closes back inside the box.
o → Enter short at the close of the current candle.
Long signal:
o Previous 5m candle closes below the box low.
o Current 5m candle closes back inside the box.
o → Enter long at the close of the current candle.
Only the close is used to decide outside/inside – wicks alone do not trigger trades.
________________________________________
📏 Risk Management (Important Limitation)
The original discretionary concept is usually traded with:
• Stop Loss at the last meaningful swing high/low outside the box before price returns inside.
• Take Profit at a fixed R:R, typically 2:1, based on that actual swing-based risk.
However, in this Pine strategy the SL/TP must be simplified to something static and mechanical:
• SL = the high/low of the breakout candle (the candle that closed outside the box):
o Long: SL at the low of the outside candle.
o Short: SL at the high of the outside candle.
• TP = a fixed multiple of that risk:
o TP = entry ± (risk × tpRR)
o Default tpRR = 2.0 (2R).
⚠ Because of this simplification, the backtest does not perfectly represent how a skilled manual trader would trade this setup.
In live trading you can choose swing highs/lows, adjust R:R more dynamically, skip marginal setups, etc. The script can’t replicate that discretion, so the historical results are approximate, not exact.
Please treat the backtest as a rough performance proxy and as a tool to compare markets/timeframes and tweak rules – not as a precise replication of manual trade management.
________________________________________
⚙️ Inputs & Controls
• Session TZ (int selector)
0 = Exchange, 1 = America/New_York, 2 = Asia/Bangkok, 3 = UTC.
• Block start hour / length
Default: 0 and 4 → first 4h of the NY session day.
• TP (R multiple)
tpRR – default 2.0.
• Enable Longs / Shorts toggles.
• Visual options
o Show/hide box lines
o Show only the latest box or all historical boxes
o Shade the first 4h build window
o Show/hide signal markers (LONG/SHORT triangles)
________________________________________
📝 Usage Notes
• Designed for 5m charts on:
o XAUUSD (Gold)
o BTC/ETH
o Major FX pairs (EURUSD, GBPUSD, USDJPY, etc.)
o Index CFDs/Futures (US100, US500, etc.)
• Best used as:
o A framework for your playbook,
o A way to study how often this setup appears on different markets,
o And a starting point to add your own filters (trend, time filters, news filters, volatility filters, etc.).
Manual trading with dynamic swing-based stops and discretionary filters will always differ from this mechanical version – keep that in mind when interpreting the equity curve and statistics.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarle liberamente e senza alcuna limitazione – ulteriori informazioni qui.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.
Script protetto
Questo script è pubblicato come codice protetto. Tuttavia, è possibile utilizzarle liberamente e senza alcuna limitazione – ulteriori informazioni qui.
Declinazione di responsabilità
Le informazioni e le pubblicazioni non sono intese come, e non costituiscono, consulenza o raccomandazioni finanziarie, di investimento, di trading o di altro tipo fornite o approvate da TradingView. Per ulteriori informazioni, consultare i Termini di utilizzo.