//@version=6
strategy(
title = "MACD + RSI Confluence with ATR Brackets",
shorttitle = "MACD-RSI-ATR v6",
overlay = true,
initial_capital = 10000,
default_qty_type = strategy.percent_of_equity,
default_qty_value = 10,
commission_type = strategy.commission.percent,
commission_value = 0.05,
slippage = 2
)
// ─── Inputs ──────────────────────────────────────────────────────────────────
emaLen = input.int(200, "Regime EMA Length", minval = 10, group = "Trend & Momentum")
rsiLen = input.int(14, "RSI Length", minval = 2, group = "Trend & Momentum")
rsiCeiling = input.float(55.0, "Max RSI on Entry", minval = 10.0, maxval = 90.0, group = "Trend & Momentum")
atrLen = input.int(14, "ATR Length", minval = 1, group = "Risk Management")
stopMult = input.float(2.0, "Stop Loss (ATR Multiple)", minval = 0.5, step = 0.25, group = "Risk Management")
targetMult = input.float(3.0, "Take Profit (ATR Multiple)", minval = 0.5, step = 0.25, group = "Risk Management")
// ─── Core Calculations (Hoisted for Pine Script v6 Lazy Evaluation) ─────────
regimeEma = ta.ema(close, emaLen)
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
rsiVal = ta.rsi(close, rsiLen)
atrVal = ta.atr(atrLen)
macdCross = ta.crossover(macdLine, signalLine)
// ─── Entry & Bracket State ───────────────────────────────────────────────────
longSignal = barstate.isconfirmed and close > regimeEma and macdCross and rsiVal < rsiCeiling
var float activeStop = na
var float activeTarget = na
if longSignal and strategy.position_size == 0
activeStop := close - atrVal * stopMult
activeTarget := close + atrVal * targetMult
strategy.entry("Long", strategy.long, comment = "MACD+RSI Long")
if strategy.position_size > 0
strategy.exit("Exit Long", from_entry = "Long", stop = activeStop, limit = activeTarget)
else
activeStop := na
activeTarget := na
// ─── Price-Scale Visuals ─────────────────────────────────────────────────────
plot(regimeEma, "Regime EMA 200", color = color.new(#2962ff, 0), linewidth = 2)
plot(activeStop, "ATR Stop Loss", color = color.new(#ef5350, 0), style = plot.style_linebr)
plot(activeTarget, "ATR Target", color = color.new(#26a69a, 0), style = plot.style_linebr)
plotshape(longSignal and strategy.position_size == 0, "Long Signal", shape.triangleup, location.belowbar, #26a69a, size = size.small)