world stage index
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © kattsu

//@version=5
indicator('world stage index', overlay=false)

//40symbols

//"TVC:SHCOMP" is revised to "SSE:000001"

s1 = request.security('OSE:NK2251!', '', close)
s2 = request.security('DJ:DJI', '', close)
s3 = request.security('NASDAQ:IXIC', '', close)
s4 = request.security('SP:SPX', '', close)
s5 = request.security('XETR:DAX', '', close)
s6 = request.security('TVC:CAC40', '', close)
s7 = request.security('TVC:UKX', '', close)
s8 = request.security('TSX:TSX', '', close)
s9 = request.security('SSE:000001', '', close)
s10 = request.security('SZSE:399001', '', close)
s11 = request.security('TVC:HSI', '', close)
s12 = request.security('TWSE:TAIEX', '', close)
s13 = request.security('BSE:SENSEX', '', close)
s14 = request.security('OANDA:SG30SGD', '', close)
s15 = request.security('INDEX:KSI', '', close)
s16 = request.security('SET:SET', '', close)
s17 = request.security('INDEX:SX5E', '', close)
s18 = request.security('INDEX:FTSEMIB', '', close)
s19 = request.security('SIX:SMI', '', close)
s20 = request.security('BME:IBC', '', close)
s21 = request.security('EURONEXT:BEL20', '', close)
s22 = request.security('TVC:AEX', '', close)
s23 = request.security('OMXCOP:OMXC25', '', close)
s24 = request.security('ATHEX:GD', '', close)
s25 = request.security('ASX:XJO', '', close)
s26 = request.security('TVC:NZ50G', '', close)
s27 = request.security('IDX:COMPOSITE', '', close)
s28 = request.security('FTSEMYX:FBMKLCI', '', close)
s29 = request.security('BMFBOVESPA:IBOV', '', close)
s30 = request.security('BMV:ME', '', close)
s31 = request.security('BVL:SPBLPGPT', '', close)
s32 = request.security('TVC:SA40', '', close)
s33 = request.security('MOEX:IMOEX', '', close)
s34 = request.security('GPW:WIG20', '', close)
s35 = request.security('OMXHEX:OMXH25', '', close)
s36 = request.security('OMXSTO:OMXS30', '', close)
s37 = request.security('DFM:DFMGI', '', close)
s38 = request.security('TADAWUL:TASI', '', close)
s39 = request.security('QSE:GNRI', '', close)
s40 = request.security('EGX:EGX30', '', close)

