//@version=5
strategy("Gold Scalping (Anti-Repainting)", overlay=true, precision=0,
explicit_plot_zorder=true, max_labels_count=500)
// === INPUTS ===
sensitivity = [Link](4, "Sensitivity (0.5 - 4)", 0.5, 4, step=0.1)
emaCloud = [Link](false, "EMA Cloud")
suppRes = [Link](false, "Support & Resistance")
breaks = [Link](false, "Breaks")
usePsar = [Link](false, "PSAR")
emaEnergy = [Link](true, "EMA Energy")
useMTF = [Link](true, "Usa filtro MTF (SMA9 su TF superiore)")
higher_tf = [Link]("30", "Timeframe superiore")
// === TP / SL SETTINGS ===
tpMode = [Link]("Fixed", options=["Fixed", "ATR-based"], title="TP
Mode")
tpFixed = [Link](100, title="TP Fisso (punti)", minval=1)
tpAtrMult = [Link](2.0, title="TP Moltiplicatore × ATR", minval=0.1,
step=0.1)
slPoints = [Link](50, title="Stop Loss (punti)", minval=1)
atr = [Link](14)
tpDynamic = tpMode == "Fixed" ? tpFixed : atr * tpAtrMult
// === SUPER TREND ===
supertrend(_src, factor, atrLen) =>
atr_st = [Link](atrLen)
upperBand = _src + factor * atr_st
lowerBand = _src - factor * atr_st
prevUpper = nz(upperBand[1])
prevLower = nz(lowerBand[1])
upperBand := upperBand < prevUpper or close[1] > prevUpper ? upperBand :
prevUpper
lowerBand := lowerBand > prevLower or close[1] < prevLower ? lowerBand :
prevLower
int direction = na
float super = na
float prevSuper = nz(super[1])
if na(atr_st[1])
direction := 1
else if prevSuper == prevUpper
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
super := direction == -1 ? lowerBand : upperBand
[super, direction]
[supertrend, direction] = supertrend(close, sensitivity, 11)
// === MEDIA MOBILI ===
sma9 = [Link](close, 13)
ema1 = [Link](high, 9)
ema2 = [Link](high, 12)
ema3 = [Link](high, 15)
ema4 = [Link](high, 18)
ocAvg = [Link](open, close)
psar = [Link](0.02, 0.02, 0.2)
// === COLORI ===
green = #0290f6
red = #cf2dfc
emaCloudColor = emaCloud ? (close > supertrend ? green : red) : na
emaEnergyColor(ma) => emaEnergy ? (close >= ma ? green : red) : na
// === PLOT ===
plot(ema1, "", na)
plot(ema2, "", emaCloudColor)
plot(ema3, "", emaCloudColor)
plot(ema4, "", na)
plot(psar, "PSAR", usePsar ? (psar < ocAvg ? green : red) : na, 1,
plot.style_circles)
barcolor(close > supertrend ? green : red)
// === MTF CONDITION ===
sma9HTF = [Link]([Link], higher_tf, [Link](close, 13))
mtfLong = not useMTF or close >= sma9HTF
mtfShort = not useMTF or close <= sma9HTF
// === SIGNALS (ANTI-REPAINT) ===
bull = [Link](close, supertrend) and close >= sma9 and mtfLong and
[Link]
bear = [Link](close, supertrend) and close <= sma9 and mtfShort and
[Link]
y1 = low - ([Link](30) * 2)
y2 = high + ([Link](30) * 2)
if bull
[Link]("Long", [Link])
[Link]("Exit Long", from_entry="Long", profit=tpDynamic, loss=slPoints)
[Link](bar_index, y1, "BUY", xloc.bar_index, [Link], green,
label.style_label_up, [Link])
if bear
[Link]("Short", [Link])
[Link]("Exit Short", from_entry="Short", profit=tpDynamic,
loss=slPoints)
[Link](bar_index, y2, "SELL", xloc.bar_index, [Link], red,
label.style_label_down, [Link])
// === SUPPORTI / RESISTENZE NON-REPAINT ===
barsL = 10
barsR = 10
isPivotHigh = high[barsR] == [Link](high, barsL + barsR + 1)
isPivotLow = low[barsR] == [Link](low, barsL + barsR + 1)
plotPivotHigh = isPivotHigh ? high[barsR] : na
plotPivotLow = isPivotLow ? low[barsR] : na
plot(plotPivotHigh, "Resistance", suppRes ? red : na, 2, offset=-(barsR))
plot(plotPivotLow, "Support", suppRes ? green : na, 2, offset=-(barsR))
// === BREAKOUT (non repaint) ===
breakRes = [Link](close, plotPivotHigh) and [Link]
breakSup = [Link](close, plotPivotLow) and [Link]
plotshape(breaks and breakRes, "Break Res", [Link], [Link],
green, 0, "B", [Link], false, [Link])
plotshape(breaks and breakSup, "Break Sup", [Link], [Link],
red, 0, "B", [Link], false, [Link])
// === ALERTS (solo su barre confermate) ===
alertcondition(bull or bear or breakRes or breakSup, "Alert Any", "AI Signals Gold\
nAlert Triggered on {{ticker}} @ {{close}}")
alertcondition(bull, "Alert Buy", "AI Signals Gold\nBuy {{ticker}} @ {{close}}")
alertcondition(bear, "Alert Sell", "AI Signals Gold\nSell {{ticker}} @ {{close}}")
alertcondition(breakRes, "Broke Resistance", "AI Signals Gold\nBroke Resistance on
{{ticker}} @ {{close}}")
alertcondition(breakSup, "Broke Support", "AI Signals Gold\nBroke Support on
{{ticker}} @ {{close}}")