//@version=5 strategy("A Sniper Order Flow", overlay=true, initial_capital=1000000, default_qty_type=strategy.fixed, default_qty_value=1, commission_type=strategy.commission.percent, commission_value=0.01, slippage=1, pyramiding=0) // ─── TDI Inputs ───────────────────────────────────────────────────────────────── rsiLen = input.int(13, "RSI Length", minval=1, group="TDI") signalLen = input.int(7, "Signal Length", minval=1, group="TDI") rsiSrc = input.source(close, "RSI Source", group="TDI") // ─── EMA Inputs ───────────────────────────────────────────────────────────────── ema8Len = input.int(8, "EMA 8 Length", group="EMAs") ema14Len = input.int(14, "EMA 14 Length", group="EMAs") ema50Len = input.int(50, "EMA 50 Length", group="EMAs") ema200Len = input.int(200, "EMA 200 Length", group="EMAs") // ─── Exit Inputs (Standardised) ──────────────────────────────────────────────── atrLen = input.int(14, "ATR Length", group="Exits") slMult = input.float(3.0, "SL ATR Multiplier", group="Exits", step=0.1) tpMult = input.float(6.0, "TP ATR Multiplier", group="Exits", step=0.1) riskPct = input.float(1.0, "Risk % per Trade", group="Exits", step=0.1) // ─── TDI Calculations ───────────────────────────────────────────────────────── rsiVal = ta.rma(rsiSrc, rsiLen) signalLine = ta.rma(rsiVal, signalLen) bandwidth = ta.rma(math.abs(rsiVal - signalLine), signalLen) tdiUpper = rsiVal + bandwidth tdiLower = rsiVal - bandwidth // ─── EMA Calculations ───────────────────────────────────────────────────────── ema8 = ta.ema(close, ema8Len) ema14 = ta.ema(close, ema14Len) ema50 = ta.ema(close, ema50Len) ema200 = ta.ema(close, ema200Len) // ─── ATR for Exits ──────────────────────────────────────────────────────────── exitAtr = ta.atr(atrLen) // ─── A+ Setup Conditions ────────────────────────────────────────────────────── // Bullish A+ Setup: TDI RSI crosses above signal + price above 50 EMA + 8>14 EMA bullishSetup = ta.crossover(rsiVal, signalLine) and close > ema50 and ema8 > ema14 // Bearish A+ Setup: TDI RSI crosses below signal + price below 50 EMA + 8<14 EMA bearishSetup = ta.crossunder(rsiVal, signalLine) and close < ema50 and ema8 < ema14 // Trend confirmation: price above 200 EMA for longs, below for shorts bullTrend = close > ema200 bearTrend = close < ema200 // Combined entry signals longCondition = bullishSetup and bullTrend and (strategy.position_size == 0) shortCondition = bearishSetup and bearTrend and (strategy.position_size == 0) // ─── SL/TP Risk Sizing ──────────────────────────────────────────────────────── sl_distance = math.max(exitAtr * slMult, syminfo.mintick * 10) qty = (strategy.equity * (riskPct / 100)) / sl_distance // ─── Entries ─────────────────────────────────────────────────────────────────── if longCondition strategy.entry("Long", strategy.long, qty=qty) if shortCondition strategy.entry("Short", strategy.short, qty=qty) // ─── ATR-Based Exits ─────────────────────────────────────────────────────────── if strategy.position_size > 0 if strategy.position_size > 0 strategy.exit("LX", "Long", stop=strategy.position_avg_price - slMult*exitAtr, limit=strategy.position_avg_price + tpMult*exitAtr) if strategy.position_size < 0 strategy.exit("SX", "Short", stop=strategy.position_avg_price + slMult*exitAtr, limit=strategy.position_avg_price - tpMult*exitAtr) // ─── Visual Elements ─────────────────────────────────────────────────────────── plot(ema8, "EMA 8", color.orange, linewidth=1) plot(ema14, "EMA 14", color.yellow, linewidth=1) plot(ema50, "EMA 50", color=#00BFFF, linewidth=2) plot(ema200, "EMA 200", color.red, linewidth=2) // TDI RSI line plot(rsiVal, "RSI", color.blue, linewidth=2) plot(signalLine, "Signal", color.orange, linewidth=1, style=plot.style_line) plot(tdiUpper, "Upper", color.gray, linewidth=1, style=plot.style_line) plot(tdiLower, "Lower", color.gray, linewidth=1, style=plot.style_line) // A+ Setup labels on live candle if barstate.islast if bullishSetup and bullTrend label.new/bar_index, high, "A+ Long", color=color.green, textcolor=color.white, style=label.style_label_up, size=size.normal if bearishSetup and bearTrend label.new/bar_index, low, "A+ Short", color=color.red, textcolor=color.white, style=label.style_label_down, size=size.normal