Michigan Consumer Sentiment
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © callmejaytrader

//@version=5
indicator("Consumer Sentiment")

quandl_ticker = "QUANDL:UMICH/SOC1"
data = request.security(quandl_ticker, "D", close)
plot(data,"Sentiment",color=color.red)

interval = 260

if (timeframe.isweekly)
    interval := 52
    
if (timeframe.ismonthly)
    interval := 12

min = ta.lowest(data, interval)
max = ta.highest(data, interval)

sentimentStock = ta.stoch(data, max, min, interval)
plot(sentimentStock, "Stochastic sentiment", color=color.black)