[WRx450] FED net liquidity
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © WRx450

//@version=5
indicator("[WRx450] FED net liquidity", overlay=true, timeframe='D')

offset = input.int(0,"Offset curves in days", tooltip = "offset all data")  // move data on time line by days

Symbol1 = input.symbol("FRED:WALCL", "FED Total Asset")                  // weekly report on Wednesday
FEDasset = request.security(Symbol1,"",close) 

Symbol2 = input.symbol("FRED:RRPONTSYD", "FED Repo market")             // Daily report
FEDrepo = request.security(Symbol2,"",close) 

Symbol3 = input.symbol("FRED:WTREGEN", "FED Treasury General Account")  // weekly report on Wednesday
FEDtreasury = request.security(Symbol3,"",close) 

ShowTA = input.bool(false,"Show Total Asset")       // activate the curves on graphique
ShowRepo = input.bool(false,"Show Repo")
ShowTGA = input.bool(false,"Show TGA")
ShowNetLiquid = input.bool(true,"Show Net Liquidity","Net liquidity is updated only on wednesday because Total Asset and TGA are updated only on wednesday, making the result on daily unacurate")
ShowChange = input.bool(false,"Show Net Liquidity change","show only the weekly change on wednesday. Add the same indicator and move it to a new graph down for clearer view")

float NetLiquidity = 0

if FEDasset != FEDasset[1]
    NetLiquidity := FEDasset - FEDrepo - FEDtreasury
else
    NetLiquidity := NetLiquidity[1]

NetChange = NetLiquidity - NetLiquidity[1]

plot(not ShowChange and ShowTA ? FEDasset : na, "FED TA", color.blue, style = plot.style_stepline, offset = offset)
plot(not ShowChange and ShowRepo ? FEDrepo : na, "FED TA", color.yellow, style = plot.style_stepline, offset = offset)
plot(not ShowChange and ShowTGA ? FEDtreasury : na, "FED TA", color.orange, style = plot.style_stepline, offset = offset)

plot(not ShowChange and ShowNetLiquid ? NetLiquidity : na, "FED net liquidity", color.white, style = plot.style_stepline_diamond, offset = offset)

plot(ShowChange ? NetChange : na, "FED Net Liquiditity change", color = NetChange >= 0 ? color.green : color.red , style = plot.style_columns, offset = offset)
