0% found this document useful (0 votes)
159 views9 pages

EMA & RSI Trading Strategies

The document describes an EMA trading strategy. It defines 5 and 20 period exponential moving averages (EMA) of closing prices. It generates buy signals when the 5 period EMA crosses above the 20 period EMA, and generates sell signals when the 20 period EMA crosses above the 5 period EMA. It plots the EMAs on the chart and places arrow indicators at the buy and sell signal points.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
159 views9 pages

EMA & RSI Trading Strategies

The document describes an EMA trading strategy. It defines 5 and 20 period exponential moving averages (EMA) of closing prices. It generates buy signals when the 5 period EMA crosses above the 20 period EMA, and generates sell signals when the 20 period EMA crosses above the 5 period EMA. It plots the EMAs on the chart and places arrow indicators at the buy and sell signal points.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

//@version=5

indicator("EMA Strategy", overlay=true)

ema5 = [Link](close, 5)

ema20 = [Link](close, 20)

buy_signal = [Link](ema5, ema20)

sell_signal = [Link](ema20, ema5)

bgcolor(buy_signal ? [Link] : sell_signal ? [Link] : na)

plot(ema5, color=[Link], title="5 EMA")

plot(ema20, color=[Link], title="20 EMA")

plotshape(buy_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Buy")

plotshape(sell_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Sell")
//@version=5

indicator("EMA Strategy", overlay=true)

ema5 = [Link](close, 5)

ema20 = [Link](close, 20)

buy_signal = [Link](ema5, ema20)

sell_signal = [Link](ema20, ema5)

plot(ema5, color=[Link], title="5 EMA")

plot(ema20, color=[Link], title="20 EMA")

plotshape(buy_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Buy")

plotshape(sell_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Sell")
//@version=5

indicator("EMA Strategy", overlay=true)

ema5 = [Link](close, 5)

ema22 = [Link](close, 22)

buy_signal = [Link](ema5, ema22)

sell_signal = [Link](ema22, ema5)

plot(ema5, color=[Link], title="5 EMA")

plot(ema22, color=[Link], title="22 EMA")

plotshape(buy_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Buy")

plotshape(sell_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Sell")
//@version=5

indicator("RSI Strategy", overlay=true)

rsi30 = [Link](close, 30)

rsi50 = [Link](close, 50)

buy_signal = [Link](rsi30, rsi50)

sell_signal = [Link](rsi50, rsi30)

plot(rsi30, color=[Link], title="30 RSI")

plot(rsi50, color=[Link], title="50 RSI")

plotshape(buy_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Buy")

plotshape(sell_signal, style=[Link], color=[Link], size=[Link],


location=[Link], text="Sell")
//@version=4
study("Downtrend Signal")

// Define input variables


fallingCandles1 = input(title="Falling Candles 5 min", type=[Link], defval=7)
fallingCandles2 = input(title="Falling Candles 1 day", type=[Link], defval=4)

// Calculate the difference between close and close of 'fallingCandles' bars ago in 5 min timeframe
falling1 = close - security([Link], "5", close)[fallingCandles1]

// Determine downtrend signal in 5 min timeframe


downtrendSignal1 = true
for i = 1 to fallingCandles1-1
if (close[i] >= close[i+1])
downtrendSignal1 := false

// Plot downtrend signal as triangle in 5 min timeframe


plotshape(downtrendSignal1 and falling1 < 0, style=[Link], color=[Link],
location=[Link], size=[Link])

// Calculate the difference between close and close of 'fallingCandles' bars ago in daily timeframe
falling2 = close - security([Link], "D", close)[fallingCandles2]

// Determine downtrend signal in daily timeframe


downtrendSignal2 = true
for i = 1 to fallingCandles2-1
if (close[i] >= close[i+1])
downtrendSignal2 := false

// Plot downtrend signal as triangle in daily timeframe


plotshape(downtrendSignal2 and falling2 < 0, style=[Link], color=[Link],
location=[Link], size=[Link])
//@version=4
study("Uptrend Signal")

// Define input variables


upwardCandles_5min = input(title="Upward Candles (5-min)", type=[Link], defval=7)
upwardCandles_D = input(title="Upward Candles (Daily)", type=[Link], defval=4)

// Calculate the difference between close and close of 'upwardCandles_5min' bars ago
upward_5min = close - close[upwardCandles_5min]

// Determine uptrend signal in 5-min frame


uptrendSignal_5min = true
for i = 1 to upwardCandles_5min-1
if (close[i] <= close[i+1])
uptrendSignal_5min := false

// Plot uptrend signal as triangle in 5-min frame


plotshape(uptrendSignal_5min and upward_5min > 0 and [Link], style=[Link],
color=[Link], location=[Link], size=[Link], title="Uptrend Signal (5-min)")

// Calculate the difference between close and close of 'upwardCandles_D' bars ago
upward_D = close - security([Link], "D", close)[upwardCandles_D]

// Create a variable for security function value


security_D = security([Link], "D", close)

// Determine uptrend signal in daily frame


uptrendSignal_D = true
for i = 1 to upwardCandles_D-1
if (security_D[i] <= security_D[i+1])
uptrendSignal_D := false

// Plot uptrend signal as triangle in daily frame


plotshape(uptrendSignal_D and upward_D > 0 and [Link], style=[Link],
color=[Link], location=[Link], size=[Link], title="Uptrend Signal (Daily)")

//@version=5
indicator("EMA Strategy", overlay=true)
ema5 = [Link](close, 5)
ema20 = [Link](close, 20)

buy_signal = [Link](ema5, ema20)


sell_signal = [Link](ema20, ema5)

plot(ema5, color=[Link], title="5 EMA")


plot(ema20, color=[Link], title="20 EMA")

plotshape(buy_signal, style=[Link], color=[Link], size=[Link], location=[Link],


text="Buy")
plotshape(sell_signal, style=[Link], color=[Link], size=[Link], location=[Link],
text="Sell")

Trading bot ema

//@version=4
strategy("Moving Average Crossover Strategy", overlay=true)

// Define strategy inputs

fastLength = input(10, "Fast MA Length")

slowLength = input(20, "Slow MA Length")

capital = 10000

// Calculate moving averages

fastMA = sma(close, fastLength)

slowMA = sma(close, slowLength)

// Define buy and sell conditions

buySignal = crossover(fastMA, slowMA)

sellSignal = crossunder(fastMA, slowMA)

// Execute buy and sell orders

if (buySignal)

[Link]("Buy", [Link])

[Link]("Take Profit", [Link], limit=close * 1.01)

[Link]("Stop Loss", [Link], stop=close * 0.99)

if (sellSignal)

[Link]("Sell", [Link])

[Link]("Take Profit", [Link], limit=close * 0.99)

[Link]("Stop Loss", [Link], stop=close * 1.01)

// Plot moving averages on the chart

plot(fastMA, color=[Link], title="Fast MA")

plot(slowMA, color=[Link], title="Slow MA"

//@version=5
strategy("EMA Strategy", overlay=true)
ema5 = [Link](close, 5)
ema20 = [Link](close, 20)

buy_signal = [Link](ema5, ema20)


sell_signal = [Link](ema20, ema5)

// Trading capital
capital = 10000

// Execute buy and sell orders


if (buy_signal)
[Link]("Buy", [Link])
[Link]("Take Profit", "Buy", limit=close * 1.01)
[Link]("Stop Loss", "Buy", stop=close * 0.99)

if (sell_signal)
[Link]("Sell", [Link])
[Link]("Take Profit", "Sell", limit=close * 0.99)
[Link]("Stop Loss", "Sell", stop=close * 1.01)

plot(ema5, color=[Link], title="5 EMA")


plot(ema20, color=[Link], title="20 EMA")

plotshape(buy_signal, style=[Link], color=[Link], size=[Link], location=[Link],


text="Buy")
plotshape(sell_signal, style=[Link], color=[Link], size=[Link], location=[Link],
text="Sell")

You might also like