SMA Multi Time Frame Table V1.5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jbritton001
// MA MTF v 1.0.9
// script will plot the smas on higher time frames 
// Added Table
// Colored the MAs to make the plot colors
// fixed some floating issues .. along with corrected some request.security issues 
// added XY code to where the table can be moved around
// fixed then broke ... fixed the data sourced in the Weekly coloumn but lost one 
// added the wvma .. its plotted but NOT in the table as I have reached the number of security requests 
// left in the commented out parts in case TV allows more then 40 security requests in the future
// removed a few settings along with the VWMA so this is only SMA 
//@version=5

indicator(title="Multi Time Frame", shorttitle=" SMA MTF Ver: 1.5", overlay=true)

// BEGIN SCRIPT 

// Custom function to truncate (cut) excess decimal places
truncate(_number, _decimalPlaces) =>
    _factor = math.pow(10, _decimalPlaces)
    int(_number * _factor) / _factor
	

s01=input.int(title="SMA 1", defval=5, group='SMA')
s02=input.int(title="SMA 2", defval=10, group='SMA')
s03=input.int(title="SMA 3", defval=20, group='SMA')
s04=input.int(title="SMA 4", defval=50, group='SMA')
s05=input.int(title="SMA 5", defval=120, group='SMA')
s06=input.int(title="SMA 6", defval=200, group='SMA')

// SMAs
sma1=ta.sma(close, s01)
sma2=ta.sma(close, s02)
sma3=ta.sma(close, s03)
sma4=ta.sma(close, s04)
sma5=ta.sma(close, s05) 
sma6=ta.sma(close, s06)

