//@version=6
strategy("Clean Precision Strategy - AI Driven", overlay=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// === PARAMETERS ===
atrLen = input.int(14, "ATR Length")
atrMult = input.float(1.0, "ATR Multiplier for Volatility Filter")
volumeMultiplier = input.float(1.5, "Volume Spike Multiplier")
tpMultiplier = input.float(1.5, "Take Profit Multiplier")
slMultiplier = input.float(1.0, "Stop Loss Multiplier")
// === TREND DETECTION (Microstructure) ===
higherLow = low > low[1] and low[1] > low[2]
lowerHigh = high < high[1] and high[1] < high[2]
// === ENGULFING CANDLE DETECTION ===
bullEngulf = close > open and close > close[1] and open < close[1]
bearEngulf = close < open and close < close[1] and open > close[1]
// === VOLUME SPIKE ===
avgVolume = ta.sma(volume, 20)
volSpike = volume > avgVolume * volumeMultiplier
// === VOLATILITY FILTER ===
atr = ta.atr(atrLen)
atrOk = atr > ta.sma(atr, atrLen) * atrMult
// === SIGNAL CONDITIONS ===
buySignal = higherLow and bullEngulf and volSpike and atrOk
sellSignal = lowerHigh and bearEngulf and volSpike and atrOk
// === TRADE EXECUTION ===
if buySignal
strategy.entry("Buy", strategy.long)
label.new(bar_index, low, "BUY", style=label.style_label_up, color=color.green,
textcolor=color.white)
// TP and SL lines
line.new(bar_index, low + atr * tpMultiplier, bar_index + 3, low + atr * tpMultiplier,
color=color.green, width=2)
line.new(bar_index, low - atr * slMultiplier, bar_index + 3, low - atr * slMultiplier,
color=color.red, width=2)
if sellSignal
strategy.entry("Sell", strategy.short)
label.new(bar_index, high, "SELL", style=label.style_label_down, color=color.red,
textcolor=color.white)
// TP and SL lines
line.new(bar_index, high - atr * tpMultiplier, bar_index + 3, high - atr * tpMultiplier,
color=color.green, width=2)
line.new(bar_index, high + atr * slMultiplier, bar_index + 3, high + atr * slMultiplier,
color=color.red, width=2)
// === EXITS ===
strategy.exit("TP/SL Buy", from_entry="Buy", profit=atr * tpMultiplier, loss=atr * slMultiplier)
strategy.exit("TP/SL Sell", from_entry="Sell", profit=atr * tpMultiplier, loss=atr * slMultiplier)