Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save doppelgunner/50cdd5ceb24176d879dabf2bfd832857 to your computer and use it in GitHub Desktop.
Save doppelgunner/50cdd5ceb24176d879dabf2bfd832857 to your computer and use it in GitHub Desktop.
Algo Trading: Simple 3-EMA Indicator (youtube: https://www.youtube.com/channel/UC4dgxbwzMoV6aKSyNkf9hhA)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © doppelgunner
//@version=4
study("Algo Trading: Simple 3-EMA Indicator", overlay=true)
ema_fast_length = input(50, "EMA Fast Length", minval=1, group="EMA Settings")
ema_mid_length = input(100, "EMA Mid Length", minval=1, group="EMA Settings")
ema_slow_length = input(200, "EMA Slow Length", minval=1, group="EMA Settings")
ema_slow = ema(close, ema_slow_length)
ema_mid = ema(close, ema_mid_length)
ema_fast = ema(close, ema_fast_length)
plot(ema_slow, color=color.black, linewidth=3)
plot(ema_mid, color=color.red, linewidth=2)
plot(ema_fast, color=color.blue, linewidth=1)
buy = crossover(ema_fast, ema_mid) and close > ema_slow
sell = crossunder(ema_fast, ema_mid) and close < ema_slow
plotshape(buy, "Buy Signal", style=shape.labelup, location=location.belowbar, color=color.green, text="Buy", textcolor=color.white)
plotshape(sell, "Sell Signal", style=shape.labeldown, location=location.abovebar, color=color.red, text="Sell", textcolor=color.white)
bars_buy = barssince(buy)
bars_sell = barssince(sell)
inLong = bars_buy < bars_sell
inShort = bars_buy > bars_sell
showBGColor = input(true, "Show BG Color?", type=input.bool, group="Color Settings")
bgcolor((not showBGColor) ? color.white : inLong ? color.green : color.red)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment