//@version=5
indicator("Supertrend Breakout Levels with T3/T4 (Auto End)", overlay=true,
max_lines_count=100)
// === User Inputs ===
supertrend_length = input.int(10, "Supertrend ATR Length")
supertrend_factor = input.float(3.0, "Supertrend Factor")
atr_length = input.int(10, "ATR Length")
show_entry = input.bool(true, "Show Entry Level")
show_t1 = input.bool(true, "Show Target 1")
show_t2 = input.bool(true, "Show Target 2")
show_t3 = input.bool(true, "Show Target 3 (ATR*6)")
show_t4 = input.bool(true, "Show Target 4 (ATR*8)")
show_sl = input.bool(true, "Show Stop Loss")
// === 1H Timeframe Data ===
[h_close, h_high, h_low] = request.security(syminfo.tickerid, "60", [close, high,
low])
// === Supertrend Calculation ===
atr_st = ta.atr(supertrend_length)
basic_upper = (h_high + h_low) / 2 + supertrend_factor * atr_st
basic_lower = (h_high + h_low) / 2 - supertrend_factor * atr_st
var float final_upper = na
var float final_lower = na
var int st_dir = 1
final_upper := na(final_upper[1]) ? basic_upper : (basic_upper < final_upper[1] or
h_close[1] > final_upper[1] ? basic_upper : final_upper[1])
final_lower := na(final_lower[1]) ? basic_lower : (basic_lower > final_lower[1] or
h_close[1] < final_lower[1] ? basic_lower : final_lower[1])
prev_st_dir = st_dir
st_dir := h_close > final_upper[1] ? 1 : h_close < final_lower[1] ? -1 : st_dir[1]
supertrend = st_dir == 1 ? final_lower : final_upper
plot(supertrend, color=st_dir == 1 ? color.green : color.red, title="Supertrend")
// === ATR Buffer ===
atr_buf = ta.atr(atr_length)
// === Breakout Detection ===
bull_breakout = ta.crossover(h_close, supertrend)
bear_breakout = ta.crossunder(h_close, supertrend)
// === Declare persistent lines ===
var line entry_line = na
var line t1_line = na
var line t2_line = na
var line t3_line = na
var line t4_line = na
var line sl_line = na
// === On Breakout, create lines with extend.right ===
if bull_breakout
entry = h_high + 0.5 * atr_buf
t1 = entry + 2 * atr_buf
t2 = entry + 4 * atr_buf
t3 = entry + 6 * atr_buf
t4 = entry + 8 * atr_buf
sl = entry - 2 * atr_buf
if show_entry
entry_line := line.new(x1=bar_index, y1=entry, x2=bar_index + 50, y2=entry,
color=color.blue, width=1, extend=extend.right)
if show_t1
t1_line := line.new(x1=bar_index, y1=t1, x2=bar_index + 50, y2=t1,
color=color.green, width=1, extend=extend.right)
if show_t2
t2_line := line.new(x1=bar_index, y1=t2, x2=bar_index + 50, y2=t2,
color=color.lime, width=1, extend=extend.right)
if show_t3
t3_line := line.new(x1=bar_index, y1=t3, x2=bar_index + 50, y2=t3,
color=color.lime, width=1, extend=extend.right)
if show_t4
t4_line := line.new(x1=bar_index, y1=t4, x2=bar_index + 50, y2=t4,
color=color.green, width=1, extend=extend.right)
if show_sl
sl_line := line.new(x1=bar_index, y1=sl, x2=bar_index + 50, y2=sl,
color=color.red, width=1, extend=extend.right)
if bear_breakout
entry = h_low - 0.5 * atr_buf
t1 = entry - 2 * atr_buf
t2 = entry - 4 * atr_buf
t3 = entry - 6 * atr_buf
t4 = entry - 8 * atr_buf
sl = entry + 2 * atr_buf
if show_entry
entry_line := line.new(x1=bar_index, y1=entry, x2=bar_index + 50, y2=entry,
color=color.blue, width=1, extend=extend.right)
if show_t1
t1_line := line.new(x1=bar_index, y1=t1, x2=bar_index + 50, y2=t1,
color=color.green, width=1, extend=extend.right)
if show_t2
t2_line := line.new(x1=bar_index, y1=t2, x2=bar_index + 50, y2=t2,
color=color.lime, width=1, extend=extend.right)
if show_t3
t3_line := line.new(x1=bar_index, y1=t3, x2=bar_index + 50, y2=t3,
color=color.lime, width=1, extend=extend.right)
if show_t4
t4_line := line.new(x1=bar_index, y1=t4, x2=bar_index + 50, y2=t4,
color=color.green, width=1, extend=extend.right)
if show_sl
sl_line := line.new(x1=bar_index, y1=sl, x2=bar_index + 50, y2=sl,
color=color.red, width=1, extend=extend.right)
// === On Supertrend Reversal, stop line extension ===
if (prev_st_dir == 1 and st_dir == -1) or (prev_st_dir == -1 and st_dir == 1)
if not na(entry_line)
line.set_extend(entry_line, extend=extend.none)
if not na(t1_line)
line.set_extend(t1_line, extend=extend.none)
if not na(t2_line)
line.set_extend(t2_line, extend=extend.none)
if not na(t3_line)
line.set_extend(t3_line, extend=extend.none)
if not na(t4_line)
line.set_extend(t4_line, extend=extend.none)
if not na(sl_line)
line.set_extend(sl_line, extend=extend.none)
// === Explanation ===
// ✅ Adds T3 (ATR*6) and T4 (ATR*8) to your systematic breakout trading framework.
// ✅ Lines extend until Supertrend reverses, then stop, maintaining clean pivot-
style visuals.
// ✅ Fully compatible with your systematic ATR + Supertrend workflow.