Global Money Supply 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 Money Supply 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_MS = (request.security('FRED:WM2NS', i_res, close)*100)/request.security('TVC:DXY',i_res,close) 
CN_MS = (request.security('ECONOMICS:CNM2',i_res, close))/request.security('FX:USDCNH',i_res,close)
JP_MS = (request.security('ECONOMICS:JPM3',i_res, close))/request.security('FX:USDJPY',i_res,close) 
EU_MS = (request.security('ECONOMICS:EUM3',i_res, close))*request.security('FX:EURUSD',i_res,close) 
UK_MS = (request.security('ECONOMICS:GBM3',i_res, close))*request.security('FX:GBPUSD',i_res,close) 

KR_MS = (request.security('ECONOMICS:KRM3',i_res, close))/request.security('FX_IDC:USDKRW',i_res,close)
IN_MS = (request.security('ECONOMICS:INM3',i_res, close))/request.security('FX_IDC:USDINR',i_res,close)
CA_MS = (request.security('ECONOMICS:CAM3',i_res, close))*request.security('FX_IDC:CADUSD',i_res,close)
AU_MS = (request.security('ECONOMICS:AUM3',i_res, close))*request.security('FX:AUDUSD',i_res,close)

TW_MS = (request.security('ECONOMICS:TWM2',i_res, close))/request.security('FX_IDC:USDTWD',i_res,close)
BR_MS = (request.security('ECONOMICS:BRM3',i_res, close))/request.security('FX_IDC:USDBRL',i_res,close)
CH_MS = (request.security('ECONOMICS:CHM3',i_res, close))*request.security('FX_IDC:CHFUSD',i_res,close)
RU_MS = (request.security('ECONOMICS:RUM2',i_res, close))/request.security('FX_IDC:USDRUB',i_res,close)
MX_MS = (request.security('ECONOMICS:MXM3',i_res, close))/request.security('FX:USDMXN',i_res,close)

TH_MS = (request.security('ECONOMICS:THM3',i_res, close))/request.security('FX_IDC:USDTHB',i_res,close)
ID_MS = (request.security('ECONOMICS:IDM2',i_res, close))/request.security('FX_IDC:USDIDR',i_res,close)
SG_MS = (request.security('ECONOMICS:SGM3',i_res, close))/request.security('FX_IDC:USDSGD',i_res,close)

Global_MS = (US_MS+CN_MS+JP_MS+EU_MS+UK_MS+KR_MS+IN_MS+CA_MS+AU_MS+TW_MS+BR_MS+CH_MS+RU_MS+MX_MS+TH_MS+ID_MS+SG_MS)/1e12

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

if timeframe.isdaily
    Global_MS_offset := 0

if timeframe.isweekly
    Global_MS_offset := 0
    
if timeframe.ismonthly
    Global_MS_offset := 0
    
plot(Global_MS, title='Global Money Supply', color=color.new(color.black, 10), style=plot.style_line, offset=Global_MS_offset)