//ema5,20,40 of each symbols
As1 = ta.ema(s1, 5)
Bs1 = ta.ema(s1, 20)
Cs1 = ta.ema(s1, 40)
As2 = ta.ema(s2, 5)
Bs2 = ta.ema(s2, 20)
Cs2 = ta.ema(s2, 40)
As3 = ta.ema(s3, 5)
Bs3 = ta.ema(s3, 20)
Cs3 = ta.ema(s3, 40)
As4 = ta.ema(s4, 5)
Bs4 = ta.ema(s4, 20)
Cs4 = ta.ema(s4, 40)
As5 = ta.ema(s5, 5)
Bs5 = ta.ema(s5, 20)
Cs5 = ta.ema(s5, 40)
As6 = ta.ema(s6, 5)
Bs6 = ta.ema(s6, 20)
Cs6 = ta.ema(s6, 40)
As7 = ta.ema(s7, 5)
Bs7 = ta.ema(s7, 20)
Cs7 = ta.ema(s7, 40)
As8 = ta.ema(s8, 5)
Bs8 = ta.ema(s8, 20)
Cs8 = ta.ema(s8, 40)
As9 = ta.ema(s9, 5)
Bs9 = ta.ema(s9, 20)
Cs9 = ta.ema(s9, 40)
As10 = ta.ema(s10, 5)
Bs10 = ta.ema(s10, 20)
Cs10 = ta.ema(s10, 40)
As11 = ta.ema(s11, 5)
Bs11 = ta.ema(s11, 20)
Cs11 = ta.ema(s11, 40)
As12 = ta.ema(s12, 5)
Bs12 = ta.ema(s12, 20)
Cs12 = ta.ema(s12, 40)
As13 = ta.ema(s13, 5)
Bs13 = ta.ema(s13, 20)
Cs13 = ta.ema(s13, 40)
As14 = ta.ema(s14, 5)
Bs14 = ta.ema(s14, 20)
Cs14 = ta.ema(s14, 40)
As15 = ta.ema(s15, 5)
Bs15 = ta.ema(s15, 20)
Cs15 = ta.ema(s15, 40)
As16 = ta.ema(s16, 5)
Bs16 = ta.ema(s16, 20)
Cs16 = ta.ema(s16, 40)
As17 = ta.ema(s17, 5)
Bs17 = ta.ema(s17, 20)
Cs17 = ta.ema(s17, 40)
As18 = ta.ema(s18, 5)
Bs18 = ta.ema(s18, 20)
Cs18 = ta.ema(s18, 40)
As19 = ta.ema(s19, 5)
Bs19 = ta.ema(s19, 20)
Cs19 = ta.ema(s19, 40)
As20 = ta.ema(s20, 5)
Bs20 = ta.ema(s20, 20)
Cs20 = ta.ema(s20, 40)
As21 = ta.ema(s21, 5)
Bs21 = ta.ema(s21, 20)
Cs21 = ta.ema(s21, 40)
As22 = ta.ema(s22, 5)
Bs22 = ta.ema(s22, 20)
Cs22 = ta.ema(s22, 40)
As23 = ta.ema(s23, 5)
Bs23 = ta.ema(s23, 20)
Cs23 = ta.ema(s23, 40)
As24 = ta.ema(s24, 5)
Bs24 = ta.ema(s24, 20)
Cs24 = ta.ema(s24, 40)
As25 = ta.ema(s25, 5)
Bs25 = ta.ema(s25, 20)
Cs25 = ta.ema(s25, 40)
As26 = ta.ema(s26, 5)
Bs26 = ta.ema(s26, 20)
Cs26 = ta.ema(s26, 40)
As27 = ta.ema(s27, 5)
Bs27 = ta.ema(s27, 20)
Cs27 = ta.ema(s27, 40)
As28 = ta.ema(s28, 5)
Bs28 = ta.ema(s28, 20)
Cs28 = ta.ema(s28, 40)
As29 = ta.ema(s29, 5)
Bs29 = ta.ema(s29, 20)
Cs29 = ta.ema(s29, 40)
As30 = ta.ema(s30, 5)
Bs30 = ta.ema(s30, 20)
Cs30 = ta.ema(s30, 40)
As31 = ta.ema(s31, 5)
Bs31 = ta.ema(s31, 20)
Cs31 = ta.ema(s31, 40)
As32 = ta.ema(s32, 5)
Bs32 = ta.ema(s32, 20)
Cs32 = ta.ema(s32, 40)
As33 = ta.ema(s33, 5)
Bs33 = ta.ema(s33, 20)
Cs33 = ta.ema(s33, 40)
As34 = ta.ema(s34, 5)
Bs34 = ta.ema(s34, 20)
Cs34 = ta.ema(s34, 40)
As35 = ta.ema(s35, 5)
Bs35 = ta.ema(s35, 20)
Cs35 = ta.ema(s35, 40)
As36 = ta.ema(s36, 5)
Bs36 = ta.ema(s36, 20)
Cs36 = ta.ema(s36, 40)
As37 = ta.ema(s37, 5)
Bs37 = ta.ema(s37, 20)
Cs37 = ta.ema(s37, 40)
As38 = ta.ema(s38, 5)
Bs38 = ta.ema(s38, 20)
Cs38 = ta.ema(s38, 40)
As39 = ta.ema(s39, 5)
Bs39 = ta.ema(s39, 20)
Cs39 = ta.ema(s39, 40)
As40 = ta.ema(s40, 5)
Bs40 = ta.ema(s40, 20)
Cs40 = ta.ema(s40, 40)

