Global Unemployment Rate
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © miguefinance
// The Global Unemployment rate includes the Eurozone + 19 countries from all the continents, which are some of the richest countries as well as some of the most populous
// it does not include India as its unemployment data as of today is only since year 2019

//@version=5
indicator("Global Unemployment Rate", overlay=false)

// PINE SCRIPTS LIMITS TO REQUESTING 40 SECURITIES, SO I HAD TO PUT ONLY SOME THE RICHEST COUNTRIES AND THE MOST POPULOUS

EUPOP=request.security("ECONOMICS:EUPOP", timeframe.period, close)
EUUR=request.security("ECONOMICS:EUUR", timeframe.period, close)
//north america
USPOP=request.security("ECONOMICS:USPOP", timeframe.period, close)
USUR=request.security("ECONOMICS:USUR", timeframe.period, close)
//CAPOP=request.security("ECONOMICS:CAPOP", timeframe.period, close)
//CAUR=request.security("ECONOMICS:CAUR" , timeframe.period, close)
// non EU europe
//CHPOP=request.security("ECONOMICS:CHPOP", timeframe.period, close)
//CHUR=request.security("ECONOMICS:CHUR", timeframe.period, close)
GBPOP=request.security("ECONOMICS:GBPOP", timeframe.period, close)
GBUR=request.security("ECONOMICS:GBUR", timeframe.period, close)
//FIPOP=request.security("ECONOMICS:FIPOP", timeframe.period, close)
//FIUR=request.security("ECONOMICS:FIUR", timeframe.period, close)
//SEPOP=request.security("ECONOMICS:SEPOP", timeframe.period, close)
//SEUR=request.security("ECONOMICS:SEUR", timeframe.period, close)
RUPOP=request.security("ECONOMICS:RUPOP", timeframe.period, close)
RUUR=request.security("ECONOMICS:RUUR", timeframe.period, close)
//pacific
AUPOP=request.security("ECONOMICS:AUPOP", timeframe.period, close)
AUUR=request.security("ECONOMICS:AUUR", timeframe.period, close)      // australia data is from 1979
//NZPOP=request.security("ECONOMICS:NZPOP", timeframe.period, close) 
//NZUR=request.security("ECONOMICS:NZUR", timeframe.period, close)
//Asia
BDPOP=request.security("ECONOMICS:BDPOP", timeframe.period, close)
BDUR=request.security("ECONOMICS:BDUR", timeframe.period, close)       ///bangladesh data is from 1992
CNPOP=request.security("ECONOMICS:CNPOP", timeframe.period, close)
CNUR=request.security("ECONOMICS:CNUR", timeframe.period, close)       // China data is from 2002 
IDPOP=request.security("ECONOMICS:IDPOP", timeframe.period, close)
IDUR=request.security("ECONOMICS:IDUR", timeframe.period, close)       //indonesia data is from 1983
//INPOP=request.security("ECONOMICS:INPOP", timeframe.period, close)
//INUR=request.security("ECONOMICS:INUR", timeframe.period, close)      //india DATA IS FROM 2019 ONLY!!! so have to disable it
JPPOP=request.security("ECONOMICS:JPPOP", timeframe.period, close)
JPUR=request.security("ECONOMICS:JPUR", timeframe.period, close)      // japan data is from 1954
//KRPOP=request.security("ECONOMICS:KRPOP", timeframe.period, close)
//KRUR=request.security("ECONOMICS:KRUR", timeframe.period, close)     //Korea data is from 2008 only!
MMPOP=request.security("ECONOMICS:MMPOP", timeframe.period, close)
MMUR=request.security("ECONOMICS:MMUR", timeframe.period, close)      // mianmar data is from 1991
PHPOP=request.security("ECONOMICS:PHPOP", timeframe.period, close)
PHUR=request.security("ECONOMICS:PHUR", timeframe.period, close)     // philipines data from 1986
PKPOP=request.security("ECONOMICS:PKPOP", timeframe.period, close)
PKUR=request.security("ECONOMICS:PKUR", timeframe.period, close)     // pakistan data is from 1986
THPOP=request.security("ECONOMICS:THPOP", timeframe.period, close)
THUR=request.security("ECONOMICS:THUR", timeframe.period, close)     // thailand data is from 1978
VNPOP=request.security("ECONOMICS:VNPOP", timeframe.period, close)  
VNUR=request.security("ECONOMICS:VNUR", timeframe.period, close)    // vietnam data is from 1999
//SGPOP=request.security("ECONOMICS:SGPOP", timeframe.period, close)
//SGUR=request.security("ECONOMICS:SGUR", timeframe.period, close)
//latin america
ARPOP=request.security("ECONOMICS:ARPOP", timeframe.period, close)
ARUR=request.security("ECONOMICS:ARUR", timeframe.period, close)     //argetina data is from 2003
//BRPOP=request.security("ECONOMICS:BRPOP", timeframe.period, close)
//BRUR=request.security("ECONOMICS:BRUR", timeframe.period, close)     // data is from 2012 ONLY.. this is the FILTER
//CLPOP=request.security("ECONOMICS:CLPOP", timeframe.period, close)
//CLUR=request.security("ECONOMICS:CLUR", timeframe.period, close)
//COPOPv=request.security("ECONOMICS:COPOP", timeframe.period, close)
//COUR=request.security("ECONOMICS:COUR", timeframe.period, close)
MXPOP=request.security("ECONOMICS:MXPOP", timeframe.period, close)
MXUR=request.security("ECONOMICS:MXUR", timeframe.period, close)        //mexico data is from 1995
//PEPOP=request.security("ECONOMICS:PEPOP", timeframe.period, close)
//PEUR=request.security("ECONOMICS:PEUR", timeframe.period, close)
//VEPOP=request.security("ECONOMICS:VEPOP", timeframe.period, close)
//VEUR=request.security("ECONOMICS:VEUR", timeframe.period, close)
//middle east
//AEPOP=request.security("ECONOMICS:AEPOP", timeframe.period, close)
//AEUR=request.security("ECONOMICS:AEUR", timeframe.period, close)
//ILPOP=request.security("ECONOMICS:ILPOP", timeframe.period, close)
//ILUR=request.security("ECONOMICS:ILUR", timeframe.period, close)
//TRPOP=request.security("ECONOMICS:TRPOP", timeframe.period, close)
//TRUR=request.security("ECONOMICS:TRUR", timeframe.period, close)            // turkey data is from 2005
//IRPOP=request.security("ECONOMICS:IRPOP", timeframe.period, close)
//IRUR=request.security("ECONOMICS:IRUR", timeframe.period, close)       
//africa
CDPOP=request.security("ECONOMICS:CDPOP", timeframe.period, close)
CDUR=request.security("ECONOMICS:CDUR", timeframe.period, close)            // congo data is from 2000
EGPOP=request.security("ECONOMICS:EGPOP", timeframe.period, close)
EGUR=request.security("ECONOMICS:EGUR", timeframe.period, close)          // egypt data from 1994
ETPOP=request.security("ECONOMICS:ETPOP", timeframe.period, close)       
ETUR=request.security("ECONOMICS:ETUR", timeframe.period, close)          //ethiopia data from 1999
//KEPOP=request.security("ECONOMICS:KEPOP", timeframe.period, close)
//KEUR=request.security("ECONOMICS:KEUR", timeframe.period, close)         //Kenya data from 1992 
//NGPOP=request.security("ECONOMICS:NGPOP", timeframe.period, close)
//NGUR=request.security("ECONOMICS:NGUR", timeframe.period, close)          //data is only from 2006
//TZPOP=request.security("ECONOMICS:TZPOP", timeframe.period, close)
//TZUR=request.security("ECONOMICS:TZUR", timeframe.period, close)         //data since 2001
ZAPOP=request.security("ECONOMICS:ZAPOP", timeframe.period, close)
ZAUR=request.security("ECONOMICS:ZAUR", timeframe.period, close)      // data is from year 2000

