OPEN-SOURCE SCRIPT

Gold Trading Strategy

//version=5
indicator("Gold Trading Strategy", overlay=true)

// Input parameters
shortMA = ta.sma(close, 9)
longMA = ta.sma(close, 21)
rsi = ta.rsi(close, 14)
[bbUpper, bbMiddle, bbLower] = ta.bb(close, 20, 2)

// Time filter (IST time range)
timeFilter = (hour >= 12 and hour < 14) or (hour >= 18 and hour < 21)

// Buy condition
buyCondition = ta.crossover(shortMA, longMA) and rsi > 50 and close > bbMiddle and timeFilter
// Sell condition
sellCondition = ta.crossunder(shortMA, longMA) and rsi < 50 and close < bbMiddle and timeFilter

// Plot MAs
plot(shortMA, color=color.blue, title="9 MA")
plot(longMA, color=color.red, title="21 MA")

// Plot Bollinger Bands
plot(bbUpper, color=color.gray, title="BB Upper")
plot(bbMiddle, color=color.gray, title="BB Middle")
plot(bbLower, color=color.gray, title="BB Lower")

// Plot Buy & Sell signals
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.labelup, size=size.large, title="Buy Signal")
plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.labeldown, size=size.large, title="Sell Signal")

// Plot Entry & Exit Markers
plotshape(series=buyCondition, location=location.belowbar, color=color.blue, style=shape.triangleup, size=size.large, title="Entry")
plotshape(series=sellCondition, location=location.abovebar, color=color.orange, style=shape.triangledown, size=size.large, title="Exit")

// Add text labels for entry and exit points
var float labelOffset = ta.atr(14) // Offset labels for better visibility

if buyCondition
label.new(x=time, y=low - labelOffset, text="Entry", color=color.blue, textcolor=color.white, size=size.large, style=label.style_label_down)

if sellCondition
label.new(x=time, y=high + labelOffset, text="Exit", color=color.orange, textcolor=color.white, size=size.large, style=label.style_label_up)

Penafian