Growth Stock Cyclic
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/


// This indicator takes advantage of the fact that when the 10 and 5 year Treasury Constant Maturity Minus Federal Funds rates (T10YFF/T5YFF)
// go down sharply, investors tend to rotate into stocks. This arbitrage works great for growth stocks, since growth stocks are higher beta by
// virtue of their lower market cap and more speculative nature in general. This script identifies the moving-average convergence/divergence of the
// average of the 10y and 5y treasury rates and then finds the variance of that macd line. By averaging that variance with the macdline's inverse,
// an analog output of treasury -> stock rotation can be identified. The upper and lower thresholds bring buy and sell windows into focus.
// © jamiesonpa

//@version=5
indicator("Growth Stock Cyclic")

t10yff = input.symbol("FRED:T10YFF", "Symbol")
t10yff_security = request.security(t10yff, 'D', close)
t5yff = input.symbol("FRED:T5YFF", "Symbol")
t5yff_security = request.security(t5yff, 'D', close)

t10yff_security := (t10yff_security + t5yff_security)/2

[t10yff_security_macdLine, t10yff_security_signalLine, t10yff_security_histLine] = ta.macd(close, 3, 12, 120)

indicator_falling = ta.falling(t10yff_security_macdLine, 3)

tymacdvariance = ta.sma(ta.variance(t10yff_security_macdLine,5),3)

slope = t10yff_security_macdLine - t10yff_security_macdLine[1]

buy_signal_line = (-t10yff_security_macdLine + tymacdvariance)/2

xMax = ta.highest(buy_signal_line,500)
xMin = ta.lowest(buy_signal_line, 500)
line_range = xMax - xMin
buy_signal_line := 100 * buy_signal_line / line_range

bsl_top_threshold = ta.variance(buy_signal_line, 20)
bsl_top_threshold := (ta.sma(bsl_top_threshold, 10)/30)+10

bsl_bottom_threshold = ta.variance(buy_signal_line, 20)
bsl_bottom_threshold := (ta.sma(bsl_bottom_threshold, 10)/30)-10


//plot(tymacdvariance)
//plot(-t10yff_security_macdLine, color=color.red)
plot(buy_signal_line, color=color.white)
plot(bsl_top_threshold, color=color.red)
plot(bsl_bottom_threshold, color=color.green)
//plot(percent_change_10ymacdline, color= color.green)
//plotshape(buysignal, location = location.abovebar, color= color.green, style = shape.cross, size = size.small)
