Risk On Risk Off
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © xloexs

//@version=5
indicator("Risk On Risk Off")

//Theory:
//Indicator to determine if the current economic environment is either Risk On or Risk Off
//Parameters:
//Risk On when: 60 Day Cumulative Return of BND is Above BIL
//Risk Off when: 60 Day Cumulative Return of BND is Below BIL

//Calculation:

//60 Day Cumulative Return of BND
//BND Current Price
bndc = request.security("BND", "D", close)
//plot(bndc, "BND Current Price", color.yellow, 2)
//BND 60 Day Price
bndo = request.security("BND", "60D", close)
//plot(bndo, "BND 60D Price", color.green, 2)
//Calculation of Cumulative Return
//((Current price)-(Original price))/Original price
cumpbnd = (bndc - bndo)/bndo
plot(cumpbnd, "BND 60 Day Cumulative Price Return", color.green, 2)

//60 Day Cumulative Return of BIL
//BIL Current Price
bilc = request.security("BIL", "D", close)
//plot(bilc, "BIL Current Price", color.yellow, 2)
//BIL 60 Day Price
bilo= request.security("BIL", "60D", close)
//plot(bilo, "BIL 60 Day Price", color.green, 2)
//Calculation of Cumulative Return
//((Current price)-(Original price))/Original price
cumpbil = (bilc - bilo)/bilo
plot(cumpbil, "BIL 60 Day Cumulative Price Return", color.yellow, 2)