OPEN-SOURCE SCRIPT
Candle Breakout Strategy

Short description (one-liner)
Candle Breakout Strategy — identifies a user-specified candle (UTC time), draws its high/low range, then enters on breakouts with configurable stop-loss, take-profit (via Risk:Reward) and optional alerts.
Full description (ready-to-paste)
Candle Breakout Strategy
Version 1.0 — Strategy script (Pine v5)
Overview
The Candle Breakout Strategy automatically captures a single "range candle" at a user-specified UTC time, draws its high/low as a visible box and dashed level lines, and waits for a breakout. When price closes above the range high it enters a Long; when price closes below the range low it enters a Short. Stop-loss is placed at the opposite range boundary and take-profit is calculated with a user-configurable Risk:Reward multiplier. Alerts for entries can be enabled.
This strategy is intended for breakout style trading where a clearly defined intraday range is established at a fixed time. It is simple, transparent and easy to adapt to multiple symbols and timeframes.
How it works (step-by-step)
On every bar the script checks the current UTC time.
When the first bar that matches the configured Target Hour:Target Minute (UTC) appears, the script records that candle’s high and low. This defines the breakout range.
A box and dashed lines are drawn on the chart to display the range and extended to the right while the range is active.
The script then waits for price to close outside the box:
Close > Range High → Long entry
Close < Range Low → Short entry
When an entry triggers:
Stop-loss = opposite range boundary (range low for longs, range high for shorts).
Take-profit = entry ± (risk × Risk:Reward). Risk is computed as the distance between entry price and stop-loss.
After entry the range becomes inactive (waitingForBreakout = false) until the next configured target time.
Inputs / Parameters
Target Hour (UTC) — the hour (0–23) in UTC when the range candle is detected.
Target Minute — minute (0–59) of the target candle.
Risk:Reward Ratio — multiplier for computing take profit from risk (0.5–10). Example: 2 means TP = entry + 2×risk.
Enable Alerts — turn on/off entry alerts (string message sent once per bar when an entry occurs).
Show Last Box Only (internal behavior) — when enabled the previous box is deleted at the next range creation so only the most recent range is visible (default behavior in the script).
Visuals & On-chart Info
A semi-transparent blue box shows the recorded range and extends to the right while active.
Dashed horizontal lines mark the range high and low.
On-chart shapes: green triangle below bar for Long signals, red triangle above bar for Short signals.
An information table (top-right) displays:
Target Time (UTC)
Active Range (Yes / No)
Range High
Range Low
Risk:Reward
Alerts
If Enable Alerts is on, the script sends an alert with the following formats when an entry occurs:
Long alert:
🟢 LONG SIGNAL
Entry Price: <price>
Stop Loss: <price>
Take Profit: <price>
Short alert:
🔴 SHORT SIGNAL
Entry Price: <price>
Stop Loss: <price>
Take Profit: <price>
Use TradingView's alert dialog to create alerts based on the script — select the script’s alert condition or use the alert() messages.
Recommended usage & tips
Timeframe: This strategy works on any timeframe but the definition of "candle at target time" depends on the chart timeframe. For intraday breakout styles, use 1m — 60m charts depending on the session you want to capture.
Target Time: Choose a time that is meaningful for the instrument (e.g., market open, economic release, session overlap). All times are handled in UTC.
Position Sizing: The script’s example uses strategy.percent_of_equity with 100% default — change default_qty_value or strategy settings to suit your risk management.
Filtering: Consider combining this breakout with trend filters (EMA, ADX, etc.) to reduce false breakouts.
Backtesting: Always backtest over a sufficiently large and recent sample. Pay attention to slippage and commission settings in TradingView’s strategy tester.
Known behavior & limitations
The script registers the breakout on close outside the recorded range. If you prefer intrabar breakout rules (e.g., high/low breach without close), you must adjust the condition accordingly.
The recorded range is taken from a single candle at the exact configured UTC time. If there are missing bars or the chart timeframe doesn't align, the intended candle may differ — choose the target time and chart timeframe consistently.
Only a single active position is allowed at a time (the script checks strategy.position_size == 0 before entries).
Example setups
EURUSD (Forex): Target Time 07:00 UTC — captures London open range.
Nifty / Index: Target Time 09:15 UTC — captures local session open range.
Crypto: Target Time 00:00 UTC — captures daily reset candle for breakout.
Risk disclaimer
This script is educational and provided as-is. Past performance is not indicative of future results. Use proper risk management, test on historical data, and consider slippage and commissions. Do not trade real capital without sufficient testing.
Change log
v1.0 — Initial release: range capture, box and level drawing, long/short entry by close breakout, SL at opposite boundary, TP via Risk:Reward, alerts, info table.
If you want, I can also:
Provide a short README version (2–3 lines) for the TradingView “Short description” field.
Add a couple of suggested alert templates for the TradingView alert dialog (if you want alerts that include variable placeholders).
Convert the disclaimer into multiple language versions.
Candle Breakout Strategy — identifies a user-specified candle (UTC time), draws its high/low range, then enters on breakouts with configurable stop-loss, take-profit (via Risk:Reward) and optional alerts.
Full description (ready-to-paste)
Candle Breakout Strategy
Version 1.0 — Strategy script (Pine v5)
Overview
The Candle Breakout Strategy automatically captures a single "range candle" at a user-specified UTC time, draws its high/low as a visible box and dashed level lines, and waits for a breakout. When price closes above the range high it enters a Long; when price closes below the range low it enters a Short. Stop-loss is placed at the opposite range boundary and take-profit is calculated with a user-configurable Risk:Reward multiplier. Alerts for entries can be enabled.
This strategy is intended for breakout style trading where a clearly defined intraday range is established at a fixed time. It is simple, transparent and easy to adapt to multiple symbols and timeframes.
How it works (step-by-step)
On every bar the script checks the current UTC time.
When the first bar that matches the configured Target Hour:Target Minute (UTC) appears, the script records that candle’s high and low. This defines the breakout range.
A box and dashed lines are drawn on the chart to display the range and extended to the right while the range is active.
The script then waits for price to close outside the box:
Close > Range High → Long entry
Close < Range Low → Short entry
When an entry triggers:
Stop-loss = opposite range boundary (range low for longs, range high for shorts).
Take-profit = entry ± (risk × Risk:Reward). Risk is computed as the distance between entry price and stop-loss.
After entry the range becomes inactive (waitingForBreakout = false) until the next configured target time.
Inputs / Parameters
Target Hour (UTC) — the hour (0–23) in UTC when the range candle is detected.
Target Minute — minute (0–59) of the target candle.
Risk:Reward Ratio — multiplier for computing take profit from risk (0.5–10). Example: 2 means TP = entry + 2×risk.
Enable Alerts — turn on/off entry alerts (string message sent once per bar when an entry occurs).
Show Last Box Only (internal behavior) — when enabled the previous box is deleted at the next range creation so only the most recent range is visible (default behavior in the script).
Visuals & On-chart Info
A semi-transparent blue box shows the recorded range and extends to the right while active.
Dashed horizontal lines mark the range high and low.
On-chart shapes: green triangle below bar for Long signals, red triangle above bar for Short signals.
An information table (top-right) displays:
Target Time (UTC)
Active Range (Yes / No)
Range High
Range Low
Risk:Reward
Alerts
If Enable Alerts is on, the script sends an alert with the following formats when an entry occurs:
Long alert:
🟢 LONG SIGNAL
Entry Price: <price>
Stop Loss: <price>
Take Profit: <price>
Short alert:
🔴 SHORT SIGNAL
Entry Price: <price>
Stop Loss: <price>
Take Profit: <price>
Use TradingView's alert dialog to create alerts based on the script — select the script’s alert condition or use the alert() messages.
Recommended usage & tips
Timeframe: This strategy works on any timeframe but the definition of "candle at target time" depends on the chart timeframe. For intraday breakout styles, use 1m — 60m charts depending on the session you want to capture.
Target Time: Choose a time that is meaningful for the instrument (e.g., market open, economic release, session overlap). All times are handled in UTC.
Position Sizing: The script’s example uses strategy.percent_of_equity with 100% default — change default_qty_value or strategy settings to suit your risk management.
Filtering: Consider combining this breakout with trend filters (EMA, ADX, etc.) to reduce false breakouts.
Backtesting: Always backtest over a sufficiently large and recent sample. Pay attention to slippage and commission settings in TradingView’s strategy tester.
Known behavior & limitations
The script registers the breakout on close outside the recorded range. If you prefer intrabar breakout rules (e.g., high/low breach without close), you must adjust the condition accordingly.
The recorded range is taken from a single candle at the exact configured UTC time. If there are missing bars or the chart timeframe doesn't align, the intended candle may differ — choose the target time and chart timeframe consistently.
Only a single active position is allowed at a time (the script checks strategy.position_size == 0 before entries).
Example setups
EURUSD (Forex): Target Time 07:00 UTC — captures London open range.
Nifty / Index: Target Time 09:15 UTC — captures local session open range.
Crypto: Target Time 00:00 UTC — captures daily reset candle for breakout.
Risk disclaimer
This script is educational and provided as-is. Past performance is not indicative of future results. Use proper risk management, test on historical data, and consider slippage and commissions. Do not trade real capital without sufficient testing.
Change log
v1.0 — Initial release: range capture, box and level drawing, long/short entry by close breakout, SL at opposite boundary, TP via Risk:Reward, alerts, info table.
If you want, I can also:
Provide a short README version (2–3 lines) for the TradingView “Short description” field.
Add a couple of suggested alert templates for the TradingView alert dialog (if you want alerts that include variable placeholders).
Convert the disclaimer into multiple language versions.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
