Global Central Banks Balance Sheet USD-Adjusted
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © SirChub

//@version=5
indicator("Global Central Banks Balance Sheet USD-Adjusted", overlay=true, scale=scale.right)

i_res = input.timeframe('D', "Resolution", options=['D', 'W', 'M'])
unit_input = input.string('Trillions', options=['Millions', 'Billions', 'Trillions'])
units = unit_input == 'Billions' ? 1e3 : unit_input == 'Millions' ? 1e0 : unit_input == 'Trillions' ? 1e6 : na

US_CBBS = (request.security('ECONOMICS:USCBBS', i_res, close)*100)/request.security('TVC:DXY',i_res,close) 
CN_CBBS = (request.security('ECONOMICS:CNCBBS',i_res, close))/request.security('FX:USDCNH',i_res,close)
JP_CBBS = (request.security('ECONOMICS:JPCBBS',i_res, close))/request.security('FX:USDJPY',i_res,close) 
EU_CBBS = (request.security('ECONOMICS:EUCBBS',i_res, close))*request.security('FX:EURUSD',i_res,close) 
UK_CBBS = (request.security('ECONOMICS:GBCBBS',i_res, close))*request.security('FX:GBPUSD',i_res,close) 

CH_CBBS = (request.security('ECONOMICS:CHCBBS',i_res, close))*request.security('FX_IDC:CHFUSD',i_res,close)
NO_CBBS = (request.security('ECONOMICS:NOCBBS',i_res, close))/request.security('FX_IDC:USDNOK',i_res,close)
CA_CBBS = (request.security('ECONOMICS:CACBBS',i_res, close))*request.security('FX_IDC:CADUSD',i_res,close)
AU_CBBS = (request.security('ECONOMICS:AUCBBS',i_res, close))*request.security('FX:AUDUSD',i_res,close)

BR_CBBS = (request.security('ECONOMICS:BRCBBS',i_res, close))/request.security('FX_IDC:USDBRL',i_res,close)
ID_CBBS = (request.security('ECONOMICS:IDM2',i_res, close))/request.security('FX_IDC:USDIDR',i_res,close)+(request.security('ECONOMICS:IDFER',i_res, close)-150000000001)
RU_CBBS = (request.security('ECONOMICS:RUCBBS',i_res, close))/request.security('FX_IDC:USDRUB',i_res,close)
MX_CBBS = (request.security('ECONOMICS:MXCBBS',i_res, close))/request.security('FX:USDMXN',i_res,close)
IN_CBBS = (request.security('ECONOMICS:INCBBS',i_res, close))/request.security('FX_IDC:USDINR',i_res,close)

TW_CBBS = (request.security('ECONOMICS:TWCBBS',i_res, close))/request.security('FX_IDC:USDTWD',i_res,close)
TH_CBBS = (request.security('ECONOMICS:THCBBS',i_res, close))/request.security('FX_IDC:USDTHB',i_res,close)
SG_CBBS = (request.security('ECONOMICS:SGCBBS',i_res, close))/request.security('FX_IDC:USDSGD',i_res,close)
KR_CBBS = (request.security('ECONOMICS:KRCBBS',i_res, close))/request.security('FX_IDC:USDKRW',i_res,close)
HK_CBBS = (request.security('ECONOMICS:HKM1',i_res, close))/request.security('FX_IDC:USDHKD',i_res,close)+(request.security('ECONOMICS:HKFER',i_res, close))

Global_CBBS = (US_CBBS+CN_CBBS+JP_CBBS+EU_CBBS+UK_CBBS+KR_CBBS+IN_CBBS+CA_CBBS+AU_CBBS+TW_CBBS+BR_CBBS+CH_CBBS+RU_CBBS+MX_CBBS+TH_CBBS+ID_CBBS+SG_CBBS+HK_CBBS+NO_CBBS)/1e12

var Global_CBBS_offset = 0 // 2-week offset for use with daily charts

if timeframe.isdaily
    Global_CBBS_offset := 0

if timeframe.isweekly
    Global_CBBS_offset := 0
    
if timeframe.ismonthly
    Global_CBBS_offset := 0
    
plot(Global_CBBS, title='Global Central Banks Balance Sheet', color=color.new(color.black, 50), style=plot.style_line, offset=Global_CBBS_offset)