Reza

Wait 5 sec.

RezaBitcoin / TetherUSBINANCE:BTCUSDTBrezafadaei1986 //@version=6 strategy("BTC Trend Pullback 15m - Test v1", overlay=true, initial_capital=10000, currency=currency.USD, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.05, slippage=2, default_qty_type=strategy.percent_of_equity, default_qty_value=10, process_orders_on_close=true) // Inputs fastLen = input.int(50, "Local EMA Fast", minval=1) slowLen = input.int(200, "Local EMA Slow", minval=2) pullLen = input.int(20, "Pullback EMA", minval=1) htf = input.timeframe("60", "Trend timeframe") htfFast = input.int(50, "HTF EMA Fast", minval=1) htfSlow = input.int(200, "HTF EMA Slow", minval=2) adxLen = input.int(14, "DMI / ADX Length", minval=2) adxMin = input.float(18, "Minimum ADX", minval=1) atrLen = input.int(14, "ATR Length", minval=1) atrMult = input.float(1.5, "Stop ATR Multiplier", minval=0.1, step=0.1) rr = input.float(2.5, "Target R Multiple", minval=0.5, step=0.25) useVolume = input.bool(false, "Require above-average volume") volLen = input.int(20, "Volume Average Length", minval=1) // Local trend emaFast = ta.ema(close, fastLen) emaSlow = ta.ema(close, slowLen) emaPull = ta.ema(close, pullLen) // Confirmed higher-timeframe trend values htfFastValue = request.security( syminfo.tickerid, htf, ta.ema(close, htfFast), lookahead=barmerge.lookahead_on) htfSlowValue = request.security( syminfo.tickerid, htf, ta.ema(close, htfSlow), lookahead=barmerge.lookahead_on) htfBull = htfFastValue > htfSlowValue htfBear = htfFastValue < htfSlowValue // Trend strength and volatility = ta.dmi(adxLen, adxLen) atr = ta.atr(atrLen) volOK = not useVolume or volume > ta.sma(volume, volLen) // Pullback and reclaim recentLowTouch = ta.lowest(low, 3) = emaPull longSignal = barstate.isconfirmed and htfBull and emaFast > emaSlow and close > emaFast and ta.crossover(close, emaPull) and recentLowTouch and adx >= adxMin and diPlus > diMinus and volOK shortSignal = barstate.isconfirmed and htfBear and emaFast < emaSlow and close < emaFast and ta.crossunder(close, emaPull) and recentHighTouch and adx >= adxMin and diMinus > diPlus and volOK // Freeze initial stop and target when signal occurs var float activeStop = na var float activeTarget = na if strategy.position_size == 0 activeStop := na activeTarget := na if longSignal and strategy.position_size == 0 riskDist = atr * atrMult activeStop := close - riskDist activeTarget := close + riskDist * rr strategy.entry("Long", strategy.long) strategy.exit("Long Exit", "Long", stop=activeStop, limit=activeTarget) if shortSignal and strategy.position_size == 0 riskDist = atr * atrMult activeStop := close + riskDist activeTarget := close - riskDist * rr strategy.entry("Short", strategy.short) strategy.exit("Short Exit", "Short", stop=activeStop, limit=activeTarget) // Keep exit orders active if strategy.position_size > 0 and not na(activeStop) strategy.exit("Long Exit", "Long", stop=activeStop, limit=activeTarget) if strategy.position_size < 0 and not na(activeStop) strategy.exit("Short Exit", "Short", stop=activeStop, limit=activeTarget) // Visuals plot(emaPull, "EMA 20", color=color.yellow) plot(emaFast, "EMA 50", color=color.aqua) plot(emaSlow, "EMA 200", color=color.orange) plot(strategy.position_size != 0 ? activeStop : na, "Stop", color=color.red, style=plot.style_linebr) plot(strategy.position_size != 0 ? activeTarget : na, "Target", color=color.lime, style=plot.style_linebr) plotshape(longSignal and strategy.position_size == 0, title="Long Setup", style=shape.labelup, location=location.belowbar, color=color.green, text="LONG", textcolor=color.white, size=size.tiny) plotshape(shortSignal and strategy.position_size == 0, title="Short Setup", style=shape.labeldown, location=location.abovebar, color=color.red, text="SHORT", textcolor=color.white, size=size.tiny)