// Normalize the unemployment data

// 40 COUNTRIES (it fails due to TradingView Limits):
//total_population = EUPOP + EUUR + USPOP + USUR + CAPOP + CAUR + CHPOP + CHUR + GBPOP + GBUR + FIPOP + FIUR + SEPOP + SEUR + RUPOP + RUUR + AUPOP + AUUR + NZPOP + NZUR + BDPOP + BDUR + CNPOP + CNUR + IDPOP + IDUR + INPOP + INUR + JPPOP + JPUR + KRPOP + KRUR + MMPOP + MMUR + PHPOP + PHUR + PKPOP + PKUR + THPOP + THUR + VNPOP + VNUR + SGPOP + SGUR + ARPOP + ARUR + BRPOP + BRUR + CLPOP + CLUR + COPOPv + COUR + MXPOP + MXUR + PEPOP + PEUR + VEPOP + VEUR + AEPOP + AEUR + ILPOP + ILUR + TRPOP + TRUR + IRPOP + IRUR + CDPOP + CDUR + EGPOP + EGUR + ETPOP + ETUR + KEPOP + KEUR + NGPOP + NGUR + TZPOP + TZUR + ZAPOP + ZAUR
//total_unemployed_population = EUPOP * EUUR + USPOP * USUR + CAPOP * CAUR + CHPOP * CHUR + GBPOP * GBUR + FIPOP * FIUR + SEPOP * SEUR + RUPOP * RUUR + AUPOP * AUUR + NZPOP * NZUR + BDPOP * BDUR + CNPOP * CNUR + IDPOP * IDUR + INPOP * INUR + JPPOP * JPUR + KRPOP * KRUR + MMPOP * MMUR + PHPOP * PHUR + PKPOP * PKUR + THPOP * THUR + VNPOP * VNUR + SGPOP * SGUR + ARPOP * ARUR + BRPOP * BRUR + CLPOP * CLUR + COPOPv * COUR + MXPOP * MXUR + PEPOP * PEUR + VEPOP * VEUR + AEPOP * AEUR + ILPOP * ILUR + TRPOP * TRUR + IRPOP * IRUR + CDPOP * CDUR + EGPOP * EGUR + ETPOP * ETUR + KEPOP * KEUR + NGPOP * NGUR + TZPOP * TZUR + ZAPOP * ZAUR

