Intraday MAs for Regular/Extended Session
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © schroederjoa

//@version=5
indicator("Intraday MAs for Regular/Extended Session", "",overlay=true)

tooltip_01 = "Name to distinguish in case you have multiples of this indicator"

descr = input.string("", title="Name of MA Set", tooltip=tooltip_01)

var GRP2 = "Line Style Definitions"

ls_ema_ext = input.string("LINE", title="Show EMA / EXT as", options=["LINE","STEPLINE","CROSS","CIRCLES"], group=GRP2, tooltip="Use this type for EMA on Day, Week, Month")
ls_ema_reg = input.string("LINE", title="Show EMA / REG as", options=["LINE","STEPLINE","CROSS","CIRCLES"], group=GRP2)
ls_sma_ext = input.string("LINE", title="Show SMA / EXT as", options=["LINE","STEPLINE","CROSS","CIRCLES"], group=GRP2, tooltip="Use this type for SMA on Day, Week, Month")
ls_sma_reg = input.string("LINE", title="Show SMA / REG as", options=["LINE","STEPLINE","CROSS","CIRCLES"], group=GRP2)


var GRP1 = "Moving Averages"

tooltip_02 = "MA Color\nMA Line Style\nMA Line Width"

itv_01 = input.int(9, title="MA 01     Interval ", tooltip="", minval = 0, inline = "01_1", group=GRP1)
ema_01 = input.bool(true,title="EMA", inline = "01_1", group=GRP1)
sma_01 = input.bool(true,title="SMA", inline = "01_1", group=GRP1)
reg_01 = input.bool(true,title="REG", inline = "01_1", group=GRP1)
ext_01 = input.bool(true,title="EXT", inline = "01_1", group=GRP1)
tfr_01 = input.timeframe("5", title="         Timeframe", inline = "01_2", group=GRP1, options=["1","3","5","10","15","30","60","120","240","1D","1W","1M"])
lwi_01 = input.int(1, title="Linewidth",  minval=1, maxval=10, inline = "01_2", group=GRP1)
col_01 = input.color(color.blue, title="", inline = "01_2", group=GRP1)
tfr_01_daily = tfr_01 == "1D" or tfr_01 == "1W" or tfr_01 == "1M"

itv_02 = input.int(20, title="MA 02     Interval ", tooltip="", minval = 0, inline = "02_1", group=GRP1)
ema_02 = input.bool(true,title="EMA", inline = "02_1", group=GRP1)
sma_02 = input.bool(true,title="SMA", inline = "02_1", group=GRP1)
reg_02 = input.bool(true,title="REG", inline = "02_1", group=GRP1)
ext_02 = input.bool(true,title="EXT", inline = "02_1", group=GRP1)
tfr_02 = input.timeframe("5", title="         Timeframe", inline = "02_2", group=GRP1, options=["1","3","5","10","15","30","60","120","240","1D","1W","1M"])
lwi_02 = input.int(1, title="Linewidth",  minval=1, maxval=10, inline = "02_2", group=GRP1)
col_02 = input.color(color.green, title="", inline = "02_2", group=GRP1)
tfr_02_daily = tfr_02 == "1D" or tfr_02 == "1W" or tfr_02 == "1M"

itv_03 = input.int(50, title="MA 03     Interval ", tooltip="", minval = 0, inline = "03_1", group=GRP1)
ema_03 = input.bool(true,title="EMA", inline = "03_1", group=GRP1)
sma_03 = input.bool(true,title="SMA", inline = "03_1", group=GRP1)
reg_03 = input.bool(true,title="REG", inline = "03_1", group=GRP1)
ext_03 = input.bool(true,title="EXT", inline = "03_1", group=GRP1)
tfr_03 = input.timeframe("5", title="         Timeframe", inline = "03_2", group=GRP1, options=["1","3","5","10","15","30","60","120","240","1D","1W","1M"])
lwi_03 = input.int(1, title="Linewidth",  minval=1, maxval=10, inline = "03_2", group=GRP1)
col_03 = input.color(color.gray, title="", inline = "03_2", group=GRP1)
tfr_03_daily = tfr_03 == "1D" or tfr_03 == "1W" or tfr_03 == "1M"

