Cumulative ADD
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © StevenM85

//@version=5
indicator("Cum ADD")



ticker = input.string(title='Exchange', defval='NDXcomp', options=['NDXcomp', 'NYSE'])
pltsma=input(defval=true, title='Show', inline='0')
sma=input(title='Length', defval=9, inline='0')
smatype=input.string(title='Type', defval='EMA', options=['SMA','EMA'], inline='0')
pltlongsma=input(defval=true, title='Show', inline='1')
smalong=input(title='Length', defval=50, inline='1')
smalongtype=input.string(title='Type', defval='SMA', options=['SMA','EMA'], inline='1')
add_diff=request.security(ticker=='NDXcomp'? "ADDQ":"ADD", 'D', close)

cumdiff = ta.cum(add_diff)
ma10=smatype=="SMA"?ta.sma(cumdiff, sma):ta.ema(cumdiff, sma)
ma50=smalongtype=="SMA"?ta.sma(cumdiff, smalong):ta.ema(cumdiff, smalong)
plot(cumdiff, color=color.black)
plot(ma10, color=color.new(color.blue, transp=pltsma==true?0:100))
plot(ma50, color=color.new(color.orange, transp=pltlongsma==true?0:100))


// --- PLOT THE TABLE ---
var table newHighLowTable = table.new(position.middle_left, 2, 1, border_width=1, border_color=color.rgb(209, 212, 219, 0))
i_plotTable = true
//Function
f_fillCell(_table, _column, _row, _value) =>
    _c_color = color.rgb(54, 58, 69, 0)
    _transp = 0
    _cellText = str.tostring(_value, '0')
    table.cell(_table, _column, _row, _cellText, bgcolor=color.rgb(209, 212, 219, 0), text_color=color.rgb(54, 58, 69, 0), text_size=size.normal)

// Diplay
if i_plotTable

    table.cell(newHighLowTable, 0, 0, text=ticker, bgcolor=color.rgb(209, 212, 219, 0), text_color=color.rgb(54, 58, 69, 0), text_size=size.normal)
    table.cell(newHighLowTable, 1, 0, text=' ', bgcolor=color.white, text_color=color.rgb(54, 58, 69, 0), text_size=size.normal)

