OPEN-SOURCE SCRIPT

Gold_Bulls | TP1+TP2 + Trailing SL + Clean Entry

128
//version=5
indicator("Gold_Bulls | TP1+TP2 + Trailing SL + Clean Entry", overlay=true)

// === INPUTS ===
lookbackDays = input.int(4, "Lookback Days (5m candles)")
pivotLen = input.int(5, "Pivot Strength")
rr1 = input.float(1.0, "TP1 Risk:Reward")
rr2 = input.float(1.5, "TP2 Risk:Reward")
trailATRmult = input.float(1.2, "Trailing SL ATR Multiplier")

// === TIME FILTER ===
inLastDays = time > (timenow - lookbackDays * 24 * 60 * 60 * 1000)

// === PIVOT S/R ===
pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
pivotLow = ta.pivotlow(low, pivotLen, pivotLen)

resistance = not na(pivotHigh) and inLastDays ? pivotHigh : na
support = not na(pivotLow) and inLastDays ? pivotLow : na

plotshape(resistance, location=location.abovebar, style=shape.triangledown, color=color.purple, size=size.tiny)
plotshape(support, location=location.belowbar, style=shape.triangleup, color=color.blue, size=size.tiny)

// === TRACK LAST LEVEL ===
var float lastSupport = na
var float lastResistance = na
if not na(support)
lastSupport := support
if not na(resistance)
lastResistance := resistance

// === ATR for Trailing SL ===
atr = ta.atr(14)

// === VARIABLES ===
var float entryBuy = na
var float slBuy = na
var float tp1Buy = na
var float tp2Buy = na
var float trailBuy = na

var float entrySell = na
var float slSell = na
var float tp1Sell = na
var float tp2Sell = na
var float trailSell = na

// === CONDITIONAL ENTRY ===
buyCond = na(entryBuy) and close > lastResistance and ta.barssince(close > lastResistance) == 0
sellCond = na(entrySell) and close < lastSupport and ta.barssince(close < lastSupport) == 0

// === BUY ENTRY ===
if buyCond
entryBuy := close
slBuy := ta.lowest(low, 6)
risk = entryBuy - slBuy
tp1Buy := entryBuy + risk * rr1
tp2Buy := entryBuy + risk * rr2
trailBuy := entryBuy - atr * trailATRmult

if not na(entryBuy)
trailBuy := math.max(trailBuy, close - atr * trailATRmult)

if close < trailBuy or close > tp2Buy
entryBuy := na
slBuy := na
tp1Buy := na
tp2Buy := na
trailBuy := na

// === SELL ENTRY ===
if sellCond
entrySell := close
slSell := ta.lowest(low, 6) // as per your request
risk = entrySell - slSell
tp1Sell := entrySell - risk * rr1
tp2Sell := entrySell - risk * rr2
trailSell := entrySell + atr * trailATRmult

if not na(entrySell)
trailSell := math.min(trailSell, close + atr * trailATRmult)

if close > trailSell or close < tp2Sell
entrySell := na
slSell := na
tp1Sell := na
tp2Sell := na
trailSell := na

// === PLOTS ===
plotshape(buyCond, location=location.belowbar, style=shape.labelup, color=color.green, text="BUY")
plot(entryBuy, title="Buy Entry", color=color.green)
plot(slBuy, title="Buy SL", color=color.orange)
plot(tp1Buy, title="Buy TP1", color=color.lime)
plot(tp2Buy, title="Buy TP2", color=color.teal)
plot(trailBuy, title="Buy Trailing SL", color=color.yellow)

plotshape(sellCond, location=location.abovebar, style=shape.labeldown, color=color.red, text="SELL")
plot(entrySell, title="Sell Entry", color=color.red)
plot(slSell, title="Sell SL", color=color.orange)
plot(tp1Sell, title="Sell TP1", color=color.green)
plot(tp2Sell, title="Sell TP2", color=color.teal)
plot(trailSell, title="Sell Trailing SL", color=color.yellow)

// === ALERTS ===
alertcondition(buyCond, title="BUY Signal", message="📈 BUY Signal Triggered!")
alertcondition(sellCond, title="SELL Signal", message="📉 SELL Signal Triggered!")

Feragatname

Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.