GoldMind AI Strategy — Full Script
Pine Script v5 · XAU/USD · EMA + RSI + MACD + ADX + Webhook
Copy Script
//@version=5
strategy(
title = "GoldMind AI Strategy — XAU/USD",
shorttitle = "GOLDMIND",
overlay = true,
default_qty_type = strategy.fixed,
default_qty_value = 1,
initial_capital = 10000,
currency = currency.USD,
pyramiding = 0
)
// ═══════════════════════════════════════════════════════════════
// INPUTS
// ═══════════════════════════════════════════════════════════════
var string WEBHOOK_URL = input.string(
defval = "https://mastertrade.delgara.com/goldmind/broker/webhook",
title = "GoldMind Webhook URL",
tooltip = "GoldMind server endpoint — do not change"
)
var string SECRET = input.string(
defval = "goldmind_tv_secret_change_me",
title = "Webhook Secret",
tooltip = "Must match WEBHOOK_SECRET in server .env"
)
// EMA
ema20_len = input.int(20, "EMA Fast", minval=5)
ema50_len = input.int(50, "EMA Mid", minval=10)
ema200_len = input.int(200, "EMA Slow", minval=50)
// RSI
rsi_len = input.int(14, "RSI Period", minval=5)
rsi_ob = input.int(70, "RSI Overbought")
rsi_os = input.int(30, "RSI Oversold")
// ATR — dynamic SL/TP
atr_len = input.int(14, "ATR Period")
atr_sl_mult = input.float(1.5, "ATR × SL", step=0.1)
atr_tp1_mult = input.float(2.0, "ATR × TP1", step=0.1)
atr_tp2_mult = input.float(3.5, "ATR × TP2", step=0.1)
atr_tp3_mult = input.float(5.0, "ATR × TP3", step=0.1)
// MACD
macd_fast = input.int(12, "MACD Fast")
macd_slow = input.int(26, "MACD Slow")
macd_sig = input.int(9, "MACD Signal")
// Filters
use_session = input.bool(true, "London/NY session only")
min_adx = input.float(20.0, "Min ADX (trend filter)", step=1.0)
// ═══════════════════════════════════════════════════════════════
// INDICATORS
// ═══════════════════════════════════════════════════════════════
ema20 = ta.ema(close, ema20_len)
ema50 = ta.ema(close, ema50_len)
ema200 = ta.ema(close, ema200_len)
rsi = ta.rsi(close, rsi_len)
atr = ta.atr(atr_len)
[macd_line, signal_line, macd_hist] = ta.macd(close, macd_fast, macd_slow, macd_sig)
// ADX
up_move = high - high[1]
down_move = low[1] - low
plus_dm = up_move > down_move and up_move > 0 ? up_move : 0.0
minus_dm = down_move > up_move and down_move > 0 ? down_move : 0.0
atr14 = ta.rma(ta.tr(true), 14)
plus_di = 100 * ta.rma(plus_dm, 14) / atr14
minus_di = 100 * ta.rma(minus_dm, 14) / atr14
adx = ta.rma(100 * math.abs(plus_di - minus_di) / (plus_di + minus_di), 14)
// Session (London 07:00 + NY 14:00 → 21:00 UTC)
in_session = use_session ? (hour(time,"UTC") >= 7 and hour(time,"UTC") < 21) : true
// SL/TP distances
sl_dist = atr * atr_sl_mult
tp1_dist = atr * atr_tp1_mult
tp2_dist = atr * atr_tp2_mult
tp3_dist = atr * atr_tp3_mult
// ═══════════════════════════════════════════════════════════════
// ENTRY CONDITIONS
// ═══════════════════════════════════════════════════════════════
// BUY: price above EMA200 + EMA20>EMA50 + RSI 50-70 + MACD rising + ADX trending
buy_cond = (
close > ema200 and ema20 > ema50 and
rsi > 50 and rsi < rsi_ob and
macd_hist > 0 and macd_hist > macd_hist[1] and
adx > min_adx and in_session
)
// SELL: price below EMA200 + EMA20 rsi_os and
macd_hist < 0 and macd_hist < macd_hist[1] and
adx > min_adx and in_session
)
// RSI extreme reversals
rsi_buy = rsi < rsi_os and rsi > rsi[1] and in_session
rsi_sell = rsi > rsi_ob and rsi < rsi[1] and in_session
long_signal = buy_cond or rsi_buy
short_signal = sell_cond or rsi_sell
// ═══════════════════════════════════════════════════════════════
// EXECUTION + WEBHOOK ALERTS
// ═══════════════════════════════════════════════════════════════
var float entry_price = na
var float sl_price = na
var float tp1_price = na
if long_signal and strategy.position_size == 0
entry_price := close
sl_price := close - sl_dist
tp1_price := close + tp1_dist
strategy.entry("Long", strategy.long, comment="BUY")
strategy.exit("Long Exit", "Long", stop=sl_price, limit=tp1_price)
// → fires JSON alert to GoldMind server → OANDA executes
alert(str.format(
'{{"action":"BUY","price":{0},"stop_loss":{1},"tp1":{2},"tp2":{3},"secret":"{4}"}}',
entry_price, sl_price,
entry_price + tp1_dist, entry_price + tp2_dist, SECRET
), alert.freq_once_per_bar)
if short_signal and strategy.position_size == 0
entry_price := close
sl_price := close + sl_dist
tp1_price := close - tp1_dist
strategy.entry("Short", strategy.short, comment="SELL")
strategy.exit("Short Exit", "Short", stop=sl_price, limit=tp1_price)
alert(str.format(
'{{"action":"SELL","price":{0},"stop_loss":{1},"tp1":{2},"tp2":{3},"secret":"{4}"}}',
entry_price, sl_price,
entry_price - tp1_dist, entry_price - tp2_dist, SECRET
), alert.freq_once_per_bar)
close_long = strategy.position_size > 0 and (rsi > rsi_ob or close < ema50)
close_short = strategy.position_size < 0 and (rsi < rsi_os or close > ema50)
if close_long or close_short
strategy.close_all(comment="EXIT")
alert(str.format('{{"action":"CLOSE","price":{0},"secret":"{1}"}}',
close, SECRET), alert.freq_once_per_bar)
// ═══════════════════════════════════════════════════════════════
// VISUALS
// ═══════════════════════════════════════════════════════════════
plot(ema20, "EMA 20", color=color.new(color.blue, 0), linewidth=1)
plot(ema50, "EMA 50", color=color.new(color.orange, 0), linewidth=1)
plot(ema200, "EMA 200", color=color.new(color.red, 0), linewidth=2)
plotshape(long_signal and strategy.position_size == 0,
title="BUY", style=shape.triangleup, location=location.belowbar,
color=color.lime, size=size.small, text="BUY")
plotshape(short_signal and strategy.position_size == 0,
title="SELL", style=shape.triangledown, location=location.abovebar,
color=color.red, size=size.small, text="SELL")
plot(strategy.position_size != 0 ? sl_price : na, "SL", color=color.red, style=plot.style_linebr)
plot(strategy.position_size != 0 ? tp1_price : na, "TP1", color=color.green, style=plot.style_linebr)
bgcolor(in_session ? color.new(color.blue, 97) : na)
var table t = table.new(position.top_right, 2, 6, border_width=1)
if barstate.islast
table.cell(t, 0, 0, "GoldMind AI", bgcolor=color.new(color.orange,20), text_color=color.white)
table.cell(t, 1, 0, "XAU/USD", bgcolor=color.new(color.orange,20), text_color=color.white)
table.cell(t, 0, 1, "EMA20", text_color=color.gray)
table.cell(t, 1, 1, str.tostring(math.round(ema20,2)), text_color=color.blue)
table.cell(t, 0, 2, "RSI", text_color=color.gray)
table.cell(t, 1, 2, str.tostring(math.round(rsi,1)),
text_color=rsi>rsi_ob?color.red:rsimin_adx?color.lime:color.orange)
table.cell(t, 0, 4, "Session", text_color=color.gray)
table.cell(t, 1, 4, in_session?"ACTIVE":"CLOSED",
text_color=in_session?color.lime:color.red)
table.cell(t, 0, 5, "Position", text_color=color.gray)
table.cell(t, 1, 5,
strategy.position_size>0?"LONG":strategy.position_size<0?"SHORT":"FLAT",
text_color=strategy.position_size>0?color.lime:strategy.position_size<0?color.red:color.gray)