//criteria of stage 1
//A=ema05, B=ema20 , C=ema40

Sone(A, B, C) =>
    if A >= B and B >= C
        1
    else
        0

//criteria of stage 4
//A=ema05, B=ema20 , C=ema40

Sfour(A, B, C) =>
    if C >= B and B >= A
        1
    else
        0

//Assign each symbols to a function

Sone1 = Sone(As1, Bs1, Cs1)
Sone2 = Sone(As2, Bs2, Cs2)
Sone3 = Sone(As3, Bs3, Cs3)
Sone4 = Sone(As4, Bs4, Cs4)
Sone5 = Sone(As5, Bs5, Cs5)
Sone6 = Sone(As6, Bs6, Cs6)
Sone7 = Sone(As7, Bs7, Cs7)
Sone8 = Sone(As8, Bs8, Cs8)
Sone9 = Sone(As9, Bs9, Cs9)
Sone10 = Sone(As10, Bs10, Cs10)
Sone11 = Sone(As11, Bs11, Cs11)
Sone12 = Sone(As12, Bs12, Cs12)
Sone13 = Sone(As13, Bs13, Cs13)
Sone14 = Sone(As14, Bs14, Cs14)
Sone15 = Sone(As15, Bs15, Cs15)
Sone16 = Sone(As16, Bs16, Cs16)
Sone17 = Sone(As17, Bs17, Cs17)
Sone18 = Sone(As18, Bs18, Cs18)
Sone19 = Sone(As19, Bs19, Cs19)
Sone20 = Sone(As20, Bs20, Cs20)
Sone21 = Sone(As21, Bs21, Cs21)
Sone22 = Sone(As22, Bs22, Cs22)
Sone23 = Sone(As23, Bs23, Cs23)
Sone24 = Sone(As24, Bs24, Cs24)
Sone25 = Sone(As25, Bs25, Cs25)
Sone26 = Sone(As26, Bs26, Cs26)
Sone27 = Sone(As27, Bs27, Cs27)
Sone28 = Sone(As28, Bs28, Cs28)
Sone29 = Sone(As29, Bs29, Cs29)
Sone30 = Sone(As30, Bs30, Cs30)
Sone31 = Sone(As31, Bs31, Cs31)
Sone32 = Sone(As32, Bs32, Cs32)
Sone33 = Sone(As33, Bs33, Cs33)
Sone34 = Sone(As34, Bs34, Cs34)
Sone35 = Sone(As35, Bs35, Cs35)
Sone36 = Sone(As36, Bs36, Cs36)
Sone37 = Sone(As37, Bs37, Cs37)
Sone38 = Sone(As38, Bs38, Cs38)
Sone39 = Sone(As39, Bs39, Cs39)
Sone40 = Sone(As40, Bs40, Cs40)