itv_04 = input.int(100, title="MA 04     Interval ", tooltip="", minval = 0, inline = "04_1", group=GRP1)
ema_04 = input.bool(true,title="EMA", inline = "04_1", group=GRP1)
sma_04 = input.bool(true,title="SMA", inline = "04_1", group=GRP1)
reg_04 = input.bool(true,title="REG", inline = "04_1", group=GRP1)
ext_04 = input.bool(true,title="EXT", inline = "04_1", group=GRP1)
tfr_04 = input.timeframe("5", title="         Timeframe", inline = "04_2", group=GRP1, options=["1","3","5","10","15","30","60","120","240","1D","1W","1M"])
lwi_04 = input.int(1, title="Linewidth",  minval=1, maxval=10, inline = "04_2", group=GRP1)
col_04 = input.color(color.red, title="", inline = "04_2", group=GRP1)
tfr_04_daily = tfr_04 == "1D" or tfr_04 == "1W" or tfr_04 == "1M"

itv_05 = input.int(200, title="MA 05     Interval ", tooltip="", minval = 0, inline = "05_1", group=GRP1)
ema_05 = input.bool(true,title="EMA", inline = "05_1", group=GRP1)
sma_05 = input.bool(true,title="SMA", inline = "05_1", group=GRP1)
reg_05 = input.bool(true,title="REG", inline = "05_1", group=GRP1)
ext_05 = input.bool(true,title="EXT", inline = "05_1", group=GRP1)
tfr_05 = input.timeframe("5", title="         Timeframe", inline = "05_2", group=GRP1, options=["1","3","5","10","15","30","60","120","240","1D","1W","1M"])
lwi_05 = input.int(1, title="Linewidth",  minval=1, maxval=10, inline = "05_2", group=GRP1)
col_05 = input.color(color.yellow, title="", inline = "05_2", group=GRP1)
tfr_05_daily = tfr_05 == "1D" or tfr_05 == "1W" or tfr_05 == "1M"

lineStyleChooser(s)=>
    (s == "CIRCLES") ? plot.style_circles : (s == "CROSS") ? plot.style_cross : (s == "STEPLINE") ? plot.style_stepline : plot.style_line 

   
s01_1 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_01 , ta.ema(close, itv_01))
s01_2 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_01 , ta.ema(close, itv_01))
s01_3 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_01 , ta.sma(close, itv_01))
s01_4 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_01 , ta.sma(close, itv_01))

plot(itv_01 == 0 ? na : ema_01 and (ext_01 or tfr_01_daily) ?    s01_1 : na, title="MA01 - EMA/EXT", color=col_01, style=lineStyleChooser(ls_ema_ext), linewidth=lwi_01)
plot(itv_01 == 0 ? na : ema_01 and reg_01 and not tfr_01_daily ? s01_2 : na, title="MA01 - EMA/REG", color=col_01, style=lineStyleChooser(ls_ema_reg), linewidth=lwi_01)
plot(itv_01 == 0 ? na : sma_01 and (ext_01 or tfr_01_daily) ?    s01_3 : na, title="MA01 - SMA/EXT", color=col_01, style=lineStyleChooser(ls_sma_ext), linewidth=lwi_01)
plot(itv_01 == 0 ? na : sma_01 and reg_01 and not tfr_01_daily ? s01_4 : na, title="MA01 - SMA/REG", color=col_01, style=lineStyleChooser(ls_sma_reg), linewidth=lwi_01)

s02_1 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_02 , ta.ema(close, itv_02))
s02_2 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_02 , ta.ema(close, itv_02))
s02_3 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_02 , ta.sma(close, itv_02))
s02_4 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_02 , ta.sma(close, itv_02))

plot(itv_02 == 0 ? na : ema_02 and (ext_02 or tfr_02_daily) ?    s02_1 : na, title="MA02 - EMA/EXT", color=col_02, style=lineStyleChooser(ls_ema_ext), linewidth=lwi_02)
plot(itv_02 == 0 ? na : ema_02 and reg_02 and not tfr_02_daily ? s02_2 : na, title="MA02 - EMA/REG", color=col_02, style=lineStyleChooser(ls_ema_reg), linewidth=lwi_02)
plot(itv_02 == 0 ? na : sma_02 and (ext_02 or tfr_02_daily) ?    s02_3 : na, title="MA02 - SMA/EXT", color=col_02, style=lineStyleChooser(ls_sma_ext), linewidth=lwi_02)
plot(itv_02 == 0 ? na : sma_02 and reg_02 and not tfr_02_daily ? s02_4 : na, title="MA02 - SMA/REG", color=col_02, style=lineStyleChooser(ls_sma_reg), linewidth=lwi_02)

