ADD 2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Tom1trader
// This is the NYSE Advancers - decliners which the SPX pretty much has to follow. The level gives an idea of days move
//  but I follow the direction as when more advance (green) or decline (red) the index tends to track it pretty closely.


// On SPX and correlateds - very useful for intr-day trading (Scalping or 0DTE option trades) but not for higher time fromes at all.

// I left it at 5 minutes timeframe which displays well on any intraday chart. You can change it by changing the "5" in the security
//  function on line 13 to what you want or change it to timeframe.period (no quotes). 5 min displays better on higher i.e. 15min.

//@version=5
indicator('ADD 2', overlay=false)

f_ma(source, length, type) =>
    value_ = 0.0
    if type    == 'SMA' 
        value_ := ta.sma(source, length) 
    if type  == 'EMA' 
        value_ := ta.ema(source, length)
    if type  == 'WMA' 
        value_ := ta.wma(source, length)
    if type  == 'HMA' 
        value_ := ta.hma(source, length)    
    value_


grp_add     = 'ADD'
i_mtf       = input.timeframe('5',  title="Time  Frame", group = grp_add)
i_length    = input(10, 'MA length', group = grp_add, inline = '101')
ma_type     = input.string('SMA', '', options=['SMA', 'EMA', 'WMA', 'HMA'], inline = '101', group=grp_add)

a = request.security('USI:ADD', i_mtf, hlc3)

green = #00DD00 
red   = #DD0000

dircol  = a > a[1] ? green : red
ma      = f_ma(a, i_length, ma_type)

plot(a, title='ADD', color=dircol, linewidth=3)
plot(ma, color=color.new(color.white, 0), linewidth=3)

