tradingview/%b.pine

19 lines
719 B
Plaintext
Raw Normal View History

2023-11-02 12:46:03 +00:00
// Credit to @kerberos007.
//@version=5
indicator("%B", shorttitle="%B", overlay=false)
moving_average = input.int(20, minval=1, title="Moving Average")
std_dev = input(2.0, title="Standard Deviations")
symbol = input("VIX", title="Symbol")
current_close = request.security(symbol, timeframe.period, close)
[basis, upper_band, lower_band] = ta.bb(current_close, moving_average, std_dev)
percentB = (current_close - lower_band) / (upper_band - lower_band)
plot(percentB, title="%B", color=color.yellow)
hline(0, "Lower Band", color=color.red, linestyle=hline.style_solid)
hline(0.5, "Middle Band", color=color.gray, linestyle=hline.style_solid)
hline(1, "Upper Band", color=color.lime, linestyle=hline.style_solid)