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

//@version=5
indicator('NVT')
chart = input.string(defval='NVT', options=['NVT', 'NVT Golden Cross'])
type = input.string(defval='GLASSNODE', options=['GLASSNODE', 'CRYPTOCAP'],title='Source')
ext = if type == 'GLASSNODE'
    '_TOTALVOLUMEUSD'
else if type == 'CRYPTOCAP'
    ''
pr = if type == 'GLASSNODE'
    close
else if type == 'CRYPTOCAP'
    volume
ext1 = if type == 'GLASSNODE'
    '_MARKETCAP'
else if type == 'CRYPTOCAP'
    ''



supply = request.security(type + ':' + syminfo.basecurrency + ext1, timeframe.period, close)

vol = request.security(type + ':' + syminfo.basecurrency + ext, timeframe.period, pr)
day = input(defval=1, title='volume time period')
nvt = supply / ta.sma(vol, day)

nvtd = supply / vol
nvtdiff = ta.sma(nvtd, 10) - ta.sma(nvtd, 30)
nvtgs = nvtdiff / ta.stdev(nvtdiff, 300)
plot(chart == 'NVT' ? nvt : na, title='NVT', style=plot.style_line, color=color.new(color.white, 50))
h1 = hline(chart=='NVT'? 15:2.2 , color=color.red)
h2 = hline( chart == 'NVT Golden Cross'? -1.6 : na, color=color.green)
plot(chart == 'NVT Golden Cross' ? nvtgs : na, title='NVTgs', color=color.new(color.blue, 0))
fill(h1, h2, color= chart == 'NVT Golden Cross'? color.from_gradient(nvtgs, -1.6, 2.2, color.new(color.green,90), color.new(color.red, 90)) : na)