Plots the historical beta of the selected security to the S&P500. The observation period is adjustable
study(title="S&P500 Beta", shorttitle="Beta") sym = "SPY", res=period, src = close, length = input(100, minval=1) ovr = security(sym, res, src) secd = stdev(src, length), mktd = stdev(ovr, length) Beta = correlation(src, ovr, length) * secd / mktd plot(Beta, color=purple, style=area, transp=40)