// SMA Plots
plot(sma1, title='SMA 1', color=color.new(#9C27B0, 0)) // Purple
plot(sma2, title='SMA 2', color=color.new(#FFEB3B, 0)) // Yellow
plot(sma3, title='SMA 3', color=color.new(#00E676, 0)) // Lime Green
plot(sma4, title='SMA 4', color=color.new(#2196F3, 0)) // Blue
plot(sma5, title='SMA 5', color=color.gray) // White color.new(#FFFFFF, 0)
plot(sma6, title='SMA 6', color=color.new(#FF9800, 0)) // Orange

// MTF requests SMA 
S1 = request.security(syminfo.tickerid, "60", sma1 , lookahead=barmerge.lookahead_on) 
S2 = request.security(syminfo.tickerid, "D", sma1 , lookahead=barmerge.lookahead_on)
S3 = request.security(syminfo.tickerid, "W", sma1 , lookahead=barmerge.lookahead_on)
S4 = request.security(syminfo.tickerid, "M", sma1 , lookahead=barmerge.lookahead_on)
S5 = request.security(syminfo.tickerid, "3M", sma1 , lookahead=barmerge.lookahead_on)
S6 = request.security(syminfo.tickerid, "12M", sma1 , lookahead=barmerge.lookahead_on)

S7 = request.security(syminfo.tickerid, "60", sma2, lookahead=barmerge.lookahead_on) 
S8 = request.security(syminfo.tickerid, "D", sma2, lookahead=barmerge.lookahead_on)
S9 = request.security(syminfo.tickerid, "W", sma2, lookahead=barmerge.lookahead_on)
S10 = request.security(syminfo.tickerid, "M", sma2, lookahead=barmerge.lookahead_on)
S11 = request.security(syminfo.tickerid, "3M", sma2, lookahead=barmerge.lookahead_on)
S12 = request.security(syminfo.tickerid, "12M", sma2, lookahead=barmerge.lookahead_on)

S13 = request.security(syminfo.tickerid, "60", sma3 , lookahead=barmerge.lookahead_on) 
S14 = request.security(syminfo.tickerid, "D", sma3 , lookahead=barmerge.lookahead_on)
S15 = request.security(syminfo.tickerid, "W", sma3 , lookahead=barmerge.lookahead_on)
S16 = request.security(syminfo.tickerid, "M", sma3 , lookahead=barmerge.lookahead_on)
S17 = request.security(syminfo.tickerid, "3M", sma3 , lookahead=barmerge.lookahead_on)
S18 = request.security(syminfo.tickerid, "12M", sma3 , lookahead=barmerge.lookahead_on)

S19 = request.security(syminfo.tickerid, "60", sma4, lookahead=barmerge.lookahead_on) 
S20 = request.security(syminfo.tickerid, "D", sma4, lookahead=barmerge.lookahead_on)
S21 = request.security(syminfo.tickerid, "W", sma4, lookahead=barmerge.lookahead_on)
S22 = request.security(syminfo.tickerid, "M", sma4, lookahead=barmerge.lookahead_on)
S23 = request.security(syminfo.tickerid, "3M", sma4, lookahead=barmerge.lookahead_on)
S24 = request.security(syminfo.tickerid, "12M", sma4, lookahead=barmerge.lookahead_on)

S25 = request.security(syminfo.tickerid, "60",sma5, lookahead=barmerge.lookahead_on) 
S26 = request.security(syminfo.tickerid, "D", sma5, lookahead=barmerge.lookahead_on)
S27 = request.security(syminfo.tickerid, "W", sma5, lookahead=barmerge.lookahead_on)
S28 = request.security(syminfo.tickerid, "M", sma5, lookahead=barmerge.lookahead_on)
S29 = request.security(syminfo.tickerid, "3M", sma5, lookahead=barmerge.lookahead_on)
S30 = request.security(syminfo.tickerid, "12M", sma5, lookahead=barmerge.lookahead_on)

S31 = request.security(syminfo.tickerid, "60", sma6, lookahead=barmerge.lookahead_on) 
S32 = request.security(syminfo.tickerid, "D", sma6, lookahead=barmerge.lookahead_on)
S33 = request.security(syminfo.tickerid, "W", sma6, lookahead=barmerge.lookahead_on)
S34 = request.security(syminfo.tickerid, "M", sma6, lookahead=barmerge.lookahead_on)
S35 = request.security(syminfo.tickerid, "3M", sma6, lookahead=barmerge.lookahead_on)
S36 = request.security(syminfo.tickerid, "12M", sma6, lookahead=barmerge.lookahead_on)


//Table 

TblY = input.string("bottom", "Table Position", inline = "11", options = ["top", "middle", "bottom"])
TblX = input.string("right", "", inline = "11", options = ["left", "center", "right"])

testTable = table.new(TblY + "_" + TblX, columns = 10, rows = 10, border_width = 1,border_color = color.black,frame_width = 1,frame_color = color.red, bgcolor=color.gray)

if barstate.islastconfirmedhistory or barstate.isrealtime

    t1 = str.tostring(s01)
    t2 = str.tostring(s02)
    t3 = str.tostring(s03)
    t4 = str.tostring(s04)
    t5 = str.tostring(s05)
    t6 = str.tostring(s06)


    table.cell(table_id = testTable, column = 0, row = 0, text = "SMA",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 0, text = "Current",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 0, row = 1, text = t1 ,text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 1, text = str.tostring(truncate(sma1,2)),text_size = size.normal,bgcolor=color.new(#9C27B0, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 0, row = 2, text = t2 ,text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 2, text = str.tostring(truncate(sma2,2)),text_size = size.normal,bgcolor=color.new(#FFEB3B, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 0, row = 3, text = t3 ,text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 3, text = str.tostring(truncate(sma2,2)),text_size = size.normal,bgcolor=color.new(#00E676, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 0, row = 4, text = t4 ,text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 4, text = str.tostring(truncate(sma4,2)),text_size = size.normal,bgcolor=color.new(#2196F3, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 0, row = 5, text = t5,text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 5, text = str.tostring(truncate(sma5,2)),text_size = size.normal,bgcolor=color.new(#FFFFFF, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 0, row = 6, text = t6,text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 1, row = 6, text = str.tostring(truncate(sma6,2)),text_size = size.normal,bgcolor=color.new(#FF9800, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 0, text = "Hourly",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 1, text = str.tostring(truncate(S1,2)),text_size = size.normal,bgcolor=color.new(#9C27B0, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 2, text = str.tostring(truncate(S7,2)),text_size = size.normal,bgcolor=color.new(#FFEB3B, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 3, text = str.tostring(truncate(S13,2)),text_size = size.normal,bgcolor=color.new(#00E676, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 4, text = str.tostring(truncate(S19,2)),text_size = size.normal,bgcolor=color.new(#2196F3, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 5, text = str.tostring(truncate(S25,2)),text_size = size.normal,bgcolor=color.new(#FFFFFF, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 2, row = 6, text = str.tostring(truncate(S31,2)),text_size = size.normal,bgcolor=color.new(#FF9800, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 0, text = "Daily",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 1, text = str.tostring(truncate(S2,2)),text_size = size.normal,bgcolor=color.new(#9C27B0, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 2, text = str.tostring(truncate(S8,2)),text_size = size.normal,bgcolor=color.new(#FFEB3B, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 3, text = str.tostring(truncate(S14,2)),text_size = size.normal,bgcolor=color.new(#00E676, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 4, text = str.tostring(truncate(S20,2)),text_size = size.normal,bgcolor=color.new(#2196F3, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 5, text = str.tostring(truncate(S26,2)),text_size = size.normal,bgcolor=color.new(#FFFFFF, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 3, row = 6, text = str.tostring(truncate(S32,2)),text_size = size.normal,bgcolor=color.new(#FF9800, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 4, row = 0, text = "Weekly",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 4, row = 1, text = str.tostring(truncate(S3,2)),text_size = size.normal,bgcolor=color.new(#9C27B0, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 4, row = 2, text = str.tostring(truncate(S9,2)),text_size = size.normal,bgcolor=color.new(#FFEB3B, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 4, row = 3, text = str.tostring(truncate(S15,2)),text_size = size.normal,bgcolor=color.new(#00E676, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 4, row = 4, text = str.tostring(truncate(S21,2)),text_size = size.normal,bgcolor=color.new(#2196F3, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 4, row = 5, text = str.tostring(truncate(S27,2)),text_size = size.normal,bgcolor=color.new(#FFFFFF, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 4, row = 6, text = str.tostring(truncate(S33,2)),text_size = size.normal,bgcolor=color.new(#FF9800, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 5, row = 0, text = "Montly",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 5, row = 1, text = str.tostring(truncate(S4,2)),text_size = size.normal,bgcolor=color.new(#9C27B0, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 5, row = 2, text = str.tostring(truncate(S10,2)),text_size = size.normal,bgcolor=color.new(#FFEB3B, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 5, row = 3, text = str.tostring(truncate(S16,2)),text_size = size.normal,bgcolor=color.new(#00E676, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 5, row = 4, text = str.tostring(truncate(S22,2)),text_size = size.normal,bgcolor=color.new(#2196F3, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 5, row = 5, text = str.tostring(truncate(S28,2)),text_size = size.normal,bgcolor=color.new(#FFFFFF, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 5, row = 6, text = str.tostring(truncate(S34,2)),text_size = size.normal,bgcolor=color.new(#FF9800, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 6, row = 0, text = "Quartly",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 6, row = 1, text = str.tostring(truncate(S5,2)),text_size = size.normal,bgcolor=color.new(#9C27B0, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 6, row = 2, text = str.tostring(truncate(S11,2)),text_size = size.normal,bgcolor=color.new(#FFEB3B, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 6, row = 3, text = str.tostring(truncate(S17,2)),text_size = size.normal,bgcolor=color.new(#00E676, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 6, row = 4, text = str.tostring(truncate(S23,2)),text_size = size.normal,bgcolor=color.new(#2196F3, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 6, row = 5, text = str.tostring(truncate(S29,2)),text_size = size.normal,bgcolor=color.new(#FFFFFF, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 6, row = 6, text = str.tostring(truncate(S35,2)),text_size = size.normal,bgcolor=color.new(#FF9800, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 7, row = 0, text = "Yearly",text_size = size.normal,text_color = color.black)
    table.cell(table_id = testTable, column = 7, row = 1, text = str.tostring(truncate(S6,2)),text_size = size.normal,bgcolor=color.new(#9C27B0, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 7, row = 2, text = str.tostring(truncate(S12,2)),text_size = size.normal,bgcolor=color.new(#FFEB3B, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 7, row = 3, text = str.tostring(truncate(S18,2)),text_size = size.normal,bgcolor=color.new(#00E676, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 7, row = 4, text = str.tostring(truncate(S24,2)),text_size = size.normal,bgcolor=color.new(#2196F3, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 7, row = 5, text = str.tostring(truncate(S30,2)),text_size = size.normal,bgcolor=color.new(#FFFFFF, 0),text_color = color.black)
    table.cell(table_id = testTable, column = 7, row = 6, text = str.tostring(truncate(S36,2)),text_size = size.normal,bgcolor=color.new(#FF9800, 0),text_color = color.black)

// END OF CODE
// END OF CODE