
This strategy is a quantitative trading system based on five-minute opening breakout combined with dynamic ATR-based stop-loss management. It identifies key price levels from the first five-minute candle after market open, generates trading signals upon breakouts, and implements dynamic risk control using ATR-based stops.
The core logic includes the following key steps: 1. Determine trading session start time (e.g., NYSE 9:30 AM) 2. Capture the first five-minute candle, recording its open, high, and low prices 3. Generate long signals on high breakout and short signals on low breakout 4. Calculate volatility using 14-period ATR for dynamic stop-loss placement 5. Implement 1:1.5 risk-reward ratio with stop-loss at 1x ATR and take-profit at 1.5x the breakout range
This is a well-structured quantitative trading strategy that achieves controlled risk automated trading through opening price breakout monitoring and ATR dynamic stops. Its core strength lies in its simple yet effective design, though it requires continuous optimization for different market environments and instruments. Traders should conduct thorough backtesting and adjust parameters according to actual conditions before live implementation.
/*backtest
start: 2025-02-13 00:00:00
end: 2025-02-19 00:00:00
period: 5m
basePeriod: 5m
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
//@version=5
strategy("5-Min Open Candle Breakout", overlay=true)
// Get the current bar's year, month, and day
currentYear = year
currentMonth = month
currentDay = dayofmonth
// Define session start time (adjust based on market)
sessionStart = timestamp(currentYear, currentMonth, currentDay, 9, 30) // 9:30 AM for NYSE
// Identify the first 5-minute candle
isFirstCandle = (time >= sessionStart and time < sessionStart + 300000) // 5 min = 300,000 ms
var float openPrice = na
var float highPrice = na
var float lowPrice = na
if isFirstCandle
openPrice := open
highPrice := high
lowPrice := low
// Breakout Conditions
longEntry = ta.crossover(close, highPrice)
shortEntry = ta.crossunder(close, lowPrice)
// Define Stop Loss & Take Profit (Ratio 1:1.5)
slFactor = 1.0 // Stop Loss Multiplier
tpFactor = 1.5 // Take Profit Multiplier
atrValue = ta.atr(14) // Fix: Use ta.atr() instead of atr()
longSL = lowPrice - atrValue * slFactor
longTP = highPrice + (highPrice - lowPrice) * tpFactor
shortSL = highPrice + atrValue * slFactor
shortTP = lowPrice - (highPrice - lowPrice) * tpFactor
// Execute Trades
strategy.entry("Long", strategy.long, when=longEntry)
strategy.exit("Exit Long", from_entry="Long", stop=longSL, limit=longTP)
strategy.entry("Short", strategy.short, when=shortEntry)
strategy.exit("Exit Short", from_entry="Short", stop=shortSL, limit=shortTP)
// Plot High/Low of First Candle
plot(highPrice, title="First 5m High", color=color.green, linewidth=2)
plot(lowPrice, title="First 5m Low", color=color.red, linewidth=2)