// 20 COUNTRIES (most important in population and some of most rich), but some of the have very short data:
//total_population = EUPOP+ USPOP + RUPOP + BDPOP  + CNPOP + IDPOP  + JPPOP + KRPOP +  MMPOP  + PKPOP +  VNPOP  + ARPOP + BRPOP  + MXPOP  + TRPOP  + CDPOP  + EGPOP +  ZAPOP 
//total_unemployed_population = (EUPOP*EUUR + USPOP*USUR + RUPOP*RUUR + BDPOP*BDUR + CNPOP*CNUR + IDPOP*IDUR  + JPPOP*JPUR + KRPOP*KRUR + MMPOP*MMUR + PKPOP*PKUR + VNPOP*VNUR + ARPOP*ARUR + BRPOP*BRUR + MXPOP*MXUR + TRPOP*TRUR + CDPOP*CDUR + EGPOP*EGUR + ZAPOP*ZAUR)

// 20 countries longer data in trading view (korea, brazil, turkey were removed due to short data, then added instead TH, GB, ET, PH ):
// I have chosen countries with data from at least year 2002 (which is oldest data of China, to not ignore both china and india) so can be seen effect of the two last market crashes
total_population = EUPOP+ USPOP +GBPOP + RUPOP + AUPOP + BDPOP  + CNPOP + IDPOP  + JPPOP  +  MMPOP  + PKPOP + PHPOP + THPOP + VNPOP  + ARPOP   + MXPOP  +  CDPOP  + EGPOP + ETPOP +  ZAPOP 
total_unemployed_population = (EUPOP*EUUR + USPOP*USUR + GBPOP*GBUR + RUPOP*RUUR+ AUPOP*AUUR + BDPOP*BDUR + CNPOP*CNUR + IDPOP*IDUR  + JPPOP*JPUR  + MMPOP*MMUR + PKPOP*PKUR + PHPOP*PHUR+ THPOP*THUR +VNPOP*VNUR + ARPOP*ARUR  + MXPOP*MXUR +  CDPOP*CDUR + EGPOP*EGUR + ETPOP*ETUR + ZAPOP*ZAUR)


global_ur_normalized = total_unemployed_population / total_population
plot(global_ur_normalized, color=color.blue, title="Global Unemplyment Rate", linewidth=2)

