OECD CLI Diffusion Index
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sl-wk

//@version=5
indicator("OECD CLI Diffusion Index")

getDiff(_data) =>
    _diff_yoy = na(_data[11]) ? 0 : (_data - _data[11] > 0 ? 1 : 0)
    _count = na(_data[11]) ? 0 : 1
    [_diff_yoy, _count]
    

AUS                             = request.quandl("OECD/MEI_CLI_LOLITONO_AUS_M", barmerge.gaps_off, 0)
[AUS_Diff, AUS_count]           = getDiff(AUS)
AUT                             = request.quandl("OECD/MEI_CLI_LOLITONO_AUT_M", barmerge.gaps_off, 0)
[AUT_Diff, AUT_count]           = getDiff(AUT)
BEL                             = request.quandl("OECD/MEI_CLI_LOLITONO_BEL_M", barmerge.gaps_off, 0)
[BEL_Diff, BEL_count]           = getDiff(BEL)
BRA                             = request.quandl("OECD/MEI_CLI_LOLITONO_BRA_M", barmerge.gaps_off, 0)
[BRA_Diff, BRA_count]           = getDiff(BRA)
CAN                             = request.quandl("OECD/MEI_CLI_LOLITONO_CAN_M", barmerge.gaps_off, 0)
[CAN_Diff, CAN_count]           = getDiff(CAN)
CHE                             = request.quandl("OECD/MEI_CLI_LOLITONO_CHE_M", barmerge.gaps_off, 0)
[CHE_Diff, CHE_count]           = getDiff(CHE)
CHL                             = request.quandl("OECD/MEI_CLI_LOLITONO_CHL_M", barmerge.gaps_off, 0)
[CHL_Diff, CHL_count]           = getDiff(CHL)
CHN                             = request.quandl("OECD/MEI_CLI_LOLITONO_CHN_M", barmerge.gaps_off, 0)
[CHN_Diff, CHN_count]           = getDiff(CHN)
COL                             = request.quandl("OECD/MEI_CLI_LOLITONO_COL_M", barmerge.gaps_off, 0)
[COL_Diff, COL_count]           = getDiff(COL)
CZE                             = request.quandl("OECD/MEI_CLI_LOLITONO_CZE_M", barmerge.gaps_off, 0)
[CZE_Diff, CZE_count]           = getDiff(CZE)
DEU                             = request.quandl("OECD/MEI_CLI_LOLITONO_DEU_M", barmerge.gaps_off, 0)
[DEU_Diff, DEU_count]           = getDiff(DEU)
DNK                             = request.quandl("OECD/MEI_CLI_LOLITONO_DNK_M", barmerge.gaps_off, 0)
[DNK_Diff, DNK_count]           = getDiff(DNK)
ESP                             = request.quandl("OECD/MEI_CLI_LOLITONO_ESP_M", barmerge.gaps_off, 0)
[ESP_Diff, ESP_count]           = getDiff(ESP)
EST                             = request.quandl("OECD/MEI_CLI_LOLITONO_EST_M", barmerge.gaps_off, 0)
[EST_Diff, EST_count]           = getDiff(EST)
FIN                             = request.quandl("OECD/MEI_CLI_LOLITONO_FIN_M", barmerge.gaps_off, 0)
[FIN_Diff, FIN_count]           = getDiff(FIN)
FRA                             = request.quandl("OECD/MEI_CLI_LOLITONO_FRA_M", barmerge.gaps_off, 0)
[FRA_Diff, FRA_count]           = getDiff(FRA)
GBR                             = request.quandl("OECD/MEI_CLI_LOLITONO_GBR_M", barmerge.gaps_off, 0)
[GBR_Diff, GBR_count]           = getDiff(GBR)
GRC                             = request.quandl("OECD/MEI_CLI_LOLITONO_GRC_M", barmerge.gaps_off, 0)
[GRC_Diff, GRC_count]           = getDiff(GRC)
HUN                             = request.quandl("OECD/MEI_CLI_LOLITONO_HUN_M", barmerge.gaps_off, 0)
[HUN_Diff, HUN_count]           = getDiff(HUN)
IDN                             = request.quandl("OECD/MEI_CLI_LOLITONO_IDN_M", barmerge.gaps_off, 0)
[IDN_Diff, IDN_count]           = getDiff(IDN)
IRL                             = request.quandl("OECD/MEI_CLI_LOLITONO_IRL_M", barmerge.gaps_off, 0)
[IRL_Diff, IRL_count]           = getDiff(IRL)
ISL                             = request.quandl("OECD/MEI_CLI_LOLITONO_ISL_M", barmerge.gaps_off, 0)
[ISL_Diff, ISL_count]           = getDiff(ISL)
ISR                             = request.quandl("OECD/MEI_CLI_LOLITONO_ISR_M", barmerge.gaps_off, 0)
[ISR_Diff, ISR_count]           = getDiff(ISR)
ITA                             = request.quandl("OECD/MEI_CLI_LOLITONO_ITA_M", barmerge.gaps_off, 0)
[ITA_Diff, ITA_count]           = getDiff(ITA)
JPN                             = request.quandl("OECD/MEI_CLI_LOLITONO_JPN_M", barmerge.gaps_off, 0)
[JPN_Diff, JPN_count]           = getDiff(JPN)
KOR                             = request.quandl("OECD/MEI_CLI_LOLITONO_KOR_M", barmerge.gaps_off, 0)
[KOR_Diff, KOR_count]           = getDiff(KOR)
MEX                             = request.quandl("OECD/MEI_CLI_LOLITONO_MEX_M", barmerge.gaps_off, 0)
[MEX_Diff, MEX_count]           = getDiff(MEX)
NLD                             = request.quandl("OECD/MEI_CLI_LOLITONO_NLD_M", barmerge.gaps_off, 0)
[NLD_Diff, NLD_count]           = getDiff(NLD)
NOR                             = request.quandl("OECD/MEI_CLI_LOLITONO_NOR_M", barmerge.gaps_off, 0)
[NOR_Diff, NOR_count]           = getDiff(NOR)
POL                             = request.quandl("OECD/MEI_CLI_LOLITONO_POL_M", barmerge.gaps_off, 0)
[POL_Diff, POL_count]           = getDiff(POL)
PRT                             = request.quandl("OECD/MEI_CLI_LOLITONO_PRT_M", barmerge.gaps_off, 0)
[PRT_Diff, PRT_count]           = getDiff(PRT)
RUS                             = request.quandl("OECD/MEI_CLI_LOLITONO_RUS_M", barmerge.gaps_off, 0)
[RUS_Diff, RUS_count]           = getDiff(RUS)
SVK                             = request.quandl("OECD/MEI_CLI_LOLITONO_SVK_M", barmerge.gaps_off, 0)
[SVK_Diff, SVK_count]           = getDiff(SVK)
SVN                             = request.quandl("OECD/MEI_CLI_LOLITONO_SVN_M", barmerge.gaps_off, 0)
[SVN_Diff, SVN_count]           = getDiff(SVN)
SWE                             = request.quandl("OECD/MEI_CLI_LOLITONO_SWE_M", barmerge.gaps_off, 0)
[SWE_Diff, SWE_count]           = getDiff(SWE)
TUR                             = request.quandl("OECD/MEI_CLI_LOLITONO_TUR_M", barmerge.gaps_off, 0)
[TUR_Diff, TUR_count]           = getDiff(TUR)
USA                             = request.quandl("OECD/MEI_CLI_LOLITONO_USA_M", barmerge.gaps_off, 0)
[USA_Diff, USA_count]           = getDiff(USA)
ZAF                             = request.quandl("OECD/MEI_CLI_LOLITONO_ZAF_M", barmerge.gaps_off, 0)
[ZAF_Diff, ZAF_count]           = getDiff(ZAF)

