EMA Ribbon + Stoch (Open) v1
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © teguamit_trading

//@version=5
indicator("EMA Ribbon + Stoch", overlay=true)

// Inputs
fastMALen = input.int(title="Fast MA Length", defval=5)
medMALen  = input.int(title="Medium MA Length", defval=13)
slowMALen = input.int(title="Slow MA Length", defval=21)
ultraslowMALen = input.int(title="200 MA Length", defval=200)

kline = ta.sma(ta.stoch(close,high,low,14),3)
dline = ta.sma(kline,3)

stochLong = kline>dline
stochShort = kline<dline

// Calculate strategy values
fastMA = ta.ema(close, fastMALen)
medMA  = ta.ema(close, medMALen)
slowMA = ta.ema(close, slowMALen)
ultraslowMA = ta.ema(close,ultraslowMALen)

// Determine long trading conditions
longCondition1 = ta.crossover(fastMA,medMA)
enterLong = longCondition1 and stochLong

shortCondition1 = ta.crossunder(fastMA,medMA)
enterShort = shortCondition1 and stochShort

//plots
plot(fastMA, color=color.red)
plot(medMA, color=color.blue)
plot(slowMA, color=color.purple)
plot(ultraslowMA, color=color.black)

green = color.green
red=color.red
blue=color.blue
orange=color.orange
    
bgColour =
     enterLong ? green :
     enterShort ? red :
     na

bgcolor(color=bgColour, transp=85)

if(enterLong)
    alert("Buy gold", freq = alert.freq_once_per_bar_close)
if(enterShort)
    alert("Sell gold", freq = alert.freq_once_per_bar_close)