s03_1 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_03 , ta.ema(close, itv_03))
s03_2 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_03 , ta.ema(close, itv_03))
s03_3 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_03 , ta.sma(close, itv_03))
s03_4 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_03 , ta.sma(close, itv_03))

plot(itv_03 == 0 ? na : ema_03 and (ext_03 or tfr_03_daily) ?    s03_1 : na, title="MA03 - EMA/EXT", color=col_03, style=lineStyleChooser(ls_ema_ext), linewidth=lwi_03)
plot(itv_03 == 0 ? na : ema_03 and reg_03 and not tfr_03_daily ? s03_2 : na, title="MA03 - EMA/REG", color=col_03, style=lineStyleChooser(ls_ema_reg), linewidth=lwi_03)
plot(itv_03 == 0 ? na : sma_03 and (ext_03 or tfr_03_daily) ?    s03_3 : na, title="MA03 - SMA/EXT", color=col_03, style=lineStyleChooser(ls_sma_ext), linewidth=lwi_03)
plot(itv_03 == 0 ? na : sma_03 and reg_03 and not tfr_03_daily ? s03_4 : na, title="MA03 - SMA/REG", color=col_03, style=lineStyleChooser(ls_sma_reg), linewidth=lwi_03)

s04_1 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_04 , ta.ema(close, itv_04))
s04_2 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_04 , ta.ema(close, itv_04))
s04_3 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_04 , ta.sma(close, itv_04))
s04_4 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_04 , ta.sma(close, itv_04))

plot(itv_04 == 0 ? na : ema_04 and (ext_04 or tfr_04_daily) ?    s04_1 : na, title="MA04 - EMA/EXT", color=col_04, style=lineStyleChooser(ls_ema_ext), linewidth=lwi_04)
plot(itv_04 == 0 ? na : ema_04 and reg_04 and not tfr_04_daily ? s04_2 : na, title="MA04 - EMA/REG", color=col_04, style=lineStyleChooser(ls_ema_reg), linewidth=lwi_04)
plot(itv_04 == 0 ? na : sma_04 and (ext_04 or tfr_04_daily) ?    s04_3 : na, title="MA04 - SMA/EXT", color=col_04, style=lineStyleChooser(ls_sma_ext), linewidth=lwi_04)
plot(itv_04 == 0 ? na : sma_04 and reg_04 and not tfr_04_daily ? s04_4 : na, title="MA04 - SMA/REG", color=col_04, style=lineStyleChooser(ls_sma_reg), linewidth=lwi_04)

s05_1 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_05 , ta.ema(close, itv_05))
s05_2 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_05 , ta.ema(close, itv_05))
s05_3 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.extended), tfr_05 , ta.sma(close, itv_05))
s05_4 = request.security( ticker.new(syminfo.prefix, syminfo.ticker, session.regular),  tfr_05 , ta.sma(close, itv_05))

plot(itv_05 == 0 ? na : ema_05 and (ext_05 or tfr_05_daily) ?    s05_1 : na, title="MA05 - EMA/EXT", color=col_05, style=lineStyleChooser(ls_ema_ext), linewidth=lwi_05)
plot(itv_05 == 0 ? na : ema_05 and reg_05 and not tfr_05_daily ? s05_2 : na, title="MA05 - EMA/REG", color=col_05, style=lineStyleChooser(ls_ema_reg), linewidth=lwi_05)
plot(itv_05 == 0 ? na : sma_05 and (ext_05 or tfr_05_daily) ?    s05_3 : na, title="MA05 - SMA/EXT", color=col_05, style=lineStyleChooser(ls_sma_ext), linewidth=lwi_05)
plot(itv_05 == 0 ? na : sma_05 and reg_05 and not tfr_05_daily ? s05_4 : na, title="MA05 - SMA/REG", color=col_05, style=lineStyleChooser(ls_sma_reg), linewidth=lwi_05)