Sfour1 = Sfour(As1, Bs1, Cs1)
Sfour2 = Sfour(As2, Bs2, Cs2)
Sfour3 = Sfour(As3, Bs3, Cs3)
Sfour4 = Sfour(As4, Bs4, Cs4)
Sfour5 = Sfour(As5, Bs5, Cs5)
Sfour6 = Sfour(As6, Bs6, Cs6)
Sfour7 = Sfour(As7, Bs7, Cs7)
Sfour8 = Sfour(As8, Bs8, Cs8)
Sfour9 = Sfour(As9, Bs9, Cs9)
Sfour10 = Sfour(As10, Bs10, Cs10)
Sfour11 = Sfour(As11, Bs11, Cs11)
Sfour12 = Sfour(As12, Bs12, Cs12)
Sfour13 = Sfour(As13, Bs13, Cs13)
Sfour14 = Sfour(As14, Bs14, Cs14)
Sfour15 = Sfour(As15, Bs15, Cs15)
Sfour16 = Sfour(As16, Bs16, Cs16)
Sfour17 = Sfour(As17, Bs17, Cs17)
Sfour18 = Sfour(As18, Bs18, Cs18)
Sfour19 = Sfour(As19, Bs19, Cs19)
Sfour20 = Sfour(As20, Bs20, Cs20)
Sfour21 = Sfour(As21, Bs21, Cs21)
Sfour22 = Sfour(As22, Bs22, Cs22)
Sfour23 = Sfour(As23, Bs23, Cs23)
Sfour24 = Sfour(As24, Bs24, Cs24)
Sfour25 = Sfour(As25, Bs25, Cs25)
Sfour26 = Sfour(As26, Bs26, Cs26)
Sfour27 = Sfour(As27, Bs27, Cs27)
Sfour28 = Sfour(As28, Bs28, Cs28)
Sfour29 = Sfour(As29, Bs29, Cs29)
Sfour30 = Sfour(As30, Bs30, Cs30)
Sfour31 = Sfour(As31, Bs31, Cs31)
Sfour32 = Sfour(As32, Bs32, Cs32)
Sfour33 = Sfour(As33, Bs33, Cs33)
Sfour34 = Sfour(As34, Bs34, Cs34)
Sfour35 = Sfour(As35, Bs35, Cs35)
Sfour36 = Sfour(As36, Bs36, Cs36)
Sfour37 = Sfour(As37, Bs37, Cs37)
Sfour38 = Sfour(As38, Bs38, Cs38)
Sfour39 = Sfour(As39, Bs39, Cs39)
Sfour40 = Sfour(As40, Bs40, Cs40)

//Sum of stage1
//divided by 0.4
//to displey from 0to 100
ST1 = Sone1 + Sone2 + Sone3 + Sone4 + Sone5 + Sone6 + Sone7 + Sone8 + Sone9 + Sone10 + Sone11 + Sone12 + Sone13 + Sone14 + Sone15 + Sone16 + Sone17 + Sone18 + Sone19 + Sone20 + Sone21 + Sone22 + Sone23 + Sone24 + Sone25 + Sone26 + Sone27 + Sone28 + Sone29 + Sone30 + Sone31 + Sone32 + Sone33 + Sone34 + Sone35 + Sone36 + Sone37 + Sone38 + Sone39 + Sone40
plot(ST1 / 0.4, color=#ffd70050, style=plot.style_area)

//Sum of stage4
//divided by 0.4
//to displey from 0to 100
ST4 = Sfour1 + Sfour2 + Sfour3 + Sfour4 + Sfour5 + Sfour6 + Sfour7 + Sfour8 + Sfour9 + Sfour10 + Sfour11 + Sfour12 + Sfour13 + Sfour14 + Sfour15 + Sfour16 + Sfour17 + Sfour18 + Sfour19 + Sfour20 + Sfour21 + Sfour22 + Sfour23 + Sfour24 + Sfour25 + Sfour26 + Sfour27 + Sfour28 + Sfour29 + Sfour30 + Sfour31 + Sfour32 + Sfour33 + Sfour34 + Sfour35 + Sfour36 + Sfour37 + Sfour38 + Sfour39 + Sfour40
plot(ST4 / 0.4, color=#1e90ff50, style=plot.style_area)

//R＝ratio of stage1/4
//2.5times to displey from 0 to 100
//Because R is almost between 0 and 40

R = ST1 / ST4 * 2.5
plot(R, color=color.new(color.red, 20), style=plot.style_line, linewidth=2)

//center line
hline(50, title='50', color=color.black, linestyle=hline.style_solid, linewidth=2, editable=true)

//80% and 20% line
hline(80, title='50', color=color.green, linestyle=hline.style_solid, linewidth=1, editable=true)
hline(20, title='50', color=color.green, linestyle=hline.style_solid, linewidth=1, editable=true)

//ずらっと40個並べないで、ループ化したコードにしたい。今後の勉強課題。

