OPEN-SOURCE SCRIPT

Estrategia XAU/USD

//version=5
indicator("Estrategia XAU/USD: Cruces de EMAs y MACD", overlay=true)

// Parámetros para EMAs
shortEmaLength = input(9, title="Longitud EMA Corta")
longEmaLength = input(21, title="Longitud EMA Larga")

// Cálculo de EMAs
emaShort = ta.ema(close, shortEmaLength)
emaLong = ta.ema(close, longEmaLength)

// Parámetros para MACD
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)

// Señales de compra y venta
buySignal = ta.crossover(emaShort, emaLong) and ta.crossover(macdLine, signalLine)
sellSignal = ta.crossunder(emaShort, emaLong) and ta.crossunder(macdLine, signalLine)

// Visualización de EMAs
plot(emaShort, color=color.blue, title="EMA Corta")
plot(emaLong, color=color.red, title="EMA Larga")

// Marcadores de señales en el gráfico
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="BUY", size=size.small)
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL", size=size.small)

// Mostrar el MACD en un panel separado
hline(0, title="Cero", color=color.gray)
plot(macdLine - signalLine, title="MACD Histograma", color=color.blue, style=plot.style_histogram)
plot(macdLine, color=color.red, title="Línea MACD")
plot(signalLine, color=color.green, title="Línea de Señal")
Moving AveragesVolume

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer