Stock vs Index vs Vix (Adjusted)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sp3ed

//@version=5
indicator(title="Stock vs Index vs Vix (Adjusted)", shorttitle="SIV", timeframe="", timeframe_gaps=true)

length = input.int(34)

index = input.symbol('SPY')
vix = input.symbol('VIX')

s = (hlc3 - ta.lowest(low, length)) / (ta.highest(high, length) - ta.lowest(low, length)) * 100
i = request.security(index, '', s)
v = request.security(vix, '', 100 - s)

hline(0, linestyle=hline.style_solid, color=color.new(#434651, 0))
hline(33.33, linestyle=hline.style_dotted, color=color.new(#9598a1, 0))
hline(66.67, linestyle=hline.style_dotted, color=color.new(#9598a1, 0))
hline(100, linestyle=hline.style_solid, color=color.new(#434651, 0))

gradient = color.from_gradient(s, 33.33, 66.67, color.new(#e91e63, 0), color.new(#4caf50, 0))

plot(s, color=gradient)
plot(i, color=color.new(color.blue, 0), style=plot.style_cross)
plot(v, color=color.new(color.red, 0), style=plot.style_cross)
