0% found this document useful (0 votes)
69 views3 pages

Swing Trading EMAs with Alerts

This document is a Pine Script code for a trading indicator that utilizes Exponential Moving Averages (EMAs), Relative Strength Index (RSI), Moving Average Convergence Divergence (MACD), and Average True Range (ATR) to generate buy and sell signals. It calculates various EMAs, RSI, MACD, average volume, and relative volume, and displays these metrics in a table along with trading suggestions. Alerts are set for buy and sell conditions based on the defined criteria for long and short positions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views3 pages

Swing Trading EMAs with Alerts

This document is a Pine Script code for a trading indicator that utilizes Exponential Moving Averages (EMAs), Relative Strength Index (RSI), Moving Average Convergence Divergence (MACD), and Average True Range (ATR) to generate buy and sell signals. It calculates various EMAs, RSI, MACD, average volume, and relative volume, and displays these metrics in a table along with trading suggestions. Alerts are set for buy and sell conditions based on the defined criteria for long and short positions.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

//@version=5

indicator("Swing Trading EMAs with RSI, MACD, ATR, and Suggestions", overlay=true)

// Calcular EMAs
ema5 = [Link](close, 5)
ema10 = [Link](close, 10)
ema20 = [Link](close, 20)
ema50 = [Link](close, 50)
ema200 = [Link](close, 200)

// Calcular RSI
rsiLength = 14
rsi = [Link](close, rsiLength)

// Calcular MACD con parámetros (10, 20, 5)


[macdLine, signalLine, _] = [Link](close, 10, 20, 5)

// Calcular Volumen Promedio


volumen_promedio = [Link](volume, 20)

// Calcular Volumen Relativo


volumen_relativo = volume / volumen_promedio
volumen_relativo_porcentaje = volumen_relativo * 100

// Calcular ATR
atrLength = 14
atr = [Link](atrLength)

// Función para determinar el color de la EMA según la tendencia


getColor(ema) =>
[Link](ema) >= 0 ? [Link] : [Link]

// Plotear EMAs con grosores y colores diferenciados


plot(ema5, color=getColor(ema5), linewidth=1, title="EMA 5")
plot(ema10, color=getColor(ema10), linewidth=2, title="EMA 10")
plot(ema20, color=getColor(ema20), linewidth=3, title="EMA 20")
plot(ema50, color=[Link], linewidth=2, title="EMA 50")
plot(ema200, color=[Link], linewidth=3, title="EMA 200")

// Calcular porcentaje del precio actual respecto a cada EMA


pct_ema5 = (close / ema5) * 100 - 100
pct_ema10 = (close / ema10) * 100 - 100
pct_ema20 = (close / ema20) * 100 - 100
pct_ema50 = (close / ema50) * 100 - 100
pct_ema200 = (close / ema200) * 100 - 100

// Condiciones de entrada y salida


longCondition = (ema5 > ema10) and (ema10 > ema20) and (ema20 > ema50) and (rsi < 70) and
(macdLine > signalLine)
shortCondition = (ema5 < ema10) and (ema10 < ema20) and (ema20 < ema50) and (rsi > 30)
and (macdLine < signalLine)

// Alertas
alertcondition(longCondition, title="Buy Alert", message="Crossover: Buy Signal")
alertcondition(shortCondition, title="Sell Alert", message="Crossover: Sell Signal")

// Tabla de indicadores
var table indicatorTable = [Link](position.top_right, 2, 11)

if [Link]
[Link](indicatorTable, 0, 0, "Signal", text_size=[Link], bgcolor=[Link])
[Link](indicatorTable, 1, 0, longCondition ? "BUY" : shortCondition ? "SELL" :
"WAIT",
text_size=[Link], bgcolor=longCondition ? [Link] : shortCondition ?
[Link] : [Link])

// Colores para los valores de la tabla según tendencia


valueColorEMA5 = pct_ema5 > 0 ? [Link] : [Link]
valueColorEMA10 = pct_ema10 > 0 ? [Link] : [Link]
valueColorEMA20 = pct_ema20 > 0 ? [Link] : [Link]
valueColorEMA50 = pct_ema50 > 0 ? [Link] : [Link]
valueColorEMA200 = pct_ema200 > 0 ? [Link] : [Link]

[Link](indicatorTable, 0, 1, "EMA 5 %", text_size=[Link], bgcolor=[Link])


[Link](indicatorTable, 1, 1, [Link](pct_ema5, [Link]) + "%",
text_size=[Link], text_color=valueColorEMA5)

[Link](indicatorTable, 0, 2, "EMA 10 %", text_size=[Link],


bgcolor=[Link])
[Link](indicatorTable, 1, 2, [Link](pct_ema10, [Link]) + "%",
text_size=[Link], text_color=valueColorEMA10)

[Link](indicatorTable, 0, 3, "EMA 20 %", text_size=[Link],


bgcolor=[Link])
[Link](indicatorTable, 1, 3, [Link](pct_ema20, [Link]) + "%",
text_size=[Link], text_color=valueColorEMA20)

[Link](indicatorTable, 0, 4, "EMA 50 %", text_size=[Link],


bgcolor=[Link])
[Link](indicatorTable, 1, 4, [Link](pct_ema50, [Link]) + "%",
text_size=[Link], text_color=valueColorEMA50)

[Link](indicatorTable, 0, 5, "EMA 200 %", text_size=[Link],


bgcolor=[Link])
[Link](indicatorTable, 1, 5, [Link](pct_ema200, [Link]) + "%",
text_size=[Link], text_color=valueColorEMA200)

[Link](indicatorTable, 0, 6, "RSI", text_size=[Link], bgcolor=[Link])


[Link](indicatorTable, 1, 6, [Link](rsi, [Link]),
text_size=[Link])

[Link](indicatorTable, 0, 7, "MACD", text_size=[Link], bgcolor=[Link])


[Link](indicatorTable, 1, 7, [Link](macdLine - signalLine, [Link]),
text_size=[Link])

[Link](indicatorTable, 0, 8, "ATR", text_size=[Link], bgcolor=[Link])


[Link](indicatorTable, 1, 8, [Link](atr, [Link]),
text_size=[Link])

[Link](indicatorTable, 0, 9, "Rel Volume %", text_size=[Link],


bgcolor=[Link])
[Link](indicatorTable, 1, 9, [Link](volumen_relativo_porcentaje,
[Link]), text_size=[Link])

[Link](indicatorTable, 0, 10, "Suggestion", text_size=[Link],


bgcolor=[Link])
[Link](indicatorTable, 1, 10, longCondition ? "Long" : shortCondition ? "Short" :
"Hold", text_size=[Link], bgcolor=[Link])

You might also like