Buffett Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © IcedMilo
//@version=5
indicator(title='Buffett Indicator')

//data
marketval = request.security("FRED:WILL5000PR", '1D', close)
gdp = request.security("FRED:GDP", '1D', close) / 1000000000

//calculations
indicator_1 = float(marketval/gdp) * 100

//indicator plot
plot(indicator_1, color=color.new(#2196F3, 0), linewidth=2)

//line plots
plot(50, title='50% of GDP', color=color.new(#4CAF50, 0), linewidth=2)
plot(100, title='100% of GDP', color=color.new(#FF9800, 0), linewidth=2)
plot(150, title='150% of GDP', color=color.new(#FF5252, 0), linewidth=2)
plot(200, title='200% of GDP', color=color.new(#880E4F, 0), linewidth=2)

// SMA plot
smaLength = input.int(200, title = "SMA Length")
sma200 = ta.sma(indicator_1, smaLength)
plot(sma200, title='SMA', color=color.new(#A020F0, 0))
