//@version=5
indicator("EMA Strategy", overlay=true)
ema5 = ta.ema(close, 5)
ema20 = ta.ema(close, 20)
buy_signal = ta.crossover(ema5, ema20)
sell_signal = ta.crossover(ema20, ema5)
bgcolor(buy_signal ? color.green : sell_signal ? color.red : na)
plot(ema5, color=color.green, title="5 EMA")
plot(ema20, color=color.red, title="20 EMA")
plotshape(buy_signal, style=shape.arrowup, color=color.green, size=size.large,
location=location.belowbar, text="Buy")
plotshape(sell_signal, style=shape.arrowdown, color=color.red, size=size.large,
location=location.abovebar, text="Sell")
//@version=5
indicator("EMA Strategy", overlay=true)
ema5 = ta.ema(close, 5)
ema20 = ta.ema(close, 20)
buy_signal = ta.crossover(ema5, ema20)
sell_signal = ta.crossover(ema20, ema5)
plot(ema5, color=color.green, title="5 EMA")
plot(ema20, color=color.red, title="20 EMA")
plotshape(buy_signal, style=shape.arrowup, color=color.green, size=size.large,
location=location.belowbar, text="Buy")
plotshape(sell_signal, style=shape.arrowdown, color=color.red, size=size.large,
location=location.abovebar, text="Sell")
//@version=5
indicator("EMA Strategy", overlay=true)
ema5 = ta.ema(close, 5)
ema22 = ta.ema(close, 22)
buy_signal = ta.crossover(ema5, ema22)
sell_signal = ta.crossover(ema22, ema5)
plot(ema5, color=color.green, title="5 EMA")
plot(ema22, color=color.red, title="22 EMA")
plotshape(buy_signal, style=shape.triangleup, color=color.green, size=size.small,
location=location.belowbar, text="Buy")
plotshape(sell_signal, style=shape.triangledown, color=color.red, size=size.small,
location=location.abovebar, text="Sell")
//@version=5
indicator("RSI Strategy", overlay=true)
rsi30 = ta.rsi(close, 30)
rsi50 = ta.rsi(close, 50)
buy_signal = ta.crossover(rsi30, rsi50)
sell_signal = ta.crossover(rsi50, rsi30)
plot(rsi30, color=color.blue, title="30 RSI")
plot(rsi50, color=color.brown, title="50 RSI")
plotshape(buy_signal, style=shape.arrowup, color=color.blue, size=size.small,
location=location.belowbar, text="Buy")
plotshape(sell_signal, style=shape.arrowdown, color=color.brown, size=size.small,
location=location.abovebar, text="Sell")
//@version=4
study("Downtrend Signal")
// Define input variables
fallingCandles1 = input(title="Falling Candles 5 min", type=input.integer, defval=7)
fallingCandles2 = input(title="Falling Candles 1 day", type=input.integer, defval=4)
// Calculate the difference between close and close of 'fallingCandles' bars ago in 5 min timeframe
falling1 = close - security(syminfo.tickerid, "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=shape.triangledown, color=color.red,
location=location.belowbar, size=size.small)
// Calculate the difference between close and close of 'fallingCandles' bars ago in daily timeframe
falling2 = close - security(syminfo.tickerid, "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=shape.triangledown, color=color.red,
location=location.belowbar, size=size.small)
//@version=4
study("Uptrend Signal")
// Define input variables
upwardCandles_5min = input(title="Upward Candles (5-min)", type=input.integer, defval=7)
upwardCandles_D = input(title="Upward Candles (Daily)", type=input.integer, 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 barstate.isconfirmed, style=shape.triangleup,
color=color.green, location=location.abovebar, size=size.tiny, title="Uptrend Signal (5-min)")
// Calculate the difference between close and close of 'upwardCandles_D' bars ago
upward_D = close - security(syminfo.tickerid, "D", close)[upwardCandles_D]
// Create a variable for security function value
security_D = security(syminfo.tickerid, "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 barstate.isconfirmed, style=shape.triangleup,
color=color.green, location=location.abovebar, size=size.tiny, title="Uptrend Signal (Daily)")
//@version=5
indicator("EMA Strategy", overlay=true)
ema5 = ta.ema(close, 5)
ema20 = ta.ema(close, 20)
buy_signal = ta.crossover(ema5, ema20)
sell_signal = ta.crossover(ema20, ema5)
plot(ema5, color=color.green, title="5 EMA")
plot(ema20, color=color.red, title="20 EMA")
plotshape(buy_signal, style=shape.triangleup, color=color.green, size=size.large, location=location.belowbar,
text="Buy")
plotshape(sell_signal, style=shape.triangledown, color=color.red, size=size.large, location=location.abovebar,
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)
strategy.entry("Buy", strategy.long)
strategy.order("Take Profit", strategy.short, limit=close * 1.01)
strategy.order("Stop Loss", strategy.short, stop=close * 0.99)
if (sellSignal)
strategy.entry("Sell", strategy.short)
strategy.order("Take Profit", strategy.long, limit=close * 0.99)
strategy.order("Stop Loss", strategy.long, stop=close * 1.01)
// Plot moving averages on the chart
plot(fastMA, color=color.blue, title="Fast MA")
plot(slowMA, color=color.red, title="Slow MA"
//@version=5
strategy("EMA Strategy", overlay=true)
ema5 = ta.ema(close, 5)
ema20 = ta.ema(close, 20)
buy_signal = ta.crossover(ema5, ema20)
sell_signal = ta.crossover(ema20, ema5)
// Trading capital
capital = 10000
// Execute buy and sell orders
if (buy_signal)
strategy.entry("Buy", strategy.long)
strategy.exit("Take Profit", "Buy", limit=close * 1.01)
strategy.exit("Stop Loss", "Buy", stop=close * 0.99)
if (sell_signal)
strategy.entry("Sell", strategy.short)
strategy.exit("Take Profit", "Sell", limit=close * 0.99)
strategy.exit("Stop Loss", "Sell", stop=close * 1.01)
plot(ema5, color=color.green, title="5 EMA")
plot(ema20, color=color.red, title="20 EMA")
plotshape(buy_signal, style=shape.triangleup, color=color.green, size=size.large, location=location.belowbar,
text="Buy")
plotshape(sell_signal, style=shape.triangledown, color=color.red, size=size.large, location=location.abovebar,
text="Sell")