diffusion                       = AUS_Diff+AUT_Diff+BEL_Diff+BRA_Diff+CAN_Diff+CHE_Diff+CHL_Diff+CHN_Diff+COL_Diff+CZE_Diff+DEU_Diff+DNK_Diff+ESP_Diff+EST_Diff+FIN_Diff+FRA_Diff+GBR_Diff+GRC_Diff+HUN_Diff+IDN_Diff+IRL_Diff+ISL_Diff+ISR_Diff+ITA_Diff+JPN_Diff+KOR_Diff+MEX_Diff+NLD_Diff+NOR_Diff+POL_Diff+PRT_Diff+RUS_Diff+SVK_Diff+SVN_Diff+SWE_Diff+TUR_Diff+USA_Diff+ZAF_Diff
count                           = AUS_count+AUT_count+BEL_count+BRA_count+CAN_count+CHE_count+CHL_count+CHN_count+COL_count+CZE_count+DEU_count+DNK_count+ESP_count+EST_count+FIN_count+FRA_count+GBR_count+GRC_count+HUN_count+IDN_count+IRL_count+ISL_count+ISR_count+ITA_count+JPN_count+KOR_count+MEX_count+NLD_count+NOR_count+POL_count+PRT_count+RUS_count+SVK_count+SVN_count+SWE_count+TUR_count+USA_count+ZAF_count
diffusion_index                 = diffusion/count * 100

plot(diffusion_index, color=color.rgb(221,34,255), linewidth=2)