
Se trata de una estrategia de negociación basada en la ruptura de los puntos altos y bajos de precios en el día, combinada con el indicador ATR para ajustar dinámicamente los objetivos de stop loss y profit. La estrategia se realiza mediante la monitorización de los precios más altos y más bajos del día de negociación anterior y del día de negociación actual, para negociar cuando los precios rompen estos niveles clave. La estrategia también introduce el concepto de zona de amortiguamiento para reducir las señales falsas y utiliza los múltiplos de ATR para establecer parámetros de gestión de riesgo dinámicos.
La lógica central de la estrategia se basa en que los precios se basan en los altibajos previos a la ruptura. En concreto:
Se trata de una estrategia de negociación de ruptura de diseño razonable, lógica y clara. Combinando los indicadores ATR y el concepto de zona de amortiguamiento, equilibra eficazmente las oportunidades de negociación y el control del riesgo. La estrategia tiene un alto grado de visualización y automatización y es adecuada para el uso de los comerciantes diarios.
/*backtest
start: 2025-02-13 00:00:00
end: 2025-02-14 01:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("Previous/Current Day High-Low Breakout Strategy", overlay=true)
// === INPUTS ===
buffer = input(10, title="Buffer Points Above/Below Day High/Low") // 0-10 point buffer
atrMultiplier = input.float(1.5, title="ATR Multiplier for SL/TP") // ATR-based SL & TP
// === DETECT A NEW DAY CORRECTLY ===
dayChange = ta.change(time("D")) != 0 // Returns true when a new day starts
// === FETCH PREVIOUS DAY HIGH & LOW CORRECTLY ===
var float prevDayHigh = na
var float prevDayLow = na
if dayChange
prevDayHigh := high[1] // Store previous day's high
prevDayLow := low[1] // Store previous day's low
// === TRACK CURRENT DAY HIGH & LOW ===
todayHigh = ta.highest(high, ta.barssince(dayChange)) // Highest price so far today
todayLow = ta.lowest(low, ta.barssince(dayChange)) // Lowest price so far today
// === FINAL HIGH/LOW SELECTION (Whichever Happens First) ===
finalHigh = math.max(prevDayHigh, todayHigh) // Use the highest value
finalLow = math.min(prevDayLow, todayLow) // Use the lowest value
// === ENTRY CONDITIONS ===
// 🔹 BUY (LONG) Condition: Closes below final low - buffer
longCondition = close <= (finalLow - buffer)
// 🔻 SELL (SHORT) Condition: Closes above final high + buffer
shortCondition = close >= (finalHigh + buffer)
// === ATR STOP-LOSS & TAKE-PROFIT ===
atr = ta.atr(14)
longSL = close - (atr * atrMultiplier) // Stop-Loss for Long
longTP = close + (atr * atrMultiplier * 2) // Take-Profit for Long
shortSL = close + (atr * atrMultiplier) // Stop-Loss for Short
shortTP = close - (atr * atrMultiplier * 2) // Take-Profit for Short
// === EXECUTE LONG (BUY) TRADE ===
if longCondition
strategy.entry("BUY", strategy.long, comment="🔹 BUY Signal")
strategy.exit("SELL TP", from_entry="BUY", stop=longSL, limit=longTP)
// === EXECUTE SHORT (SELL) TRADE ===
if shortCondition
strategy.entry("SELL", strategy.short, comment="🔻 SELL Signal")
strategy.exit("BUY TP", from_entry="SELL", stop=shortSL, limit=shortTP)
// === PLOT LINES FOR VISUALIZATION ===
plot(finalHigh, title="Breakout High (Prev/Today)", color=color.new(color.blue, 60), linewidth=2, style=plot.style_stepline)
plot(finalLow, title="Breakout Low (Prev/Today)", color=color.new(color.red, 60), linewidth=2, style=plot.style_stepline)
// === ALERT CONDITIONS ===
alertcondition(longCondition, title="🔔 Buy Signal", message="BUY triggered 🚀")
alertcondition(shortCondition, title="🔔 Sell Signal", message="SELL triggered 📉")