OPEN-SOURCE SCRIPT

My script

60
//version=5
strategy("Advanced Breakout + EMA Trend Strategy [Leverage Ready]", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)

// === INPUTS === //
fastEMA_len = input.int(9, title="Fast EMA")
slowEMA_len = input.int(21, title="Slow EMA")
atrLen = input.int(14, title="ATR Length")
atr_mult_sl = input.float(1.5, title="ATR Stop Loss Multiplier")
atr_mult_tp = input.float(3.0, title="ATR Take Profit Multiplier")
consolidationBars = input.int(20, title="Consolidation Lookback")
volumeSpikeMult = input.float(1.8, title="Volume Spike Multiplier")
leverage = input.int(10, title="Leverage", minval=1)

// === CALCULATIONS === //
fastEMA = ta.ema(close, fastEMA_len)
slowEMA = ta.ema(close, slowEMA_len)
atr = ta.atr(atrLen)
rangeHigh = ta.highest(high, consolidationBars)
rangeLow = ta.lowest(low, consolidationBars)
volumeAvg = ta.sma(volume, consolidationBars)

// === MARKET CONDITIONS === //
isTrendingUp = fastEMA > slowEMA
isTrendingDown = fastEMA < slowEMA
isConsolidating = (rangeHigh - rangeLow) / close < 0.02
isBreakoutUp = close > rangeHigh and volume > volumeAvg * volumeSpikeMult
isBreakoutDown = close < rangeLow and volume > volumeAvg * volumeSpikeMult

// === ENTRY CONDITIONS === //
enterLong = isConsolidating and isBreakoutUp and isTrendingUp
enterShort = isConsolidating and isBreakoutDown and isTrendingDown

// === EXIT PRICES === //
longSL = close - atr * atr_mult_sl
longTP = close + atr * atr_mult_tp
shortSL = close + atr * atr_mult_sl
shortTP = close - atr * atr_mult_tp

// === ENTRY/EXIT EXECUTION === //
if (enterLong)
strategy.entry("Long", strategy.long, comment="Long Entry")
strategy.exit("TP/SL Long", from_entry="Long", stop=longSL, limit=longTP)

if (enterShort)
strategy.entry("Short", strategy.short, comment="Short Entry")
strategy.exit("TP/SL Short", from_entry="Short", stop=shortSL, limit=shortTP)

// === CHART PLOTTING === //
plot(fastEMA, color=color.green, title="Fast EMA")
plot(slowEMA, color=color.red, title="Slow EMA")
plotshape(enterLong, title="Long Entry", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(enterShort, title="Short Entry", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")

// === ALERT MESSAGES === //
alertcondition(enterLong, title="Long Signal", message="Long Entry Signal: BUY at {{close}} | Leverage: " + str.tostring(leverage))
alertcondition(enterShort, title="Short Signal", message="Short Entry Signal: SELL at {{close}} | Leverage: " + str.tostring(leverage))

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.