OPEN-SOURCE SCRIPT

CM_Williams_Vix_Fix Market Top Winit

205
//version=5
indicator('CM_Williams_Vix_Fix Market Top', overlay=false)

// Inputs
pd = input(22, title='LookBack Period Standard Deviation High')
bbl = input(20, title='Bollinger Band Length')
mult = input.float(2.0, minval=1, maxval=5, title='Bollinger Band Standard Deviation Up')
lb = input(50, title='Look Back Period Percentile High')
ph = input(0.85, title='Highest Percentile - 0.90=90%, 0.95=95%, 0.99=99%')
pl = input(1.01, title='Lowest Percentile - 1.10=90%, 1.05=95%, 1.01=99%')
hp = input(false, title='Show High Range - Based on Percentile and LookBack Period?')
sd = input(false, title='Show Standard Deviation Line?')

// Core Calculation (Inverted for Market Top)
wvf_top = (close - ta.lowest(close, pd)) / ta.lowest(close, pd) * 100 // Detect extreme highs

sDev = mult * ta.stdev(wvf_top, bbl)
midLine = ta.sma(wvf_top, bbl)
lowerBand = midLine - sDev
upperBand = midLine + sDev

rangeHigh = ta.highest(wvf_top, lb) * ph
rangeLow = ta.lowest(wvf_top, lb) * pl

// Color logic: highlight extreme highs
col = wvf_top >= upperBand or wvf_top >= rangeHigh ? color.red : color.gray

// Plots
plot(wvf_top, title='Williams Vix Fix Market Top', style=plot.style_histogram, linewidth=3, color=col)

// Optional plots
plot(hp ? rangeHigh : na, title='Range High Percentile', style=plot.style_line, linewidth=2, color=color.new(color.orange, 0))
plot(hp ? rangeLow : na, title='Range Low Percentile', style=plot.style_line, linewidth=2, color=color.new(color.orange, 0))
plot(sd ? upperBand : na, title='Upper Band', style=plot.style_line, linewidth=2, color=color.new(color.aqua, 0))
plot(sd ? lowerBand : na, title='Lower Band', style=plot.style_line, linewidth=2, color=color.new(color.aqua, 0))

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.