Stacked EMAs
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// @version=5
//
// Stacked EMAs
//
// Stacked EMAs & Stacked Weekly EMAs Label + 7 daily and 2 MTF weekly EMAs
//
// Created by © L&L Capital
// 

indicator("Stacked EMAs", overlay = true)

// Inputs

ema8 = input.int(defval=8, title='EMA Length')
ema13 = input.int(defval=13, title='EMA Length')
ema21 = input.int(defval=21, title='EMA Length')
ema34 = input.int(defval=34,  title='EMA Length')
ema55 = input.int(defval=55,  title='EMA Length')
ema89 = input.int(defval=89,title='EMA Length')
ema200 = input.int(defval=200,  title='EMA Length')
ema8we = input.int(defval=8,  title='EMA Weekly Length')
ema21we = input.int(defval=21,  title='EMA Weekly Length')
ema34we = input.int(defval=34,  title='EMA Weekly Length')
ema55we = input.int(defval=55,  title='EMA Weekly Length')

// EMAs

ema8d =  ta.ema(close, ema8)
ema13d = ta.ema(close, ema13)
ema21d = ta.ema(close, ema21)
ema34d = ta.ema(close, ema34)
ema55d = ta.ema(close, ema55)
ema89d = ta.ema(close, ema89)
ema200d = ta.ema(close, ema200)
ema8w = request.security(syminfo.tickerid, 'W', ta.ema(close, ema8we))
ema21w = request.security(syminfo.tickerid, 'W', ta.ema(close, ema21we))
ema34w = request.security(syminfo.tickerid, 'W', ta.ema(close, ema34we))
ema55w = request.security(syminfo.tickerid, 'W', ta.ema(close, ema55we))

// Plots

plot(ema8d, title='EMA 8', color=color.new(color.green, 0), linewidth=1)
plot(ema13d, title='EMA 13', color=color.new(color.orange, 0), linewidth=1)
plot(ema21d, title='EMA 21', color=color.new(color.yellow, 0), linewidth=2)
plot(ema34d, title='EMA 34', color=color.new(color.purple, 0), linewidth=1)
plot(ema55d, title='EMA 55', color=color.new(color.red, 0), linewidth=1)
plot(ema89d, title='EMA 89', color=color.new(color.aqua, 0), linewidth=1)
plot(ema200d, title='EMA 200', color=color.new(color.blue, 0), style=plot.style_circles, linewidth = 1)
plot(ema8w, title='EMA 8 Weekly', color=color.new(color.green, 0), linewidth=2, display=display.none)
plot(ema21w, title='EMA 21 Weekly', color=color.new(color.white, 0), linewidth=2, display=display.none)

// Stacked EMAs & Stacked Weekly EMAs Table

string  tableYposInput = input.string("top", "Panel position", inline = "11", options = ["top", "middle", "bottom"])
string  tableXposInput = input.string("right", "", inline = "11", options = ["left", "center", "right"])
color   bullColorInput = input.color(color.new(color.green, 0), "Bullish", inline = "12")
color   bearColorInput = input.color(color.new(color.red, 0), "Bearish", inline = "12")
color   neutColorInput = input.color(color.new(color.yellow, 0), "Neutral", inline = "12")  

EMAsLabel = string ("Stacked EMAs")
LabelColor = neutColorInput

if ema8d > ema21d and ema21d > ema34d and ema34d > ema55d
    LabelColor := bullColorInput
if ema8d < ema21d and ema21d < ema34d and ema34d < ema55d
    LabelColor := bearColorInput
    
WEMAsLabel = string ("Stacked Weekly EMAs")
LabelColorW = neutColorInput
if ema8w > ema21w and ema21w > ema34w and ema34w > ema55w
    LabelColorW := bullColorInput
if ema8w < ema21w and  ema21w < ema34w and ema34w < ema55w
    LabelColorW := bearColorInput

Table = table.new(tableYposInput + "_" + tableXposInput,  columns=3, rows=1, bgcolor=color.gray)
if barstate.islast
    table.cell(table_id=Table, column=1, row=0, text=EMAsLabel, height=0, text_color=color.white, text_halign=text.align_left, text_valign= text.align_center, bgcolor=LabelColor)  
    table.cell(table_id=Table, column=2, row=0, text=WEMAsLabel, height=0,text_color=color.white, text_halign=text.align_left, text_valign=text.align_center, bgcolor=LabelColorW)

