Three Headed Dragon For ThinkOrSwim

RedToGreen

Active member
Err...The 4 Headed Dragon. It was originally born with 3 heads but somehow, grew another ;)

Current Chart of EDU

I really like seeing the Future clouds in this state for a move to the upside...Of course, moves always have an end, so doesn't always work if late in.

Also works in reverse
tCjQVrG.png


SyyY1Iu.png

MRNA 6-21-2021




My original quest when using the Ichimoku was pondering, Why, on TSLA and others like it, did this fail?

iVQ9j48.png


Which led me to look at variations of the Traditonal 9/26 Ichimoku Settings
The Three Headed Dragon uses:
2-6 (Started Phasing out...More of a entry exit line)
4-13
9-26
18-52
27-78

And with that, we have a clearer picture of why TSLA had a failed Kumo Break

vrRP4p0.png


As you can see, there is resistance above, Which at the time, Was using The MTF TK Dragon (Three-Headed) and seeing price being rejected at the Weekly 52, shown below

sIA3NIc.png

Another thing I saw when using variations of the Chikou (Lagging) was when a longer term lagging was above a shorter term, It's generally bullish and vice versa

B5bJpeS.png


Lagging Histogram

Y5w8WKo.png


JFsWrfB.png


Taken from Christopher84 and His confirmation candles, I developed a similar way of gauging to see if things were trending up/down only using the Three Headed Dragon and all of its information.

The higher the number is, The more Bullish/Bearish, (positive/Negative) it is

QWC10A1.png

I do have more to add but being pressed for time I wanted to add some code for anyone interested to checkout

****Original Three headed Dragon code

Code:
## TK Dragon 12-30-2022 By Red_to_Green/AKA Hypnotic_Options
input DN = Double.NaN;
input price = close;


input T2 = 3;
input T4 = 4.5;
input T9 = 9;
input T18 = 18;
input T27 = 27;
input K6 = 8.66;
input K13 = 13;
input K26 = 26;
input K52 = 52;
input K78 = 78;

input ShowTEntry = no;
input ShowKExit = no;
input showT2 = no; #HINT ShowT2: plot Tenkan2
input showK6 = no; #HINT Showk6: plot kijun6
input showT4 = no;
input showk13 = no;
input showT9 = no;
input showk26 = no;
input showT18 = no;
input showK52 = no;
input showT27 = no;
input showK78 = no;
input ShowT2_K6 = no;
input ShowT4_K13 = no;
input showplotnumbers = no;
input showTKcloudT2K6 = no; #HINT showTKcloudT2K6: show Tenkan2, Kijun6 cloud
input showTKcloudT4K13 = no; #HINT showTKcloudT4K13: show Tenkan4, Kijun13 cloud
input showTKcloudT4K52 = no; #HINT showTKcloudT4K52: show Tenkan4, Kijun52 cloud
input showAllTKClouds = no; #HINT showallTKClouds: show Tenkan4, Kijun13, kijun52 clouds
input ShowCombinedTKCloud = no;
input ShowCombined_AB = no;

input showCloud1KUMO = no; #HINT showcloud1KUMO: show A1,B1 Dragon clouds(T2/K6)
input showcloud2KUMO = no; #HINT showcloud2KUMO: show A2,B2 Dragon clouds(T4/K13)
input showcloud3KUMO = no; #HINT showcloud3KUMO: show A3,B3 Dragon clouds(T9/K26)
input showcloud4KUMO = no; #HINT showcloud4KUMO: show A4,B4 Dragon clouds(T18/K52)
input showcloud5KUMO = no; #HINT showcloud5KUMO: show A5,B5 Dragon clouds(T27/78)
input ShowAllDragonClouds = no;

input ShowCloud1_KUMOLines = no; #HINT showcloud1_KUMOLines: plot A1,B1 Dragon lines(T2/K6)
input ShowCloud2_KUMOLines = no;  #HINT showcloud2_KUMOLines: plot A2,B2 Dragon lines(T4/K13)
input ShowCloud3_KUMOLines = no;  #HINT showcloud3_KUMOLines: plot A3,B3 Dragon lines(T9/K26)
input ShowCloud4_KUMOLines = no; #HINT showcloud4_KUMOLines: plot A4,B4 Dragon lines(T18/K52)
input ShowCloud5_KUMOLines = no;  #HINT showcloud5_KUMOLines: plot A5,B5 Dragon lines(T27/78)

input ShowEntry_ExitCloud = No; #Hint ShowEntry_ExitCloud: plot T_Entry, Kumo B cloud
input ShowT2B1_Cloud = No; #Hint ShowT2B1_Cloud : plot T2, Kumo B1 cloud
input ShowT4B2_Cloud = No; #Hint ShowT4B2_Cloud : plot T4, Kumo B2 cloud

input ShowLagging = no;
input ShowLagging1 = no;
input ShowLagging2 = no;
input ShowLagging3 = no;
input ShowLagging4 = no;
input ShowLagging5  = no;
input showPastKijunClouds = no;
input showPastKijunClouds1 = no;
input showPastKijunClouds2 = no;
input showPastKijunClouds3 = no;
input showPastKijunClouds4 = no;
input showchartlabels = yes;
input specificLength = 100;
def bn = BarNumber();
input showBalloons1 = {Left,  Right, default Off};
input showBalloons2 = {Left,  Right, default Off};
input showBalloons3 = {Left,  Right, default Off};
input showBalloons4 = {Left,  Right, default Off};

input Spacer = yes;


########################################################
      #        Tenkan_Kijun         #
##################################################

def Tenkan2 = (Highest(high, T2) + Lowest(low, T2)) / 2  ;
def Kijun6 = (Highest(high, K6) + Lowest(low, K6)) / 2;
def A1 = (Tenkan2[K6] + Kijun6[K6]) / 2;
def B1 = (Highest(high[K6], 2 * K6) + Lowest(low[K6], 2 * K6)) / 2;

def Tenkan4 = (Highest(high, T4) + Lowest(low, T4)) / 2  ;
def Kijun13 = (Highest(high, K13) + Lowest(low, K13)) / 2;
def A2 = (Tenkan4[K13] + Kijun13[K13]) / 2;
def B2 = (Highest(high[K13], 2 * K13) + Lowest(low[K13], 2 * K13)) / 2;
#plot Chikou = close[-K13];

def Tenkan9 = (Highest(high, T9) + Lowest(low, T9)) / 2  ;
def Kijun26 = (Highest(high, K26) + Lowest(low, K26)) / 2;
def A3 = (Tenkan9[K26] + Kijun26[K26]) / 2;
def B3 = (Highest(high[K26], 2 * K26) + Lowest(low[K26], 2 * K26)) / 2;

def Tenkan18 = (Highest(high, T18) + Lowest(low, T18)) / 2;
def Kijun52 = (Highest(high, K52) + Lowest(low, K52)) / 2;
def A4 = (Tenkan18[K52] + Kijun52[K52]) / 2;
def B4 = (Highest(high[K52], 2 * K52) + Lowest(low[K52], 2 * K52)) / 2;

def Tenkan27 = (Highest(high, T27) + Lowest(low, T27)) / 2;
def Kijun78 = (Highest(high, K78) + Lowest(low, K78)) / 2;
def A5 = (Tenkan27[K78] + Kijun78[K78]) / 2;
def B5 = (Highest(high[K78], 2 * K78) + Lowest(low[K78], 2 * K78)) / 2;

def ALLT = (Tenkan2 + Tenkan4) / 2 ;
def ALLK = (Kijun6 + Kijun13) / 2 ;

def AllA = (A1 + A2 + A3 + A4 + A5) / 5 ;
def AllB = (B1 + B2 + B3 + B4 + B5) / 5 ;


def AllTKLong = ALLT > ALLK;
def AllTKShort = ALLT < ALLK;

AddCloud(if ShowCombinedTKCloud then ALLT else Double.NaN, if ShowCombinedTKCloud then ALLK else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

AddCloud(if ShowCombined_AB then AllA else Double.NaN, if ShowCombined_AB then AllB else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

#####################################################
  #             CHIKOU                           #
#######################################################

#def Chikou6 = close[-K6]  ;
def Chikou13 = close[-K13]  ;
def Chikou26 =  close[-K26]  ;
def Chikou52 =  close[-K52]  ;
def Chikou78 =  close[-K78]  ;

#plot Chikou6p = if ShowLagging or ShowLagging1 then close[-K6] else Double.NaN;
plot Chikou13p = if ShowLagging or ShowLagging2  then close[-K13] else Double.NaN;
plot Chikou26p = if ShowLagging or ShowLagging3 then close[-K26] else Double.NaN;
plot Chikou52p = if ShowLagging or ShowLagging4 then close[-K52] else Double.NaN;
plot Chikou78p = if ShowLagging or ShowLagging5 then close[-K78] else Double.NaN;



########################################################
      #          TK Plots         #
##################################################



plot T1 = if showT2 or ShowT2_K6 then Tenkan2 else Double.NaN;
plot k1 = if showK6 or ShowT2_K6 then Kijun6 else Double.NaN;
T1.SetDefaultColor(CreateColor(52, 186, 136));
T1.SetLineWeight(1);
T1.SetStyle(Curve.MEDIUM_DASH);
#T1.setHiding(!showT2_K6);
k1.SetDefaultColor(CreateColor(255, 43, 43));
k1.SetLineWeight(1);
k1.SetStyle(Curve.MEDIUM_DASH);
#K1.setHiding(!showT2_K6);

plot T = if showT4 or ShowT4_K13 then Tenkan4 else Double.NaN;
plot k = if showk13 or ShowT4_K13 then Kijun13 else Double.NaN;
T.SetDefaultColor(Color.GREEN);
T.SetLineWeight(1);
T.SetStyle(Curve.FIRM);
k.SetDefaultColor(CreateColor(219, 75, 68));
k.SetLineWeight(1);
k.SetStyle(Curve.FIRM);

plot T9P = if showT9 then Tenkan9 else Double.NaN;
plot k26P = if showk26 then Kijun26 else Double.NaN;
T9P.SetDefaultColor(Color.GREEN);
T9P.SetLineWeight(1);
T9P.SetStyle(Curve.FIRM);
k26P.SetDefaultColor(CreateColor(219, 75, 68));
k26P.SetLineWeight(1);
k26P.SetStyle(Curve.FIRM);

plot T18p = if showT18 then Tenkan18 else Double.NaN;
plot k52p = if showK52 then Kijun52 else Double.NaN;
T18p.SetDefaultColor(CreateColor(99, 211, 146));
T18p.SetLineWeight(2);
T18p.SetStyle(Curve.FIRM);
k52p.SetDefaultColor(CreateColor(248, 41, 41));
k52p.SetLineWeight(2);
k52p.SetStyle(Curve.FIRM);

plot T27p = if showT27 then Tenkan27 else Double.NaN;
plot k78p = if showK78 then Kijun78 else Double.NaN;
T27p.SetDefaultColor(CreateColor(99, 211, 146));
T27p.SetLineWeight(2);
T27p.SetStyle(Curve.FIRM);
k78p.SetDefaultColor(CreateColor(248, 41, 41));
k78p.SetLineWeight(2);
k78p.SetStyle(Curve.FIRM);

##################################################################
#                   Dragon Cloud Plots                          #
##################################################################
#AddCloud(if showCloud1KUMO or ShowAllDragonClouds then A1 else Double.NaN, if showCloud1KUMO or ShowAllDragonClouds then B1 else Double.NaN, CreateColor(97, 221, 138), CreateColor(154,150,150));

#plot Cloud1a = if  ShowCloud1_KUMOLines then A1 else Double.NaN;
#Cloud1a.SetDefaultColor(CreateColor(136, 213, 94));
#Cloud1a.SetLineWeight(1);
#Cloud1a.SetStyle(Curve.LONG_DASH);

#plot Cloud1B = if  ShowCloud1_KUMOLines then B1 else Double.NaN;
#Cloud1B.SetDefaultColor(CreateColor(229, 49, 5));
#Cloud1B.SetLineWeight(1);
#Cloud1B.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud2KUMO or ShowAllDragonClouds then A2 else Double.NaN, if showcloud2KUMO or ShowAllDragonClouds then B2 else Double.NaN, CreateColor(97, 221, 138), CreateColor(129,125,125));

plot Cloud2a = if  ShowCloud2_KUMOLines then A2 else Double.NaN;
Cloud2a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud2a.SetLineWeight(1);
Cloud2a.SetStyle(Curve.LONG_DASH);

plot Cloud2b = if  ShowCloud2_KUMOLines then B2 else Double.NaN;
Cloud2b.SetDefaultColor(CreateColor(229, 49, 5));
Cloud2b.SetLineWeight(1);
Cloud2b.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud3KUMO or ShowAllDragonClouds then A3 else Double.NaN, if showcloud3KUMO or ShowAllDragonClouds then B3 else Double.NaN, CreateColor(73, 196, 128), CreateColor(101,98,98));

AddCloud(if showcloud4KUMO or ShowAllDragonClouds then A4 else Double.NaN, if showcloud4KUMO or ShowAllDragonClouds then B4 else Double.NaN, CreateColor(36, 149, 87), CreateColor(73,73,70));

AddCloud(if showcloud5KUMO or ShowAllDragonClouds then A5 else Double.NaN, if showcloud5KUMO or ShowAllDragonClouds then B5 else Double.NaN, CreateColor(6, 78, 38), CreateColor(52,51,51));

plot Cloud5a = if  ShowCloud5_KUMOLines then A5 else Double.NaN;
Cloud2a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud2a.SetLineWeight(1);
Cloud2a.SetStyle(Curve.LONG_DASH);

plot Cloud5b = if  ShowCloud5_KUMOLines then B5 else Double.NaN;
Cloud2b.SetDefaultColor(CreateColor(229, 49, 5));
Cloud2b.SetLineWeight(1);
Cloud2b.SetStyle(Curve.LONG_DASH);

##################################################################
#                   TK Cloud Plots                          #
##################################################################


AddCloud(if showTKcloudT2K6 then Tenkan2 else Double.NaN, if showTKcloudT2K6 then Kijun6 else Double.NaN, CreateColor(138, 223, 206), CreateColor(204, 30, 30));

AddCloud(if showTKcloudT4K13 then Tenkan4 else Double.NaN, if showTKcloudT4K13 then Kijun13 else Double.NaN, CreateColor(26, 201, 143), CreateColor(230, 34, 34));

AddCloud(if showTKcloudT4K52 then Tenkan4 else Double.NaN, if showTKcloudT4K52 then Kijun52 else Double.NaN, CreateColor(155, 233, 207), CreateColor(255, 121, 121));

#################################################################
#                  Tenkan Kumo clouds                      #
################################################################

AddCloud(if ShowT2B1_Cloud then Tenkan2 else Double.NaN, if ShowT2B1_Cloud then B1 else Double.NaN, CreateColor(138, 223, 206), CreateColor(204, 30, 30));
AddCloud(if ShowT4B2_Cloud then Tenkan4 else Double.NaN, if ShowT4B2_Cloud then B2 else Double.NaN, CreateColor(138, 223, 206), CreateColor(204, 30, 30));


#########################################################################
#                        Past Kijun Clouds                          #
#########################################################################
#AddCloud(if showPastKijunClouds then Chikou13p else Double.NaN, if showPastKijunClouds then Chikou6p else Double.NaN, CreateColor(97, 221, 138), CreateColor(151,104,104));
AddCloud(if showPastKijunClouds then Chikou26p else Double.NaN, if showPastKijunClouds then Chikou13p else Double.NaN, CreateColor(97, 221, 138), CreateColor(121,79,79));
AddCloud(if showPastKijunClouds then Chikou52p else Double.NaN, if showPastKijunClouds then Chikou26p else Double.NaN, CreateColor(97, 221, 138), CreateColor(95,61,61));
AddCloud(if showPastKijunClouds then Chikou78p else Double.NaN, if showPastKijunClouds then Chikou52p else Double.NaN, CreateColor(97, 221, 138), CreateColor(69,47,47));

# ============== CLOUDS =====================

#AddCloud( tenkan2, kijun6,    createColor(138,223,206),      createColor(204,30,30));   #*
#AddCloud( Tenkan4, Kijun13,     CreateColor(26, 201, 143),      CreateColor(230, 34, 34));  #*
#AddCloud( Tenkan4, Kijun52,     CreateColor(155, 233, 207),      CreateColor(255, 121, 121));  #*


#AddCloud( tenkan2, kijun6,    createColor(127,243,212),      createColor(198,175,175));   #*
#AddCloud( tenkan4, kijun13,     CreateColor(169,248,221),      CreateColor(221,65,65));  #*
#AddCloud( tenkan4, kijun52,     CreateColor(57,186,100),      CreateColor(221,65,65));  #*

#AddCloud( A2,  B2,     CreateColor(97,221,138),       CreateColor(168,102,86));  #Cloud 1
#AddCloud( A3, B3,    CreateColor(73,196,128),      CreateColor(110,89,84));
#AddCloud( A4, B4 ,    CreateColor(36,149,87),      CreateColor(64,55,52));
#AddCloud( A5, B5 ,    CreateColor(6,78,38),      CreateColor(3,3,3));


########################################################
      #          Current cloud1a status & Breaks        #
##################################################
def cloud1StatusAB = A1 > B1;
def cloud1StatusBA = A1 < B1;
def closePriceLongCloud1 = cloud1statusAB and close > A1 or cloud1StatusBA and close > B1;
def closePriceShortCloud1 = cloud1StatusAB and close < B1 or cloud1StatusBA and close < A1;
#def LagLong1 = cloud1StatusAB and chikou > A1 or cloud1statusBA and chikou > B1;

def cloud2StatusAB = A2 > B2;
def cloud2StatusBA = A2 < B2;
def closePriceLongCloud2 = cloud2statusAB and close > A2 or cloud2StatusBA and close > B2;
def closePriceShortCloud2 = cloud2StatusAB and close < B2 or cloud2StatusBA and close < A2;

def cloud3StatusAB = A3 > B3;
def cloud3StatusBA = A3 < B3;
def closePriceLongCloud3 = cloud3statusAB and close > A3 or cloud3StatusBA and close > B3;
def closePriceShortCloud3 = cloud3StatusAB and close < B3 or cloud3StatusBA and close < A3;

def cloud4StatusAB = A4 > B4;
def cloud4StatusBA = A4 < B4;
def closePriceLongCloud4 = cloud4statusAB and close > A4 or cloud4StatusBA and close > B4;
def closePriceShortCloud4 = cloud4StatusAB and close < B4 or cloud4StatusBA and close < A4;

def cloud5StatusAB = A5 > B5;
def cloud5StatusBA = A5 < B5;
def closePriceLongCloud5 = cloud5statusAB and close > A5 or cloud5StatusBA and close > B5;
def closePriceShortCloud5 = cloud5StatusAB and close < B5 or cloud5StatusBA and close < A5;


########################################################
       #             Longs        #
##################################################
def T2B1KumoLong = Tenkan2 > B1;
def T4B2KumoLong = Tenkan4 > B2;
def TKL4_13 = Tenkan4 > Kijun13;  #***
def TKL9_26 = Tenkan9 > Kijun26;
def TKL4_52 = Tenkan4 > Kijun52;
def CloseK13Long = close > Kijun13;
def CloseK52Long = close > Kijun52;  #***
def CloseK78Long = close > Kijun78;

def FutureBullishCloudA = A1[-8.66] > B1[-8.66];
def FutureBullishCloudB = A2[-13] > B2[-13];
def FutureBullishCloudC = A3[-26] > B3[-26];
def FutureBullishCloudD = A4[-52] > B4[-52];
def FutureBullishCloudE = A5[-78] > B5[-78];
#def Lag1L = Chikou13[13] > chikou6[13];
def Lag2L = Chikou26[26] > chikou13[26];
def Lag3L = Chikou52[52] > chikou26[52];
def Lag4L = Chikou78[78] > chikou52[78];
def ChikouL = Lag2L and Lag3L and Lag4L;
def DragonL = FutureBullishCloudA and FutureBullishCloudB and FutureBullishCloudC and FutureBullishCloudD and FutureBullishCloudE;
def Kumo5CrossUp = close crosses above B5 within 3 bars;


#def LagL = Chikou[52] > close[26];
#def LagS = Chikou[52] < close[26];
#def lag26L = Chikou26[26] > close[26];
#def lag26S = Chikou26[26] < close[26];

#def lag52L = Chikou[52] > close[52];
#def lag52S = Chikou[52] < close[52];

########################################################
      #           Shorts        #
##################################################
def T2B1KumoShort = Tenkan2 < B1;
def T4B2KumoShort = Tenkan4 < B2;
def TKS4_13 = Tenkan4 < Kijun13;  #***
def TKS4_52 = Tenkan4 < Kijun52;
def TKS9_26 = Tenkan9 < Kijun26;
def CloseK13Short = close < Kijun13;
def CloseK52Short = close < Kijun52; #***
def CloseK78Short = close < Kijun78;


def FutureBearishCloudA = A1[-8.66] < B1[-8.66];
def FutureBearishCloudB = A2[-13] < B2[-13];
def FutureBearishCloudC = A3[-26] < B3[-26];
def FutureBearishCloudD = A4[-52] < B4[-52];
def FutureBearishCloudE = A5[-78] < B5[-78];
#def Lag1S = Chikou13[13] < chikou6[13];
def Lag2S = Chikou26[26] < chikou13[26];
def Lag3S = Chikou52[52] < chikou26[52];
def Lag4S = Chikou78[78] < chikou52[78];

def ChikouS =  Lag2S and Lag3S and Lag4S;
def DragonS = FutureBearishCloudA and FutureBearishCloudB and FutureBearishCloudC and FutureBearishCloudD and FutureBearishCloudE;
def Kumo5CrossDown = close crosses below A5 within 3 bars;

#############################################
  #          Agreement Levels x2          #
################################################

# Longs

def Agree_TB_CloudsL = T2B1KumoLong + T4B2KumoLong;
def Agree_TKL = TKL4_13 + TKL4_52 + TKL9_26;
def Agree_CloseL = CloseK13Long + CloseK52Long + CloseK78Long;
def Agree_DragonL = FutureBullishCloudA + FutureBullishCloudB + FutureBullishCloudC + FutureBullishCloudD + FutureBullishCloudE;
def Agree_LagL = Lag2L + Lag3L + Lag4L;
def Agree_KumoL = ClosePriceLongCloud1 + closePriceLongCloud2 + ClosePriceLongCloud3 + ClosePriceLongCloud4 + ClosePriceLongCloud5;


# Shorts

def Agree_TB_CloudsS = T2B1KumoShort + T4B2KumoShort;
def Agree_TKS = TKS4_13 + TKS4_52 + TKS9_26;
def Agree_CloseS = CloseK13Short + CloseK52Short + CloseK78Short;
def Agree_DragonS = FutureBearishCloudA + FutureBearishCloudB + FutureBearishCloudC + FutureBearishCloudD + FutureBearishCloudE;
def Agree_LagS = Lag2S + Lag3S + Lag4S;
def Agree_KumoS = ClosePriceShortCloud1 + closePriceShortCloud2 + ClosePriceShortCloud3 + ClosePriceShortCloud4 + ClosePriceShortCloud5;

# Consensus_Level
def ConLevel_TBClouds = Agree_TB_CloudsL - Agree_TB_CloudsS;
def ConLevel_TK = Agree_TKL - Agree_TKS;
def ConLevel_Close = Agree_CloseL - Agree_CloseS;
def ConLevel_Dragon = Agree_DragonL - Agree_DragonS;
def ConLevel_Lag = Agree_LagL - Agree_LagS;
def ConLevel_Kumo = Agree_KumoL - Agree_KumoS;

## Momentum

def MomCloudsUp = ConLevel_TBClouds[1] < Conlevel_TBClouds;
def MomCloudsDown = ConLevel_TBClouds[1] > Conlevel_TBClouds;

def MomTKUp = ConLevel_TK[1] < Conlevel_TK;
def MomTKDown = ConLevel_TK[1] > Conlevel_TK;

def MomCloseUp = ConLevel_Close[1] < Conlevel_Close;
def MomCloseDown = ConLevel_Close[1] > Conlevel_Close;

def MomDragonUp = ConLevel_Dragon[1] < Conlevel_Dragon;
def MomDragonDown = ConLevel_Dragon[1] > Conlevel_Dragon;

def MomLagUp = ConLevel_Lag[1] < Conlevel_Lag;
def MomLagDown = ConLevel_Lag[1] > Conlevel_Lag;

def MomKumoUp = ConLevel_Kumo[1] < ConLevel_Kumo;
def MomKumoDown = ConLevel_Kumo[1] > ConLevel_Kumo;
# Total Momentum

######
def AgreeTotalL = Agree_TB_CloudsL + Agree_TKL + Agree_CloseL + Agree_DragonL + Agree_LagL + Agree_KumoL;
def AgreeTotalS = Agree_TB_CloudsS + Agree_TKS + Agree_CloseS + Agree_DragonS + Agree_LagS + Agree_KumoS;

def ConTotal = AgreeTotalL - AgreeTotalS;

def MomTotalUp = ConTotal[1] < ConTotal;
def MomTotalDown = ConTotal[1] > ConTotal;

######

#def AgreeTotalL = (T2B1KumoLong + T4B2KumoLong) + (TKL4_13 + TKL9_26 + TKL4_52) + (CloseK13Long + CloseK52Long + CloseK78Long) + (FutureBullishCloudA + FutureBullishCloudB + FutureBullishCloudC + FutureBullishCloudD + FutureBullishCloudE) + (Lag1L + Lag2L + Lag3L + Lag4L) + (ClosePriceLongCloud1 + closePriceLongCloud2 + closePriceLongCloud3 + closePriceLongCloud4 + ClosePriceLongCloud5);

#def AgreeTotalS = (T2B1KumoShort + T4B2KumoShort) + (TKS4_13 + TKS9_26 + TKS4_52) + (CloseK13Short + CloseK52Short + CloseK78Short) + (FutureBearishCloudA + FutureBearishCloudB + FutureBearishCloudC + FutureBearishCloudD + FutureBearishCloudE) + (Lag1S + Lag2S + Lag3S + Lag4S) + (closePriceShortCloud1 + closePriceShortCloud2 + closePriceShortCloud3 + closePriceShortCloud4 + closePriceShortCloud5);

#def ConTotal = AgreeTotalL - AgreeTotalS;

#def MomTotalUp = ConTotal[1] < ConTotal;
#def MomTotalDown = ConTotal[1] > ConTotal;
########################################################
      #          Trigger long         #
##################################################
def Long = ChikouL and T2B1KumoLong and T4B2KumoLong and TKL4_13 and TKL4_52 and CloseK52Long and closeK78Long and TKL9_26 and FutureBullishCloudA and FutureBullishCloudB;

def PullBack_Long = TKS4_52 and TKL4_13 and CloseK52Short and FutureBullishCloudA and FutureBullishCloudB;

########################################################
      #         Trigger Short         #
##################################################
def Short = ChikouS and T2B1KumoShort and T4B2KumoShort and TKS4_13 and TKS4_52 and CloseK52Short and CloseK78Short and TKS9_26 and FutureBearishCloudA and FutureBearishCloudB;

########################################################
      #          Pullback_Short         #
##################################################
def PullBack_Short = TKL4_52 and TKS4_13 and CloseK52Long and FutureBearishCloudA and FutureBearishCloudB;



########################################################
      #          Labels         #
##################################################
AddLabel(showchartlabels, if MomTotalUp then "ToT = " + Round(ConTotal, 1)  else if MomTotalDown then  "ToT = " + Round(ConTotal, 1)  else "ToT = " + Round(ConTotal, 1), if MomTotalDown then CreateColor(191, 42, 42) else if MomTotalUp then CreateColor(63, 187, 93) else color.DARK_GRAY);

AddLabel(showchartlabels, "        " , Color.DARK_GRAY);

AddLabel(showchartlabels, if MomCloudsUp then "T_B = " + Round(ConLevel_TBClouds, 1)  else if MomCloudsDown then  "T_B = " + Round(ConLevel_TBClouds, 1)  else "T_B = " + Round(ConLevel_TBClouds, 1), if MomCloudsDown then CreateColor(191, 42, 42) else if MomCloudsUp then CreateColor(63, 187, 93) else color.DARK_GRAY);

AddLabel(showchartlabels, if MomTKUp then "T_K = " + Round(ConLevel_TK, 1)  else if MomTKDown then  "T_K = " + Round(ConLevel_TK, 1)  else "T_K = " + Round(ConLevel_TK, 1), if MomTKDown then CreateColor(191, 42, 42) else if MomTKUp then CreateColor(63, 187, 93) else color.DARK_GRAY);

AddLabel(showchartlabels, if MomCloseUp then "Close = " + Round(ConLevel_Close, 1)  else if MomCloseDown then  "Close = " + Round(ConLevel_Close, 1)  else "Close = " + Round(ConLevel_Close, 1), if MomCloseDown then CreateColor(191, 42, 42) else if MomCloseUp then CreateColor(63, 187, 93) else color.DARK_GRAY);

AddLabel(showchartlabels, if MomDragonUp then "Dragon = " + Round(ConLevel_Dragon, 1)  else if MomDragonDown then  "Dragon = " + Round(ConLevel_Dragon, 1)  else "Dragon = " + Round(ConLevel_Dragon, 1), if MomDragonDown then CreateColor(191, 42, 42) else if MomDragonUp then CreateColor(63, 187, 93) else color.DARK_GRAY);

AddLabel(showchartlabels, if MomLagUp then "Lag = " + Round(ConLevel_Lag, 1)  else if MomLagDown then  "Lag = " + Round(ConLevel_Lag, 1)  else "Lag = " + Round(ConLevel_Lag, 1), if MomLagDown then CreateColor(191, 42, 42) else if MomLagUp then CreateColor(63, 187, 93) else color.DARK_GRAY);

AddLabel(showchartlabels, if MomKumoUp then "Kumo = " + Round(ConLevel_Kumo, 1)  else if MomKumoDown then  "Kumo = " + Round(ConLevel_Kumo, 1)  else "Kumo = " + Round(ConLevel_Kumo, 1), if MomKumoDown then CreateColor(191, 42, 42) else if MomKumoUp then CreateColor(63, 187, 93) else color.DARK_GRAY);





addLabel(yes, if showt2 and showplotnumbers then "T3.0" else "", color.DARK_GRAY);
AddLabel(yes, if showT4 and showplotnumbers then "T4.5" else "", Color.DARK_GRAY);
AddLabel(yes, if showT9 and showplotnumbers then "T9" else "", Color.DARK_GRAY);
AddLabel(yes, if showT18 and showplotnumbers then "T18" else "", Color.DARK_GRAY);
AddLabel(yes, if showT27 and showplotnumbers then "T27" else "", Color.DARK_GRAY);
AddLabel(yes, if showK6 and showplotnumbers then "K8.66" else "", Color.DARK_GRAY);
AddLabel(yes, if showk13 and showplotnumbers then "K13" else "", Color.DARK_GRAY);
AddLabel(yes, if showk26 and showplotnumbers then "K26" else "", Color.DARK_GRAY);
AddLabel(yes, if showK52 and showplotnumbers then "K52" else "", Color.DARK_GRAY);
AddLabel(yes, if showK78 and showplotnumbers then "K78" else "", Color.DARK_GRAY);

AddLabel(showchartlabels, if showCloud1KUMO and showplotnumbers or ShowCloud1_KUMOLines and showplotnumbers then "T3_K8_Kumo" else "", Color.DARK_GRAY);
AddLabel(showchartlabels, if showcloud2KUMO and showplotnumbers or ShowCloud2_KUMOLines and showplotnumbers then "T4_K13_Kumo" else "", Color.DARK_GRAY);
AddLabel(showchartlabels, if showcloud3KUMO and showplotnumbers or ShowCloud3_KUMOLines and showplotnumbers then "T9_K26_Kumo" else "", Color.DARK_GRAY);
AddLabel(showchartlabels, if showcloud4KUMO and showplotnumbers or ShowCloud4_KUMOLines and showplotnumbers then "T18_K52_Kumo" else "", Color.DARK_GRAY);
AddLabel(showchartlabels, if showcloud5KUMO and showplotnumbers or ShowCloud5_KUMOLines and showplotnumbers then "T27_K78_Kumo" else "", Color.DARK_GRAY);


#AddLabel(showchartlabels , if T2B1KumoLong then "T2_B1 -"   else if T2B1KumoShort then "T2_B1 -"   else "", if T2B1KumoLong  then CreateColor(63, 187, 93) else if T2B1KumoShort  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels , if T4B2KumoLong then "T4_B2 -"   else if T4B2KumoShort then "T4_B2 -"  else "", if T4B2KumoLong  then CreateColor(63, 187, 93) else if T4B2KumoShort  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if Entry_ExitL then "Entry -"    else if Entry_ExitS then "Exit -"  else "", if Entry_ExitL  then CreateColor(63, 187, 93) else if Entry_ExitS  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if TKL4_13 then "4>13"  else if TKS4_13 then "4<13" else "", if TKL4_13  then CreateColor(63, 187, 93) else if TKS4_13  then CreateColor(191, 42, 42) else Color.DARK_GRAY);


# =============================
#AddLabel(Spacer, "        ", Color.DARK_GRAY);


AddLabel(showchartlabels, "        " , Color.DARK_GRAY);



# ========== Cloud Status ===============================
#AddLabel(Spacer, "Clouds  ", Color.GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudA then "A1" else if FutureBearishCloudA then "A1" else "", if FutureBullishCloudA then CreateColor(63, 187, 93) else if FutureBearishCloudA then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudB then "AA" else if FutureBearishCloudB then "AA" else "", if FutureBullishCloudB then CreateColor(63, 187, 93) else if FutureBearishCloudB then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudC then "A" else if FutureBearishCloudC then "A" else "", if FutureBullishCloudC then CreateColor(63, 187, 93) else if FutureBearishCloudC then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudD then "B" else if FutureBearishCloudD then "B" else "", if FutureBullishCloudD then CreateColor(63, 187, 93) else if FutureBearishCloudD then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudE then "C" else if FutureBearishCloudE then "C" else "", if FutureBullishCloudE then CreateColor(63, 187, 93) else if FutureBearishCloudE then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels , if ChikouL then "LAG"   else if ChikouS then "LAG"   else "", if ChikouL  then CreateColor(63, 187, 93) else if ChikouS  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels , if Lag1L then "13"   else if Lag1S then "13"   else "", if Lag1L  then CreateColor(63, 187, 93) else if Lag1S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(showchartlabels , if Lag2L then "26"   else if Lag2S then "26"   else "", if Lag2L  then CreateColor(63, 187, 93) else if Lag2S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(showchartlabels , if Lag3L then "52"   else if Lag3S then "52"   else "", if Lag3L  then CreateColor(63, 187, 93) else if Lag3S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(showchartlabels , if Lag4L then "78"   else if Lag4S then "78"   else "", if Lag4L  then CreateColor(63, 187, 93) else if Lag4S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);




# ========= ALERTS ==========================

# Alert
#Alert(LONGFuture3 AND STKL, "bullish", Alert.Bar, Sound.Ding);
#Alert(SHORTFUture3 AND STKS, "bearish", Alert.Bar, Sound.Ding);


##Long
#AddOrder(OrderType.BUY_TO_OPEN, condition = long,  name = "BTO: " + BarNumber());
#AddOrder(OrderType.SELL_TO_CLOSE, condition = pullBack_Short,  name = "STC: " + BarNumber());

##Short
#AddOrder(OrderType.SELL_TO_OPEN, condition = short,  name = "STO: " + BarNumber());
#AddOrder(OrderType.BUY_TO_CLOSE, condition = pullBack_Long,  name = "BTC: " + BarNumber


#AddLabel(showchartlabels , if lag1l then "13"   else if lag1s then "13"   else "", if lag1l  then CreateColor(63, 187, 93) else if lag1s  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels , if lag2l then "26"   else if lag2s then "26"   else "", if lag2l  then CreateColor(63, 187, 93) else if lag2s  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels , if lag3l then "52"   else if lag3s then "52"   else "", if lag3l  then CreateColor(63, 187, 93) else if lag3s  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels , if lag4l then "78"   else if lag4s then "78"   else "", if lag4l  then CreateColor(63, 187, 93) else if lag4s  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudA then "A" else if FutureBearishCloudA then "A" else "", if FutureBullishCloudA then CreateColor(63, 187, 93) else if FutureBearishCloudA then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudB then "B" else if FutureBearishCloudB then "B" else "", if FutureBullishCloudB then CreateColor(63, 187, 93) else if FutureBearishCloudB then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudC then "C" else if FutureBearishCloudC then "C" else "", if FutureBullishCloudC then CreateColor(63, 187, 93) else if FutureBearishCloudC then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudD then "D" else if FutureBearishCloudD then "D" else "", if FutureBullishCloudD then CreateColor(63, 187, 93) else if FutureBearishCloudD then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels, if FutureBullishCloudE then "E" else if FutureBearishCloudE then "E" else "", if FutureBullishCloudE then CreateColor(63, 187, 93) else if FutureBearishCloudE then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(Spacer, "        ", Color.DARK_GRAY);

#AddLabel(showchartlabels , if DragonL then "DFL"   else if DragonS then "DFS"   else "", if DragonL  then CreateColor(63, 187, 93) else if DragonS  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(showchartlabels, if Long then "TKL" else if Short then "TKS"  else "", if Long  then CreateColor(63, 187, 93) else if Short  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(showchartlabels, if PullBack_Long then "PB_L" else if PullBack_Short then "PB_S"  else "", if PullBack_Long  then CreateColor(63, 187, 93) else if PullBack_Short  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels , if Kumo5CrossUp then "** B5 **"   else if Kumo5CrossDown then "** B5 **"   else "", if Kumo5CrossUp  then CreateColor(63, 187, 93) else if Kumo5CrossDown then CreateColor(191, 42, 42) else Color.DARK_GRAY);


Lagging/Histogram, and other options...if using as histogram, put on lower chart

Code:
# TK Dragon Histogram 12-31-2022 by HypnoticOptions
input DN = Double.NaN;
input price = close;


#declare zerobase;
input T4 = 4.5;
input T9 = 9;
input T18 = 18;
input T27 = 27;

input K13 = 13;
input K26 = 26;
input K52 = 52;
input K78 = 78;

input showLagHisto = no;
input ShowAllDragonClouds = no;
input ShowLagging = no;
input showPastKijunClouds = no;
input Showpriceline = No;

input showCloud1KUMO = no; #HINT showcloud1KUMO: show A1,B1 Dragon clouds(T2/K6)
input showcloud2KUMO = no; #HINT showcloud2KUMO: show A2,B2 Dragon clouds(T4/K13)
input showcloud3KUMO = no; #HINT showcloud3KUMO: show A3,B3 Dragon clouds(T9/K26)
input showcloud4KUMO = no; #HINT showcloud4KUMO: show A4,B4 Dragon clouds(T18/K52)
input showcloud5KUMO = no; #HINT showcloud5KUMO: show A5,B5 Dragon clouds(T27/78)


input ShowCloud1_KUMOLines = no; #HINT showcloud1_KUMOLines: plot A1,B1 Dragon lines(T2/K6)
input ShowCloud2_KUMOLines = no;  #HINT showcloud2_KUMOLines: plot A2,B2 Dragon lines(T4/K13)
input ShowCloud3_KUMOLines = no;  #HINT showcloud3_KUMOLines: plot A3,B3 Dragon lines(T9/K26)
input ShowCloud4_KUMOLines = no; #HINT showcloud4_KUMOLines: plot A4,B4 Dragon lines(T18/K52)
input ShowCloud5_KUMOLines = no;  #HINT showcloud5_KUMOLines: plot A5,B5 Dragon lines(T27/78)


input ShowLagging1 = no;
input ShowLagging2 = no;
input ShowLagging3 = no;
input ShowLagging4 = no;
input ShowLagging5  = no;

input showPastKijunClouds1 = no;
input showPastKijunClouds2 = no;
input showPastKijunClouds3 = no;
input showPastKijunClouds4 = no;
input showchartlabels = yes;


input Spacer = yes;


########################################################
      #        Tenkan_Kijun         #
##################################################

def Tenkan4 = (Highest(high, T4) + Lowest(low, T4)) / 2  ;
def Kijun13 = (Highest(high, K13) + Lowest(low, K13)) / 2;
def A2 = (Tenkan4[K13] + Kijun13[K13]) / 2;
def B2 = (Highest(high[K13], 2 * K13) + Lowest(low[K13], 2 * K13)) / 2;
#plot Chikou = close[-K13];

def Tenkan9 = (Highest(high, T9) + Lowest(low, T9)) / 2  ;
def Kijun26 = (Highest(high, K26) + Lowest(low, K26)) / 2;
def A3 = (Tenkan9[K26] + Kijun26[K26]) / 2;
def B3 = (Highest(high[K26], 2 * K26) + Lowest(low[K26], 2 * K26)) / 2;

def Tenkan18 = (Highest(high, T18) + Lowest(low, T18)) / 2;
def Kijun52 = (Highest(high, K52) + Lowest(low, K52)) / 2;
def A4 = (Tenkan18[K52] + Kijun52[K52]) / 2;
def B4 = (Highest(high[K52], 2 * K52) + Lowest(low[K52], 2 * K52)) / 2;

def Tenkan27 = (Highest(high, T27) + Lowest(low, T27)) / 2;
def Kijun78 = (Highest(high, K78) + Lowest(low, K78)) / 2;
def A5 = (Tenkan27[K78] + Kijun78[K78]) / 2;
def B5 = (Highest(high[K78], 2 * K78) + Lowest(low[K78], 2 * K78)) / 2;


#####################################################
  #             CHIKOU                           #
#######################################################


def Chikou13 = close[-K13]  ;
def Chikou26 =  close[-K26]  ;
def Chikou52 =  close[-K52]  ;
def Chikou78 =  close[-K78]  ;

def Lagg2 = Chikou26[26] - Chikou13[26];
def Lagg3 = Chikou52[52] - Chikou26[52];
def Lagg4 = Chikou78[78] - Chikou52[78];


plot Chikou13p = if ShowLagging or ShowLagging2  then close[-K13] else Double.NaN;
plot Chikou26p = if ShowLagging or ShowLagging3 then close[-K26] else Double.NaN;
plot Chikou52p = if ShowLagging or ShowLagging4 then close[-K52] else Double.NaN;
plot Chikou78p = if ShowLagging or ShowLagging5 then close[-K78] else Double.NaN;






##################################################################
#                   Dragon Cloud Plots                          #
##################################################################


AddCloud(if showcloud2KUMO or ShowAllDragonClouds then A2 else Double.NaN, if showcloud2KUMO or ShowAllDragonClouds then B2 else Double.NaN, CreateColor(97, 221, 138), CreateColor(129,125,125));

plot Cloud2a = if  ShowCloud2_KUMOLines then A2 else Double.NaN;
Cloud2a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud2a.SetLineWeight(1);
Cloud2a.SetStyle(Curve.LONG_DASH);

plot Cloud2b = if  ShowCloud2_KUMOLines then B2 else Double.NaN;
Cloud2b.SetDefaultColor(CreateColor(229, 49, 5));
Cloud2b.SetLineWeight(1);
Cloud2b.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud3KUMO or ShowAllDragonClouds then A3 else Double.NaN, if showcloud3KUMO or ShowAllDragonClouds then B3 else Double.NaN, CreateColor(73, 196, 128), CreateColor(101,98,98));

AddCloud(if showcloud4KUMO or ShowAllDragonClouds then A4 else Double.NaN, if showcloud4KUMO or ShowAllDragonClouds then B4 else Double.NaN, CreateColor(36, 149, 87), CreateColor(73,73,70));

AddCloud(if showcloud5KUMO or ShowAllDragonClouds then A5 else Double.NaN, if showcloud5KUMO or ShowAllDragonClouds then B5 else Double.NaN, CreateColor(6, 78, 38), CreateColor(52,51,51));

plot Cloud5a = if  ShowCloud5_KUMOLines then A5 else Double.NaN;
Cloud2a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud2a.SetLineWeight(1);
Cloud2a.SetStyle(Curve.LONG_DASH);

plot Cloud5b = if  ShowCloud5_KUMOLines then B5 else Double.NaN;
Cloud2b.SetDefaultColor(CreateColor(229, 49, 5));
Cloud2b.SetLineWeight(1);
Cloud2b.SetStyle(Curve.LONG_DASH);


#################################################################
#                  Tenkan Kumo clouds                      #
################################################################


#########################################################################
#                        Past Kijun Clouds                          #
#########################################################################

AddCloud(if showPastKijunClouds then Chikou26p else Double.NaN, if showPastKijunClouds then Chikou13p else Double.NaN, CreateColor(97, 221, 138), CreateColor(121,79,79));
AddCloud(if showPastKijunClouds then Chikou52p else Double.NaN, if showPastKijunClouds then Chikou26p else Double.NaN, CreateColor(97, 221, 138), CreateColor(95,61,61));
AddCloud(if showPastKijunClouds then Chikou78p else Double.NaN, if showPastKijunClouds then Chikou52p else Double.NaN, CreateColor(97, 221, 138), CreateColor(69,47,47));

# ============== CLOUDS =====================

#AddCloud( tenkan2, kijun6,    createColor(138,223,206),      createColor(204,30,30));   #*
#AddCloud( Tenkan4, Kijun13,     CreateColor(26, 201, 143),      CreateColor(230, 34, 34));  #*
#AddCloud( Tenkan4, Kijun52,     CreateColor(155, 233, 207),      CreateColor(255, 121, 121));  #*


#AddCloud( tenkan2, kijun6,    createColor(127,243,212),      createColor(198,175,175));   #*
#AddCloud( tenkan4, kijun13,     CreateColor(169,248,221),      CreateColor(221,65,65));  #*
#AddCloud( tenkan4, kijun52,     CreateColor(57,186,100),      CreateColor(221,65,65));  #*

#AddCloud( A2,  B2,     CreateColor(97,221,138),       CreateColor(168,102,86));  #Cloud 1
#AddCloud( A3, B3,    CreateColor(73,196,128),      CreateColor(110,89,84));
#AddCloud( A4, B4 ,    CreateColor(36,149,87),      CreateColor(64,55,52));
#AddCloud( A5, B5 ,    CreateColor(6,78,38),      CreateColor(3,3,3));


########################################################
      #          Current cloud1a status & Breaks        #
##################################################





########################################################
       #             Longs        #
##################################################

#def T4B2KumoLong = Tenkan4 > B2;
#def TKL4_13 = Tenkan4 > Kijun13;  #***
#def TKL9_26 = Tenkan9 > Kijun26;
#def TKL4_52 = Tenkan4 > Kijun52;
#def CloseK13Long = close > Kijun13;
#def CloseK52Long = close > Kijun52;  #***
#def CloseK78Long = close > Kijun78;


def FutureBullishCloudB = A2[-13] > B2[-13];
def FutureBullishCloudC = A3[-26] > B3[-26];
def FutureBullishCloudD = A4[-52] > B4[-52];
def FutureBullishCloudE = A5[-78] > B5[-78];
def Lag2L = Chikou26[26] > chikou13[26];
def Lag3L = Chikou52[52] > chikou26[52];
def Lag4L = Chikou78[78] > chikou52[78];
def ChikouL = Lag2L and Lag3L and Lag4L;
def DragonL = FutureBullishCloudB and FutureBullishCloudC and FutureBullishCloudD and FutureBullishCloudE;



#def LagL = Chikou[52] > close[26];
#def LagS = Chikou[52] < close[26];
#def lag26L = Chikou26[26] > close[26];
#def lag26S = Chikou26[26] < close[26];

#def lag52L = Chikou[52] > close[52];
#def lag52S = Chikou[52] < close[52];

########################################################
      #           Shorts        #
##################################################




def FutureBearishCloudB = A2[-13] < B2[-13];
def FutureBearishCloudC = A3[-26] < B3[-26];
def FutureBearishCloudD = A4[-52] < B4[-52];
def FutureBearishCloudE = A5[-78] < B5[-78];

def Lag2S = Chikou26[26] < chikou13[26];
def Lag3S = Chikou52[52] < chikou26[52];
def Lag4S = Chikou78[78] < chikou52[78];

def ChikouS =  Lag2S and Lag3S and Lag4S;
def DragonS = FutureBearishCloudB and FutureBearishCloudC and FutureBearishCloudD and FutureBearishCloudE;




plot Lag2Hist = if showLagHisto then Lagg2 else dn;
Lag2Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Lag2Hist.SetLineWeight(3);
Lag2Hist.AssignValueColor(if Lag2L then CreateColor(46,166,111) else if Lag2S  then CreateColor(184,37,37) else Color.DARK_GRAY );

plot Lag3Hist = if showLagHisto then Lagg3 else dn;
Lag3Hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Lag3Hist.SetLineWeight(4);
Lag3Hist.AssignValueColor(if Lag3L then CreateColor(28,120,77) else if Lag3S  then CreateColor(143,26,26) else Color.DARK_GRAY );

plot Lag4Hist = if showLagHisto then Lagg4 else dn;
Lag4Hist.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Lag4Hist.SetLineWeight(5);
Lag4Hist.AssignValueColor(if Lag4L then CreateColor(25,110,80) else if Lag4S  then CreateColor(112, 12, 17) else Color.DARK_GRAY );


AddLabel(showchartlabels , if lag2l then "26"   else if lag2s then "26"   else "", if lag2l  then CreateColor(63, 187, 93) else if lag2s  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels , if lag3l then "52"   else if lag3s then "52"   else "", if lag3l  then CreateColor(63, 187, 93) else if lag3s  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels , if lag4l then "78"   else if lag4s then "78"   else "", if lag4l  then CreateColor(63, 187, 93) else if lag4s  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(Spacer, "        ", Color.DARK_GRAY);
#AddLabel(showchartlabels, if FutureBullishCloudA then "A" else if FutureBearishCloudA then "A" else "", if FutureBullishCloudA then CreateColor(63, 187, 93) else if FutureBearishCloudA then CreateColor(191, 42, 42) else Color.DARK_GRAY);


AddLabel(showchartlabels, if FutureBullishCloudB then "B" else if FutureBearishCloudB then "B" else "", if FutureBullishCloudB then CreateColor(63, 187, 93) else if FutureBearishCloudB then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels, if FutureBullishCloudC then "C" else if FutureBearishCloudC then "C" else "", if FutureBullishCloudC then CreateColor(63, 187, 93) else if FutureBearishCloudC then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels, if FutureBullishCloudD then "D" else if FutureBearishCloudD then "D" else "", if FutureBullishCloudD then CreateColor(63, 187, 93) else if FutureBearishCloudD then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels, if FutureBullishCloudE then "E" else if FutureBearishCloudE then "E" else "", if FutureBullishCloudE then CreateColor(63, 187, 93) else if FutureBearishCloudE then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(Spacer, "        ", Color.DARK_GRAY);

#AddLabel(showchartlabels , if DragonL then "DFL"   else if DragonS then "DFS"   else "", if DragonL  then CreateColor(63, 187, 93) else if DragonS  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(showchartlabels, if Long then "TKL" else if Short then "TKS"  else "", if Long  then CreateColor(63, 187, 93) else if Short  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(showchartlabels, if PullBack_Long then "PB_L" else if PullBack_Short then "PB_S"  else "", if PullBack_Long  then CreateColor(63, 187, 93) else if PullBack_Short  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showchartlabels , if Kumo5CrossUp then "** B5 **"   else if Kumo5CrossDown then "** B5 **"   else "", if Kumo5CrossUp  then CreateColor(63, 187, 93) else if Kumo5CrossDown then CreateColor(191, 42, 42) else Color.DARK_GRAY);

plot aaa = if showpriceline then close else dn;
aaa.setdefaultColor(color.GRAY);


There are many options and settings to view the information in various ways, you'll have to see what works for you, I will add my tips later

Maybe you'll find this useful and I do have more info to share add later

Thank you, :)

Edit: Additional info

One thing I like to do is use a blank chart and enable the lagging lines/clouds on the Lagging Histogram Code.
What I'm looking for is Support/Resistance and something that STICKS OUT

aFYlw2n.png


mOEIdl2.png
oCeeg7V.png


p9p01OV.png


Trend Analysis WL column
eusrbzn.png


Code:
# TK Dragon 9-26-2022
input DN = Double.NaN;
input price = close;


input T2 = 3;
input T4 = 4.5;
input T9 = 9;
input T18 = 18;
input T27 = 27;
input K6 = 8.66;
input K13 = 13;
input K26 = 26;
input K52 = 52;
input K78 = 78;



########################################################
      #        Tenkan_Kijun         #
##################################################

def Tenkan2 = (Highest(high, T2) + Lowest(low, T2)) / 2  ;
def Kijun6 = (Highest(high, K6) + Lowest(low, K6)) / 2;
def A1 = (Tenkan2[K6] + Kijun6[K6]) / 2;
def B1 = (Highest(high[K6], 2 * K6) + Lowest(low[K6], 2 * K6)) / 2;

def Tenkan4 = (Highest(high, T4) + Lowest(low, T4)) / 2  ;
def Kijun13 = (Highest(high, K13) + Lowest(low, K13)) / 2;
def A2 = (Tenkan4[K13] + Kijun13[K13]) / 2;
def B2 = (Highest(high[K13], 2 * K13) + Lowest(low[K13], 2 * K13)) / 2;
#plot Chikou = close[-K13];

def Tenkan9 = (Highest(high, T9) + Lowest(low, T9)) / 2  ;
def Kijun26 = (Highest(high, K26) + Lowest(low, K26)) / 2;
def A3 = (Tenkan9[K26] + Kijun26[K26]) / 2;
def B3 = (Highest(high[K26], 2 * K26) + Lowest(low[K26], 2 * K26)) / 2;

def Tenkan18 = (Highest(high, T18) + Lowest(low, T18)) / 2;
def Kijun52 = (Highest(high, K52) + Lowest(low, K52)) / 2;
def A4 = (Tenkan18[K52] + Kijun52[K52]) / 2;
def B4 = (Highest(high[K52], 2 * K52) + Lowest(low[K52], 2 * K52)) / 2;

def Tenkan27 = (Highest(high, T27) + Lowest(low, T27)) / 2;
def Kijun78 = (Highest(high, K78) + Lowest(low, K78)) / 2;
def A5 = (Tenkan27[K78] + Kijun78[K78]) / 2;
def B5 = (Highest(high[K78], 2 * K78) + Lowest(low[K78], 2 * K78)) / 2;

#####################################################
  #             CHIKOU                           #
#######################################################

def Chikou6 = close[-K6]  ;
def Chikou13 = close[-K13]  ;
def Chikou26 =  close[-K26]  ;
def Chikou52 =  close[-K52]  ;
def Chikou78 =  close[-K78]  ;

def cloud1StatusAB = A1 > B1;
def cloud1StatusBA = A1 < B1;
def closePriceLongCloud1 = cloud1statusAB and close > A1 or cloud1StatusBA and close > B1;
def closePriceShortCloud1 = cloud1StatusAB and close < B1 or cloud1StatusBA and close < A1;
#def LagLong1 = cloud1StatusAB and chikou > A1 or cloud1statusBA and chikou > B1;

def cloud2StatusAB = A2 > B2;
def cloud2StatusBA = A2 < B2;
def closePriceLongCloud2 = cloud2statusAB and close > A2 or cloud2StatusBA and close > B2;
def closePriceShortCloud2 = cloud2StatusAB and close < B2 or cloud2StatusBA and close < A2;

def cloud3StatusAB = A3 > B3;
def cloud3StatusBA = A3 < B3;
def closePriceLongCloud3 = cloud3statusAB and close > A3 or cloud3StatusBA and close > B3;
def closePriceShortCloud3 = cloud3StatusAB and close < B3 or cloud3StatusBA and close < A3;

def cloud4StatusAB = A4 > B4;
def cloud4StatusBA = A4 < B4;
def closePriceLongCloud4 = cloud4statusAB and close > A4 or cloud4StatusBA and close > B4;
def closePriceShortCloud4 = cloud4StatusAB and close < B4 or cloud4StatusBA and close < A4;

def cloud5StatusAB = A5 > B5;
def cloud5StatusBA = A5 < B5;
def closePriceLongCloud5 = cloud5statusAB and close > A5 or cloud5StatusBA and close > B5;
def closePriceShortCloud5 = cloud5StatusAB and close < B5 or cloud5StatusBA and close < A5;


########################################################
       #             Longs        #
##################################################
def T2B1KumoLong = Tenkan2 > B1;
def T4B2KumoLong = Tenkan4 > B2;
def TKL4_13 = Tenkan4 > Kijun13;  #***
def TKL9_26 = Tenkan9 > Kijun26 and close > Kijun26;
def TKL4_52 = Tenkan4 > Kijun52;
def CloseK13Long = close > Kijun13;
def CloseK52Long = close > Kijun52;  #***
def CloseK78Long = close > Kijun78;

def FutureBullishCloudA = A1[-8.66] > B1[-8.66];
def FutureBullishCloudB = A2[-13] > B2[-13];
def FutureBullishCloudC = A3[-26] > B3[-26];
def FutureBullishCloudD = A4[-52] > B4[-52];
def FutureBullishCloudE = A5[-78] > B5[-78];
def Lag1L = Chikou13[13] > chikou6[13];
def Lag2L = Chikou26[26] > chikou13[26];
def Lag3L = Chikou52[52] > chikou26[52];
def Lag4L = Chikou78[78] > chikou52[78];




########################################################
      #           Shorts        #
##################################################
def T2B1KumoShort = Tenkan2 < B1;
def T4B2KumoShort = Tenkan4 < B2;
def TKS4_13 = Tenkan4 < Kijun13;  #***
def TKS4_52 = Tenkan4 < Kijun52;
def TKS9_26 = Tenkan9 < Kijun26 and close < Kijun26;
def CloseK13Short = close < Kijun13;
def CloseK52Short = close < Kijun52; #***
def CloseK78Short = close < Kijun78;

def FutureBearishCloudA = A1[-8.66] < B1[-8.66];
def FutureBearishCloudB = A2[-13] < B2[-13];
def FutureBearishCloudC = A3[-26] < B3[-26];
def FutureBearishCloudD = A4[-52] < B4[-52];
def FutureBearishCloudE = A5[-78] < B5[-78];
def Lag1S = Chikou13[13] < chikou6[13];
def Lag2S = Chikou26[26] < chikou13[26];
def Lag3S = Chikou52[52] < chikou26[52];
def Lag4S = Chikou78[78] < chikou52[78];


# Total Momentum

#def AgreeTotalL = T2B1KumoLong + T4B2KumoLong + Entry_ExitL + TKL4_13 + TKL9_26 + TKL4_52 + CloseK13Long + CloseK52Long + CloseK78Long + FutureBullishCloudA + FutureBullishCloudB + FutureBullishCloudC + FutureBullishCloudD + Lag1L + Lag2L + Lag3L + Lag4L + ClosePriceLongCloud1 + closePriceLongCloud2 + closePriceLongCloud3 + closePriceLongCloud4 + ClosePriceLongCloud5;

#def AgreeTotalS = T2B1KumoShort + T4B2KumoShort + Entry_ExitS + TKS4_13 + TKS9_26 + TKS4_52 + CloseK13Short + CloseK52Short + CloseK78Short + FutureBearishCloudA + FutureBearishCloudB + FutureBearishCloudC + FutureBearishCloudD + Lag1S + Lag2S + Lag3S + Lag4S + closePriceShortCloud1 + closePriceShortCloud2 + closePriceShortCloud3 + closePriceShortCloud4 + closePriceShortCloud5;

def AgreeTotalL = T2B1KumoLong + T4B2KumoLong + TKL4_13 + TKL9_26 + TKL4_52 + CloseK13Long + CloseK52Long + CloseK78Long + FutureBullishCloudA + FutureBullishCloudB + FutureBullishCloudC + FutureBullishCloudD + FutureBullishCloudE + Lag2L + Lag3L + Lag4L + ClosePriceLongCloud1 + closePriceLongCloud2 + closePriceLongCloud3 + closePriceLongCloud4 + ClosePriceLongCloud5;

def AgreeTotalS = T2B1KumoShort + T4B2KumoShort + TKS4_13 + TKS9_26 + TKS4_52 + CloseK13Short + CloseK52Short + CloseK78Short + FutureBearishCloudA + FutureBearishCloudB + FutureBearishCloudC + FutureBearishCloudD + FutureBearishCloudE + Lag2S + Lag3S + Lag4S + closePriceShortCloud1 + closePriceShortCloud2 + closePriceShortCloud3 + closePriceShortCloud4 + closePriceShortCloud5;


def ConTotal = AgreeTotalL - AgreeTotalS;

def MomTotalUp = ConTotal[1] < ConTotal;
def MomTotalDown = ConTotal[1] > ConTotal;







AddLabel(yes, if MomTotalUp then "(I) " + Round(ConTotal, 1)  else if MomTotalDown then  "(D) " + Round(ConTotal, 1)  else "" + Round(ConTotal, 1), if MomTotalDown then CreateColor(191, 42, 42) else if MomTotalUp then CreateColor(63, 187, 93) else Color.GRAY);

Combined Dragon Future, Lagging WL --

LgHqJoh.png


Code:
# TK Dragon 9-26-2022
input DN = Double.NaN;
input price = close;


input T2 = 3;
input T4 = 4.5;
input T9 = 9;
input T18 = 18;
input T27 = 27;
input K6 = 8.66;
input K13 = 13;
input K26 = 26;
input K52 = 52;
input K78 = 78;



########################################################
      #        Tenkan_Kijun         #
##################################################
def Tenkan2 = (Highest(high, T2) + Lowest(low, T2)) / 2  ;   
def Kijun6 = (Highest(high, K6) + Lowest(low, K6)) / 2;
def A1 = (Tenkan2[K6] + Kijun6[K6]) / 2;
def B1 = (Highest(high[K6], 2 * K6) + Lowest(low[K6], 2 * K6)) / 2;

def Tenkan4 = (Highest(high, T4) + Lowest(low, T4)) / 2  ;
def Kijun13 = (Highest(high, K13) + Lowest(low, K13)) / 2;
def A2 = (Tenkan4[K13] + Kijun13[K13]) / 2;
def B2 = (Highest(high[K13], 2 * K13) + Lowest(low[K13], 2 * K13)) / 2;
#plot Chikou = close[-K13];

def Tenkan9 = (Highest(high, T9) + Lowest(low, T9)) / 2  ;
def Kijun26 = (Highest(high, K26) + Lowest(low, K26)) / 2;
def A3 = (Tenkan9[K26] + Kijun26[K26]) / 2;
def B3 = (Highest(high[K26], 2 * K26) + Lowest(low[K26], 2 * K26)) / 2;

def Tenkan18 = (Highest(high, T18) + Lowest(low, T18)) / 2;
def Kijun52 = (Highest(high, K52) + Lowest(low, K52)) / 2;
def A4 = (Tenkan18[K52] + Kijun52[K52]) / 2;
def B4 = (Highest(high[K52], 2 * K52) + Lowest(low[K52], 2 * K52)) / 2;

def Tenkan27 = (Highest(high, T27) + Lowest(low, T27)) / 2;
def Kijun78 = (Highest(high, K78) + Lowest(low, K78)) / 2;
def A5 = (Tenkan27[K78] + Kijun78[K78]) / 2;
def B5 = (Highest(high[K78], 2 * K78) + Lowest(low[K78], 2 * K78)) / 2;


#def Chikou = close[-k26];
def Chikou6 = close[-k6];
def Chikou13 = close[-k13];
def Chikou26 = close[-k26];
def Chikou52 = close[-k52];
def Chikou78 = close[-k78];
########################################################
      #          TK Plots         #
##################################################

def Lag1L = Chikou13[13] > chikou6[13];
def Lag2L = Chikou26[26] > chikou13[26];
def Lag3L = Chikou52[52] > chikou26[52];
def Lag4L = Chikou78[78] > chikou52[78];

def Lag1S = Chikou13[13] < chikou6[13];
def Lag2S = Chikou26[26] < chikou13[26];
def Lag3S = Chikou52[52] < chikou26[52];
def Lag4S = Chikou78[78] < chikou52[78];

########################################################
#             Chart level Dragon        #
##################################################
#def FutureBullishCloudA = A1[-8.66] > B1[-8.66];
#def FutureBearishCloudA = A1[-8.66] < B1[-8.66];

def FutureBullishCloudB = A2[-13] > B2[-13];
def FutureBearishCloudB = A2[-13] < B2[-13];

def FutureBullishCloudC = A3[-26] > B3[-26];
def FutureBearishCloudC = A3[-26] < B3[-26];

def FutureBullishCloudD = A4[-52] > B4[-52];
def FutureBearishCloudD = A4[-52] < B4[-52];

def FutureBullishCloudE = A5[-78] > B5[-78];
def FutureBearishCloudE = A5[-78] < B5[-78];

########################################################
       #             Longs        #
##################################################
def DragonL = futureBullishCloudB and futureBullishCloudC and futureBullishCloudD and futureBullishCloudE;
#def T2B1KumoLong = Tenkan2 > B1;
#def T4B2KumoLong = Tenkan4 > B2;
#def TKL4_13 = Tenkan4 > Kijun13;  #***
#def TKL4_52 = Tenkan4 > Kijun52;
#def TKL9_26 = Tenkan9 > Kijun26;
#def CloseK52Long = close > Kijun52;  #***
#def CloseK78Long = close > Kijun78; #***

########################################################
      #           Shorts        #
##################################################
def DragonS =  futureBearishCloudB and futureBearishCloudC and futureBearishCloudD and futureBearishCloudE;
#def T2B1KumoShort = Tenkan2 < B1;
#def T4B2KumoShort = Tenkan4 < B2;
#def TKS4_13 = Tenkan4 < Kijun13;  #***
#def TKS4_52 = Tenkan4 < Kijun52;
#def TKS9_26 = Tenkan9 < Kijun26;
#def CloseK52Short = close < Kijun52; #***
#def CloseK78Short = close < Kijun78; #***

#def Cross52Up = close crosses above Kijun52 within 4 bars;
#def Cross52Dn = close crosses below Kijun52 within 4 bars;

#################################################################
def LAGL = lag2l and lag3l and lag4l;
def LAGS =  lag2s and lag3s and lag4s;
####### HOUR ##############3
def NoLagLPrev = LAGL and !LAGL[1] and !LAGL[2] and !LAGL[3] and !LAGL[4] and !LAGL[5];
def NoLagsPrev = LAGS and !LAGS[1] and !LAGS[2] and !LAGS[3] and !LAGS[4] and !LAGS[5];
########################################################
      #          Trigger long         #
##################################################
#def TKL = chikouL and T2B1KumoLong and T4B2KumoLong and TKL4_13 and TKL4_52 and TKL9_26 and CloseK52Long and closeK78Long and futureBullishCloudA and futureBullishCloudB;

#def PullBack_Long = TKS4_52 and TKL4_13 and CloseK52Short and futureBullishCloudA and futureBullishCloudB;

########################################################
      #         Trigger Short         #
##################################################
#def TKS = ChikouS and T2B1KumoShort and T4B2KumoShort and TKS4_13 and TKS4_52 and TKS9_26 and CloseK52Short and closeK78Short and futureBearishCloudA and futureBearishCloudB;

########################################################
      #          Pullback_Short         #
##################################################
#def PullBack_Short = TKL4_52 and TKS4_13 and CloseK52Long and futureBearishCloudA and futureBearishCloudB;


# ============================================================================

#def TKL = EntryL and TKL4_13 and TKL4_52 and CloseK52Long and futureBullishCloudA and futureBullishCloudB;

#def PullBack_Long = TKS4_52 and TKL4_13 and CloseK52Short and futureBullishCloudA;

#def NewTKL = TKL and !TKL[1];

# =====================================================================================
#def TKS = EntryS and TKS4_13 and TKS4_52 and CloseK52Short and futureBearishCloudA and futureBearishCloudB;

#def PullBack_Short = TKL4_52 and TKS4_13 and CloseK52Long and futureBearishCloudA;

#def NewTKS = TKS and !TKS[1];


#  ======================= LABELS ===============================================================
addlabel(yes, if LagL and DragonL then "L" else if LagS and dragonS then "S" else "_", if LagL and dragonL then color.VIOLET  else if LagS and dragonS then color.DARK_ORANGE else color.BLACK );

#addlabel(yes, if NoLagLPrev then "!NL" else if LagL then "L" else if NoLagsPrev then "!NS" else if LagS then "S" else "_", if NoLagLPrev then createColor(63,187,93) else if LagL then color.VIOLET  else if NoLagsPrev then createColor(191,42,42) else if LagS then color.DARK_ORANGE else color.BLACK );
 
#AddLabel(yes, if MomTotalUp then "(I) " + Round(ConTotal, 1)  else if MomTotalDown then  "(D) " + Round(ConTotal, 1)  else "" + Round(ConTotal, 1), if MomTotalDown then CreateColor(191,42,42) else if MomTotalUp then CreateColor(63,187,93) else Color.GRAY);


# ================== colors ===========
# new long -- createColor(33,145,72)
# long -- createColor(18,97,62)
# new short -- createColor(191,42,42)
# short -- createColor(119,26,26)
# up CreateColor(63,187,93)
# down CreateColor(191,42,42)


Edit - if using the dragon clouds be sure to set your chart to 78 bars extension

Here is The MTF version with Trend Analysis - Not everything has been coded as MTF as of yet..i.e displaying clouds and some other stuff

Code:
# Dragon MTF 10-23-2022 By HypnoticOptions
# MTF Consensus
input Time1 = {"5 min", "10 min", "20 min", "1 Hour", "2 Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
input Time2 = {"5 min", "10 min", "20 min", "1 Hour", "2 Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
#============TIME=========================

def Agg1;

switch (Time1) {
case "5 min":
    Agg1 = AggregationPeriod.FIVE_MIN;
case "10 min":
    Agg1 = AggregationPeriod.TEN_MIN;
case "20 min":
    Agg1 = AggregationPeriod.TWENTY_MIN;
case "1 Hour":
    Agg1 = AggregationPeriod.HOUR;
case "2 Hour":
    Agg1 = AggregationPeriod.TWO_HOURS;
case "4 Hour":
    Agg1 = AggregationPeriod.FOUR_HOURS;
case "Daily":
    Agg1 = AggregationPeriod.DAY;
case "Weekly":
    Agg1 = AggregationPeriod.WEEK;
case "Monthly":
    Agg1 = AggregationPeriod.MONTH;
}
input Q = {_____, ____, default ______};

def Agg2;

switch (Time2) {
case "5 min":
    Agg2 = AggregationPeriod.FIVE_MIN;
case "10 min":
    Agg2 = AggregationPeriod.TEN_MIN;
case "20 min":
    Agg2 = AggregationPeriod.TWENTY_MIN;
case "1 Hour":
    Agg2 = AggregationPeriod.HOUR;
case "2 Hour":
    Agg2 = AggregationPeriod.TWO_HOURS;
case "4 Hour":
    Agg2 = AggregationPeriod.FOUR_HOURS;
case "Daily":
    Agg2 = AggregationPeriod.DAY;
case "Weekly":
    Agg2 = AggregationPeriod.WEEK;
case "Monthly":
    Agg2 = AggregationPeriod.MONTH;
}


#==============END TIME==================

#=============================================
input DN = Double.NaN;
input price = close;
input PlotCloudA_B = no;
input showT2_K6 = no;
input showT2agg1 = no;
input showT2agg2 = no;
input showT4 = no;
input showT4agg1 = no;
input showT4agg2 = no;
input showk13 = no;
input showk13agg1 = no;
input showk13agg2 = no;
input showT18 = no;
input showT18agg1 = no;
input showT18agg2 = no;
input showK6 = no;
input showK6agg1 = no;
input showK6agg2 = no;
input showK52 = no;
input showK52agg1 = no;
input showK52agg2 = no;

# ========================
input showcloud1KUMO = no;  #HINT showcloud1KUMO: show Tenkan2, Kijun6 Kumo
input showcloud2KUMO = no;  #HINT showcloud2KUMO: show Tenkan4, Kijun13 Kumo
input showcloud3KUMO = no;    #HINT showcloud3KUMO: show Tenkan9, Kijun26 Kumo
input showcloud4KUMO = no;     #HINT showcloud4KUMO: show Tenkan18, Kijun52 Kumo
input showcloud5KUMO = no;     #HINT showcloud5KUMO: show Tenkan27, Kijun78 Kumo
input ShowAllDragonClouds = no;
input ShowCloud1_KUMOLines = no;
input ShowCloud2_KUMOLines = no;
input ShowCloud3_KUMOLines = no;
input ShowCloud4_KUMOLines = no;
input ShowCloud5_KUMOLines = no;
input plotCloud1 = no;
input plotcloud2 = no;
input ShowLagging = no;
input ShowPastKijunClouds = no;
input T2 = 3;
input T4 = 4.5;
input T9 = 9;
input T18 = 18;
input T27 = 27;
input K6 = 8;
input K13 = 13;
input K26 = 26;
input K52 = 52;
input K78 = 78;
input specificLength = 100;
def bn = BarNumber();
input showBalloons1 = {Left,  Right, default Off};
input showBalloons2 = {Left,  Right, default Off};
input showBalloons_K52 = {Left,  Right, default Off};
input showBalloons4 = {Left,  Right, default Off};
input UseTime1 = yes;
input UseTime2 = yes;
input showChartlabels = yes;
input showagg1labels = yes;
input showagg2labels = yes;
input Spacer = yes;


#def sbT4_K13 = (showBalloons1 == showBalloons1."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons1 == showBalloons1."Right" and IsNaN(close[-1]) and !IsNaN(close));

#def sbT9_K26 = (showBalloons2 == showBalloons2."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons2 == showBalloons2."Right" and IsNaN(close[-1]) and !IsNaN(close));

def sbT18_K52 = (showBalloons_K52 == showBalloons_K52."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons_K52 == showBalloons_K52."Right" and IsNaN(close[-1]) and !IsNaN(close));

#def sbT27_K78 = (showBalloons4 == showBalloons4."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons4 == showBalloons4."Right" and IsNaN(close[-1]) and !IsNaN(close));
# ==================== Tenkan KiJun ===============================================


def Tenkan2 = (Highest(high, T2) + Lowest(low, T2)) / 2  ;
def Kijun6 = (Highest(high, K6) + Lowest(low, K6)) / 2;
def A1 = (Tenkan2[K6] + Kijun6[K6]) / 2;
def B1 = (Highest(high[K6], 2 * K6) + Lowest(low[K6], 2 * K6)) / 2;

def Tenkan4 = (Highest(high, T4) + Lowest(low, T4)) / 2  ;
def Kijun13 = (Highest(high, K13) + Lowest(low, K13)) / 2;
def A2 = (Tenkan4[K13] + Kijun13[K13]) / 2;
def B2 = (Highest(high[K13], 2 * K13) + Lowest(low[K13], 2 * K13)) / 2;

def Tenkan9 = (Highest(high, T9) + Lowest(low, T9)) / 2  ;
def Kijun26 = (Highest(high, K26) + Lowest(low, K26)) / 2;
def A3 = (Tenkan9[K26] + Kijun26[K26]) / 2;
def B3 = (Highest(high[K26], 2 * K26) + Lowest(low[K26], 2 * K26)) / 2;

def Tenkan18 = (Highest(high, T18) + Lowest(low, T18)) / 2;
def Kijun52 = (Highest(high, K52) + Lowest(low, K52)) / 2;
def A4 = (Tenkan18[K52] + Kijun52[K52]) / 2;
def B4 = (Highest(high[K52], 2 * K52) + Lowest(low[K52], 2 * K52)) / 2;

def Tenkan27 = (Highest(high, T27) + Lowest(low, T27)) / 2;
def Kijun78 = (Highest(high, K78) + Lowest(low, K78)) / 2;
def A5 = (Tenkan27[K78] + Kijun78[K78]) / 2;
def B5 = (Highest(high[K78], 2 * K78) + Lowest(low[K78], 2 * K78)) / 2;

def Tenkan2agg1 = (Highest(high(period = Agg1), T2) + Lowest(low(period = Agg1), T2)) / 2  ;
def Kijun6agg1 = (Highest(high(period = Agg1), K6) + Lowest(low(period = Agg1), K6)) / 2;
def A1agg1 = (Tenkan2agg1[K6] + Kijun6agg1[K6]) / 2;
def B1agg1 = (Highest(high(period = Agg1)[K6], 2 * K6) + Lowest(low(period = Agg1)[K6], 2 * K6)) / 2;

def Tenkan4agg1 = (Highest(high(period = Agg1), T4) + Lowest(low(period = Agg1), T4)) / 2  ;
def Kijun13agg1 = (Highest(high(period = Agg1), K13) + Lowest(low(period = Agg1), K13)) / 2;
def A2agg1 = (Tenkan4agg1[K13] + Kijun13agg1[K13]) / 2;
def B2agg1 = (Highest(high(period = Agg1)[K13], 2 * K13) + Lowest(low(period = Agg1)[K13], 2 * K13)) / 2;

def Tenkan9agg1 = (Highest(high(period = Agg1), T9) + Lowest(low(period = Agg1), T9)) / 2  ;
def Kijun26agg1 = (Highest(high(period = Agg1), K26) + Lowest(low(period = Agg1), K26)) / 2;
def A3agg1 = (Tenkan9agg1[K26] + Kijun26agg1[K26]) / 2;
def B3agg1 = (Highest(high(period = Agg1)[K26], 2 * K26) + Lowest(low(period = Agg1)[K26], 2 * K26)) / 2;

def Tenkan18agg1 = (Highest(high(period = Agg1), T18) + Lowest(low(period = Agg1), T18)) / 2;
def Kijun52agg1 = (Highest(high(period = Agg1), K52) + Lowest(low(period = Agg1), K52)) / 2;
def A4agg1 = (Tenkan18agg1[K52] + Kijun52agg1[K52]) / 2;
def B4agg1 = (Highest(high(period = Agg1)[K52], 2 * K52) + Lowest(low(period = Agg1)[K52], 2 * K52)) / 2;

def Tenkan27agg1 = (Highest(high(period = Agg1), T27) + Lowest(low(period = Agg1), T27)) / 2;
def Kijun78agg1 = (Highest(high(period = Agg1), K78) + Lowest(low(period = Agg1), K78)) / 2;
def A5agg1 = (Tenkan27agg1[K78] + Kijun78agg1[K78]) / 2;
def B5agg1 = (Highest(high(period = Agg1)[K78], 2 * K78) + Lowest(low(period = Agg1)[K78], 2 * K78)) / 2;

def Tenkan2agg2 = (Highest(high(period = Agg2), T2) + Lowest(low(period = Agg2), T2)) / 2  ;
def Kijun6agg2 = (Highest(high(period = Agg2), K6) + Lowest(low(period = Agg2), K6)) / 2;
def A1agg2 = (Tenkan2agg2[K6] + Kijun6agg2[K6]) / 2;
def B1agg2 = (Highest(high(period = Agg2)[K6], 2 * K6) + Lowest(low(period = Agg2)[K6], 2 * K6)) / 2;

def Tenkan4agg2 = (Highest(high(period = Agg2), T4) + Lowest(low(period = Agg2), T4)) / 2  ;
def Kijun13agg2 = (Highest(high(period = Agg2), K13) + Lowest(low(period = Agg2), K13)) / 2;
def A2agg2 = (Tenkan4agg2[K13] + Kijun13agg2[K13]) / 2;
def B2agg2 = (Highest(high(period = Agg2)[K13], 2 * K13) + Lowest(low(period = Agg2)[K13], 2 * K13)) / 2;

def Tenkan9agg2 = (Highest(high(period = Agg2), T9) + Lowest(low(period = Agg2), T9)) / 2  ;
def Kijun26agg2 = (Highest(high(period = Agg2), K26) + Lowest(low(period = Agg2), K26)) / 2;
def A3agg2 = (Tenkan9agg2[K26] + Kijun26agg2[K26]) / 2;
def B3agg2 = (Highest(high(period = Agg2)[K26], 2 * K26) + Lowest(low(period = Agg2)[K26], 2 * K26)) / 2;

def Tenkan18agg2 = (Highest(high(period = Agg2), T18) + Lowest(low(period = Agg2), T18)) / 2;
def Kijun52agg2 = (Highest(high(period = Agg2), K52) + Lowest(low(period = Agg2), K52)) / 2;
def A4agg2 = (Tenkan18agg2[K52] + Kijun52agg2[K52]) / 2;
def B4agg2 = (Highest(high(period = Agg2)[K52], 2 * K52) + Lowest(low(period = Agg2)[K52], 2 * K52)) / 2;

def Tenkan27agg2 = (Highest(high(period = Agg2), T27) + Lowest(low(period = Agg2), T27)) / 2;
def Kijun78agg2 = (Highest(high(period = Agg2), K78) + Lowest(low(period = Agg2), K78)) / 2;
def A5agg2 = (Tenkan27agg2[K78] + Kijun78agg2[K78]) / 2;
def B5agg2 = (Highest(high(period = Agg2)[K78], 2 * K78) + Lowest(low(period = Agg2)[K78], 2 * K78)) / 2;

# ============ cloud plots ===============

plot Cloud1a_1 = if plotCloud1 then A1 else Double.NaN;
Cloud1a_1.SetDefaultColor(CreateColor(136, 213, 94));
Cloud1a_1.SetLineWeight(1);
Cloud1a_1.SetStyle(Curve.LONG_DASH);

plot Cloud1B_1 = if plotCloud1 then B1 else Double.NaN;
Cloud1B_1.SetDefaultColor(CreateColor(229, 49, 5));
Cloud1B_1.SetLineWeight(1);
Cloud1B_1.SetStyle(Curve.LONG_DASH);

plot Cloud1a_2 = if plotcloud2 then A2 else Double.NaN;
Cloud1a_2.SetDefaultColor(CreateColor(136, 213, 94));
Cloud1a_2.SetLineWeight(1);
Cloud1a_2.SetStyle(Curve.LONG_DASH);

plot Cloud1B_2 = if plotcloud2 then B2 else Double.NaN;
Cloud1B_2.SetDefaultColor(CreateColor(229, 49, 5));
Cloud1B_2.SetLineWeight(1);
Cloud1B_2.SetStyle(Curve.LONG_DASH);


##################################################################
#                   Dragon Cloud Plots                          #
##################################################################
AddCloud(if showCloud1KUMO or ShowAllDragonClouds then A1 else Double.NaN, if showCloud1KUMO or ShowAllDragonClouds then B1 else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

plot Cloud1a = if  ShowCloud1_KUMOLines then A1 else Double.NaN;
Cloud1a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud1a.SetLineWeight(1);
Cloud1a.SetStyle(Curve.LONG_DASH);

plot Cloud1B = if  ShowCloud1_KUMOLines then B1 else Double.NaN;
Cloud1B.SetDefaultColor(CreateColor(229, 49, 5));
Cloud1B.SetLineWeight(1);
Cloud1B.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud2KUMO or ShowAllDragonClouds then A2 else Double.NaN, if showcloud2KUMO or ShowAllDragonClouds then B2 else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

plot Cloud2a = if  ShowCloud2_KUMOLines then A2 else Double.NaN;
Cloud2a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud2a.SetLineWeight(1);
Cloud2a.SetStyle(Curve.LONG_DASH);

plot Cloud2b = if  ShowCloud2_KUMOLines then B2 else Double.NaN;
Cloud2b.SetDefaultColor(CreateColor(229, 49, 5));
Cloud2b.SetLineWeight(1);
Cloud2b.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud3KUMO or ShowAllDragonClouds then A3 else Double.NaN, if showcloud3KUMO or ShowAllDragonClouds then B3 else Double.NaN, CreateColor(73, 196, 128), CreateColor(110, 89, 84));

AddCloud(if showcloud4KUMO or ShowAllDragonClouds then A4 else Double.NaN, if showcloud4KUMO or ShowAllDragonClouds then B4 else Double.NaN, CreateColor(36, 149, 87), CreateColor(64, 55, 52));

AddCloud(if showcloud5KUMO or ShowAllDragonClouds then A5 else Double.NaN, if showcloud5KUMO or ShowAllDragonClouds then B5 else Double.NaN, CreateColor(6, 78, 38), CreateColor(3, 3, 3));

# ============================================================================
# ====================== CHIKOU ============================================
def Chikou6 = close[-K6]  ;
def Chikou13 = close[-K13]  ;
def Chikou26 =  close[-K26]  ;
def Chikou52 =  close[-K52]  ;
def Chikou78 =  close[-K78]  ;

plot Chikou6p = if ShowLagging then close[-K6] else Double.NaN;
plot Chikou13p = if ShowLagging then close[-K13] else Double.NaN;
plot Chikou26p = if ShowLagging then close[-K26] else Double.NaN;
plot Chikou52p = if ShowLagging then close[-K52] else Double.NaN;
plot Chikou78p = if ShowLagging then close[-K78] else Double.NaN;

###########
# AGG1  #
###########

def Chikou6AGG1 = close(period = Agg1)[-K6]  ;
def Chikou13AGG1 = close(period = Agg1)[-K13]  ;
def Chikou26AGG1 =  close(period = Agg1)[-K26]  ;
def Chikou52AGG1 =  close(period = Agg1)[-K52]  ;
def Chikou78AGG1 =  close(period = Agg1)[-K78]  ;

###########
# AGG2  #
###########

def Chikou6AGG2 = close(period = Agg2)[-K6]  ;
def Chikou13AGG2 = close(period = Agg2)[-K13]  ;
def Chikou26AGG2 =  close(period = Agg2)[-K26]  ;
def Chikou52AGG2 =  close(period = Agg2)[-K52]  ;
def Chikou78AGG2 =  close(period = Agg2)[-K78]  ;


#######################################################################
#                        Past Kijun Clouds                          #
#########################################################################
AddCloud(if ShowPastKijunClouds then Chikou13p else Double.NaN, if ShowPastKijunClouds then Chikou6p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));
AddCloud(if ShowPastKijunClouds then Chikou26p else Double.NaN, if ShowPastKijunClouds then Chikou13p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));
AddCloud(if ShowPastKijunClouds then Chikou52p else Double.NaN, if ShowPastKijunClouds then Chikou26p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));
AddCloud(if ShowPastKijunClouds then Chikou78p else Double.NaN, if ShowPastKijunClouds then Chikou52p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

# ============================================================================
# ================== TK PLOTS =========================================
plot T = if showT4 then Tenkan4 else Double.NaN;
plot k = if showk13 then Kijun13 else Double.NaN;
T.SetDefaultColor(CreateColor(75, 235, 175));
T.SetLineWeight(1);
T.SetStyle(Curve.FIRM);
k.SetDefaultColor(CreateColor(219, 75, 68));
k.SetLineWeight(1);
k.SetStyle(Curve.FIRM);

plot T1 = if showT2_K6 then Tenkan2 else Double.NaN;
plot k1 = if showT2_K6 then Kijun6 else Double.NaN;
T1.SetDefaultColor(CreateColor(52, 186, 136));
T1.SetLineWeight(1);
T1.SetStyle(Curve.MEDIUM_DASH);
k1.SetDefaultColor(CreateColor(255, 43, 43));
k1.SetLineWeight(1);
k1.SetStyle(Curve.MEDIUM_DASH);

plot T18p = if showT18 then Tenkan18 else Double.NaN;
plot k52p = if showK52 then Kijun52 else Double.NaN;
T18p.SetDefaultColor(CreateColor(99, 211, 146));
T18p.SetLineWeight(2);
T18p.SetStyle(Curve.FIRM);
k52p.SetDefaultColor(CreateColor(248, 41, 41));
k52p.SetLineWeight(2);
k52p.SetStyle(Curve.FIRM);

# ================= AGG1 TK ==========================================
plot TAGG1 = if showT4agg1 then Tenkan4agg1 else Double.NaN;
plot kAGG1 = if showk13agg1 then Kijun13agg1 else Double.NaN;
TAGG1.SetDefaultColor(CreateColor(75, 235, 175));
TAGG1.SetLineWeight(1);
TAGG1.SetStyle(Curve.FIRM);
kAGG1.SetDefaultColor(CreateColor(219, 75, 68));
kAGG1.SetLineWeight(1);
kAGG1.SetStyle(Curve.FIRM);

plot T1AGG1 = if showT2agg1 then Tenkan2agg1 else Double.NaN;
plot k1AGG1 = if showK6agg1 then Kijun6agg1 else Double.NaN;
T1AGG1.SetDefaultColor(CreateColor(52, 186, 136));
T1AGG1.SetLineWeight(1);
T1AGG1.SetStyle(Curve.FIRM);
k1AGG1.SetDefaultColor(CreateColor(255, 43, 43));
k1AGG1.SetLineWeight(2);
k1AGG1.SetStyle(Curve.FIRM);

plot T2agg1 = if showT18agg1 then Tenkan18agg1 else Double.NaN;
plot k2agg1 = if showK52agg1 then Kijun52agg1 else Double.NaN;
T2agg1.SetDefaultColor(CreateColor(99, 211, 146));
T2agg1.SetLineWeight(2);
T2agg1.SetStyle(Curve.LONG_DASH);
k2agg1.SetDefaultColor(CreateColor(194, 30, 30));
k2agg1.SetLineWeight(2);
k2agg1.SetStyle(Curve.LONG_DASH);

# ================= AGG2 TK ==========================================
plot TAGG2 = if showT4agg2 then Tenkan4agg2 else Double.NaN;
plot kAGG2 = if showk13agg2 then Kijun13agg2 else Double.NaN;
TAGG2.SetDefaultColor(CreateColor(75, 235, 175));
TAGG2.SetLineWeight(1);
TAGG2.SetStyle(Curve.FIRM);
kAGG2.SetDefaultColor(CreateColor(219, 75, 68));
kAGG2.SetLineWeight(1);
kAGG2.SetStyle(Curve.FIRM);

plot T1AGG2 = if showT2agg2 then Tenkan2agg2 else Double.NaN;
plot k1AGG2 = if showK6agg2 then Kijun6agg2 else Double.NaN;
T1AGG2.SetDefaultColor(CreateColor(52, 186, 136));
T1AGG2.SetLineWeight(1);
T1AGG2.SetStyle(Curve.FIRM);
k1AGG2.SetDefaultColor(CreateColor(255, 43, 43));
k1AGG2.SetLineWeight(2);
k1AGG2.SetStyle(Curve.FIRM);

plot T2agg2 = if showT18agg2 then Tenkan18agg2 else Double.NaN;
plot k2agg2 = if showK52agg2 then Kijun52agg2 else Double.NaN;
T2agg2.SetDefaultColor(CreateColor(99, 211, 146));
T2agg2.SetLineWeight(2);
T2agg2.SetStyle(Curve.LONG_DASH);
k2agg2.SetDefaultColor(CreateColor(148, 19, 19));
k2agg2.SetLineWeight(3);
k2agg2.SetStyle(Curve.LONG_DASH);
# ============== CLOUDS =====================

#AddCloud( tenkan2, kijun6,    createColor(138,223,206),      createColor(204,30,30));   #*
########################################################
#AddCloud( Tenkan4, Kijun13,     CreateColor(26, 201, 143),      CreateColor(230, 34, 34));  #*
#AddCloud( Tenkan4, Kijun52,     CreateColor(155, 233, 207),      CreateColor(255, 121, 121));  #*
######################################################

#AddCloud( tenkan2, kijun6,    createColor(127,243,212),      createColor(198,175,175));   #*
#AddCloud( tenkan4, kijun13,     CreateColor(169,248,221),      CreateColor(221,65,65));  #*
#AddCloud( tenkan4, kijun52,     CreateColor(57,186,100),      CreateColor(221,65,65));  #*

#AddCloud( A2,  B2,     CreateColor(97, 221, 138),       CreateColor(168, 102, 86));  #Cloud 1
#AddCloud( A3, B3,    CreateColor(73,196,128),      CreateColor(110,89,84));
#AddCloud( A4, B4 ,    CreateColor(36,149,87),      CreateColor(64,55,52));
#AddCloud( A5, B5 ,    CreateColor(6,78,38),      CreateColor(3,3,3));

########################################################
      #          Current cloud1a status & Breaks        #
##################################################
def cloud1StatusAB = A1 > B1;
def cloud1StatusABagg1 = A1agg1 > B1agg1;
def cloud1StatusABagg2 = A1agg2 > B1agg2;

def cloud1StatusBA = A1 < B1;
def cloud1StatusBAagg1 = A1agg1 < B1agg1;
def cloud1StatusBAagg2 = A1agg2 < B1agg2;

def closePriceLongCloud1 = cloud1StatusAB and close > A1 or cloud1StatusBA and close > B1;
def closePriceLongCloud1agg1 = cloud1StatusABagg1 and close(period = agg1) > A1agg1 or cloud1StatusBAagg1 and close(period = agg1) > B1agg1;
def closePriceLongCloud1agg2 = cloud1StatusABagg2 and close(period = agg2) > A1agg2 or cloud1StatusBAagg2 and close(period = agg2) > B1agg2;

def closePriceShortCloud1 = cloud1StatusAB and close < B1 or cloud1StatusBA and close < A1;
def closePriceShortCloud1agg1 = cloud1StatusABagg1 and close(period = agg1) < B1agg1 or cloud1StatusBAagg1 and close(period = agg1) < A1agg1;
def closePriceShortCloud1agg2 = cloud1StatusABagg2 and close(period = agg2) < B1agg2 or cloud1StatusBAagg2 and close(period = agg2) < A1agg2;
###
def cloud2StatusAB = A2 > B2;
def cloud2StatusABagg1 = A2agg1 > B2agg1;
def cloud2StatusABagg2 = A2agg2 > B2agg2;

def cloud2StatusBA = A2 < B2;
def cloud2StatusBAagg1 = A2agg1 < B2agg1;
def cloud2StatusBAagg2 = A2agg2 < B2agg2;

def closePriceLongCloud2 = cloud2StatusAB and close > A2 or cloud2StatusBA and close > B2;
def closePriceLongCloud2agg1 = cloud2StatusABagg1 and close(period = agg1) > A2agg1 or cloud2StatusBAagg1 and close(period = agg1) > B2agg1;
def closePriceLongCloud2agg2 = cloud2StatusABagg2 and close(period = agg2) > A2agg2 or cloud2StatusBAagg2 and close(period = agg2) > B2agg2;

def closePriceShortCloud2 = cloud2StatusAB and close < B2 or cloud2StatusBA and close < A2;
def closePriceShortCloud2agg1 = cloud2StatusABagg1 and close(period = agg1) < B2agg1 or cloud2StatusBAagg1 and close(period = agg1) < A2agg1;
def closePriceShortCloud2agg2 = cloud2StatusABagg2 and close(period = agg2) < B2agg2 or cloud2StatusBAagg2 and close(period = agg2) < A2agg2;
###
def cloud3StatusAB = A3 > B3;
def cloud3StatusABagg1 = A3agg1 > B3agg1;
def cloud3StatusABagg2 = A3agg2 > B3agg2;

def cloud3StatusBA = A3 < B3;
def cloud3StatusBAagg1 = A3agg1 < B3agg1;
def cloud3StatusBAagg2 = A3agg2 < B3agg2;

def closePriceLongCloud3 = cloud3StatusAB and close > A3 or cloud3StatusBA and close > B3;
def closePriceLongCloud3agg1 = cloud3StatusABagg1 and close(period = agg1) > A3agg1 or cloud3StatusBAagg1 and close(period = agg1) > B3agg1;
def closePriceLongCloud3agg2 = cloud3StatusABagg2 and close(period = agg2) > A3agg2 or cloud3StatusBAagg2 and close(period = agg2) > B3agg2;

def closePriceShortCloud3 = cloud3StatusAB and close < B3 or cloud3StatusBA and close < A3;
def closePriceShortCloud3agg1 = cloud3StatusABagg1 and close(period = agg1) < B3agg1 or cloud3StatusBAagg1 and close(period = agg1) < A3agg1;
def closePriceShortCloud3agg2 = cloud3StatusABagg2 and close(period = agg2) < B3agg2 or cloud3StatusBAagg2 and close(period = agg2) < A3agg2;
###
def cloud4StatusAB = A4 > B4;
def cloud4StatusABagg1 = A4agg1 > B4agg1;
def cloud4StatusABagg2 = A4agg2 > B4agg2;

def cloud4StatusBA = A4 < B4;
def cloud4StatusBAagg1 = A4agg1 < B4agg1;
def cloud4StatusBAagg2 = A4agg2 < B4agg2;

def closePriceLongCloud4 = cloud4StatusAB and close > A4 or cloud4StatusBA and close > B4;
def closePriceLongCloud4agg1 = cloud4StatusABagg1 and close(period = agg1) > A4agg1 or cloud4StatusBAagg1 and close(period = agg1) > B4agg1;
def closePriceLongCloud4agg2 = cloud4StatusABagg2 and close(period = agg2) > A4agg2 or cloud4StatusBAagg2 and close(period = agg2) > B4agg2;

def closePriceShortCloud4 = cloud4StatusAB and close < B4 or cloud4StatusBA and close < A4;
def closePriceShortCloud4agg1 = cloud4StatusABagg1 and close(period = agg1) < B4agg1 or cloud4StatusBAagg1 and close(period = agg1) < A4agg1;
def closePriceShortCloud4agg2 = cloud4StatusABagg2 and close(period = agg2) < B4agg2 or cloud4StatusBAagg2 and close(period = agg2) < A4agg2;
###
def cloud5StatusAB = A5 > B5;
def cloud5StatusABagg1 = A5agg1 > B5agg1;
def cloud5StatusABagg2 = A5agg2 > B5agg2;

def cloud5StatusBA = A5 < B5;
def cloud5StatusBAagg1 = A5agg1 < B5agg1;
def cloud5StatusBAagg2 = A5agg2 < B5agg2;

def closePriceLongCloud5 = cloud5StatusAB and close > A5 or cloud5StatusBA and close > B5;
def closePriceLongCloud5agg1 = cloud5StatusABagg1 and close(period = agg1) > A5agg1 or cloud5StatusBAagg1 and close(period = agg1) > B5agg1;
def closePriceLongCloud5agg2 = cloud5StatusABagg1 and close(period = agg2) > A5agg2 or cloud5StatusBAagg2 and close(period = agg2) > B5agg2;

def closePriceShortCloud5 = cloud5StatusAB and close < B5 or cloud5StatusBA and close < A5;
def closePriceShortCloud5agg1 = cloud5StatusABagg1 and close(period = agg1) < B5agg1 or cloud5StatusBAagg1 and close(period = agg1) < A5agg1;
def closePriceShortCloud5agg2 = cloud5StatusABagg2 and close(period = agg2) < B5agg2 or cloud5StatusBAagg2 and close(period = agg2) < A5agg2;

#######################################################
#            TRIGGERS                               #
#######################################################

########################################################
       #             Longs        #
##################################################
def T2B1KumoLong = Tenkan2 > B1;
def T2B1KumoLongagg1 = Tenkan2agg1 > B1agg1;
def T2B1KumoLongagg2 = Tenkan2agg2 > B1agg2;
###
def T4B2KumoLong = Tenkan4 > B2;
def T4B2KumoLongagg1 = Tenkan4agg1 > B2agg1;
def T4B2KumoLongagg2 = Tenkan4agg2 > B2agg2;
###
def TKL4_13 = Tenkan4 > Kijun13;  #***
def TKL4_13agg1 = Tenkan4agg1 > Kijun13agg1;  #***
def TKL4_13agg2 = Tenkan4agg2 > Kijun13agg2;  #***
###
def TKL9_26 = Tenkan9 > Kijun26;
def TKL9_26agg1 = Tenkan9agg1 > Kijun26agg1;
def TKL9_26agg2 = Tenkan9agg2 > Kijun26agg2;
###
def TKL4_52 = Tenkan4 > Kijun52;
def TKL4_52agg1 = Tenkan4agg1 > Kijun52agg1;
def TKL4_52agg2 = Tenkan4agg2 > Kijun52agg2;
###
def CloseK13Long = close > Kijun13;
def CloseK13Longagg1 = close(period = Agg1) > Kijun13agg1;
def CloseK13Longagg2 = close(period = Agg2) > Kijun13agg2;
###
def CloseK52Long = close > Kijun52;  #***
def CloseK52Longagg1 = close(period = Agg1) > Kijun52agg1;  #***
def CloseK52Longagg2 = close(period = Agg2) > Kijun52agg2;  #***
###
def CloseK78Long = close > Kijun78;
def CloseK78Longagg1 = close(period = Agg1) > Kijun78agg1;
def CloseK78Longagg2 = close(period = Agg2) > Kijun78agg2;
###




####################################################
  #               SHORTS                         #
####################################################
def T2B1KumoShort = Tenkan2 < B1;
def T2B1KumoShortagg1 = Tenkan2agg1 < B1agg1;
def T2B1KumoShortagg2 = Tenkan2agg2 < B1agg2;
###
def T4B2KumoShort = Tenkan4 < B2;
def T4B2KumoShortagg1 = Tenkan4agg1 < B2agg1;
def T4B2KumoShortagg2 = Tenkan4agg2 < B2agg2;
###
def TKS4_13 = Tenkan4 < Kijun13;  #***
def TKS4_13agg1 = Tenkan4agg1 < Kijun13agg1;  #***
def TKS4_13agg2 = Tenkan4agg2 < Kijun13agg2;  #***
###
def TKS9_26 = Tenkan9 < Kijun26;
def TKS9_26agg1 = Tenkan9agg1 < Kijun26agg1;
def TKS9_26agg2 = Tenkan9agg2 < Kijun26agg2;
###
def TKS4_52 = Tenkan4 < Kijun52;
def TKS4_52agg1 = Tenkan4agg1 < Kijun52agg1;
def TKS4_52agg2 = Tenkan4agg2 < Kijun52agg2;
###
def CloseK13Short = close < Kijun13;
def CloseK13Shortagg1 = close(period = Agg1) < Kijun13agg1;
def CloseK13Shortagg2 = close(period = Agg2) < Kijun13agg2;

###
def CloseK52Short = close < Kijun52;  #***
def CloseK52Shortagg1 = close(period = Agg1) < Kijun52agg1;  #***
def CloseK52Shortagg2 = close(period = Agg2) < Kijun52agg2;  #***
###
def CloseK78Short = close < Kijun78;
def CloseK78Shortagg1 = close(period = Agg1) < Kijun78agg1;
def CloseK78Shortagg2 = close(period = Agg2) < Kijun78agg2;
###

#def LagL = Chikou[52] > close[26];
def FutureBullishCloudA = A1[-8.66] > B1[-8.66];
def FutureBullishCloudB = A2[-13] > B2[-13];
def FutureBullishCloudC = A3[-26] > B3[-26];
def FutureBullishCloudD = A4[-52] > B4[-52];
def FutureBullishCloudE = A5[-78] > B5[-78];

def FutureBullishCloudAagg1 = A1agg1[-8.66] > B1agg1[-8.66];
def FutureBullishCloudBagg1  = A2agg1[-13] > B2agg1[-13];
def FutureBullishCloudCagg1  = A3agg1[-26] > B3agg1[-26];
def FutureBullishCloudDagg1  = A4agg1[-52] > B4agg1[-52];
def FutureBullishCloudEagg1  = A5agg1[-78] > B5agg1[-78];

def FutureBullishCloudAagg2 = A1agg2[-8.66] > B1agg2[-8.66];
def FutureBullishCloudBagg2  = A2agg2[-13] > B2agg2[-13];
def FutureBullishCloudCagg2  = A3agg2[-26] > B3agg2[-26];
def FutureBullishCloudDagg2  = A4agg2[-52] > B4agg2[-52];
def FutureBullishCloudEagg2  = A5agg2[-78] > B5agg2[-78];

def Lag1L = Chikou13[13] > chikou6[13];
def Lag2L = Chikou26[26] > chikou13[26];
def Lag3L = Chikou52[52] > chikou26[52];
def Lag4L = Chikou78[78] > chikou52[78];

def Lag1LAGG1 = Chikou13AGG1[13] > chikou6agg1[13];
def Lag2LAGG1 = Chikou26AGG1[26] > chikou13agg1[26];
def Lag3LAGG1 = Chikou52AGG1[52] > chikou52agg1[52];
def Lag4LAGG1 = Chikou78AGG1[78] > chikou78agg1[78];

def Lag1LAGG2 = Chikou13AGG2[13] > chikou6agg2[13];
def Lag2LAGG2 = Chikou26AGG2[26] > chikou13agg2[26];
def Lag3LAGG2 = Chikou52AGG2[52] > chikou52agg2[52];
def Lag4LAGG2 = Chikou78AGG2[78] > chikou78agg2[78];

def ChikouL = Lag1L and Lag2L and Lag3L and Lag4L;
def ChikouLagg1 = Lag1Lagg1 and Lag2Lagg1 and Lag3Lagg1 and Lag4Lagg1;
def ChikouLagg2 = Lag1Lagg2 and Lag2Lagg2 and Lag3Lagg2 and Lag4Lagg2;

def FutureBearishCloudA = A1[-8.66] < B1[-8.66];
def FutureBearishCloudB = A2[-13] < B2[-13];
def FutureBearishCloudC = A3[-26] < B3[-26];
def FutureBearishCloudD = A4[-52] < B4[-52];
def FutureBearishCloudE = A5[-78] < B5[-78];

def FutureBearishCloudAagg1 = A1agg1[-8.66] < B1agg1[-8.66];
def FutureBearishCloudBagg1  = A2agg1[-13] < B2agg1[-13];
def FutureBearishCloudCagg1  = A3agg1[-26] < B3agg1[-26];
def FutureBearishCloudDagg1  = A4agg1[-52] < B4agg1[-52];
def FutureBearishCloudEagg1  = A5agg1[-78] < B5agg1[-78];

def FutureBearishCloudAagg2 = A1agg2[-8.66] < B1agg2[-8.66];
def FutureBearishCloudBagg2  = A2agg2[-13] < B2agg2[-13];
def FutureBearishCloudCagg2  = A3agg2[-26] < B3agg2[-26];
def FutureBearishCloudDagg2  = A4agg2[-52] < B4agg2[-52];
def FutureBearishCloudEagg2  = A5agg2[-78] < B5agg2[-78];

def Lag1S = Chikou13[13] < chikou6[13];
def Lag2S = Chikou26[26] < chikou13[26];
def Lag3S = Chikou52[52] < chikou26[52];
def Lag4S = Chikou78[78] < chikou52[78];

def Lag1SAGG1 = Chikou13AGG1[13] < chikou6agg1[13];
def Lag2SAGG1 = Chikou26AGG1[26] < chikou13agg1[26];
def Lag3SAGG1 = Chikou52AGG1[52] < chikou26agg1[26];
def Lag4SAGG1 = Chikou78AGG1[78] < chikou52agg1[52];

def Lag1SAGG2 = Chikou13AGG2[13] < chikou6agg2[13];
def Lag2SAGG2 = Chikou26AGG2[26] < chikou13agg2[26];
def Lag3SAGG2 = Chikou52AGG2[52] < chikou26agg2[26];
def Lag4SAGG2 = Chikou78AGG2[78] < chikou52agg2[52];

def ChikouS = Lag1S and Lag2S and Lag3S and Lag4S;
def ChikouSagg1 = Lag1Sagg1 and Lag2Sagg1 and Lag3Sagg1 and Lag4Sagg1;
def ChikouSagg2 = Lag1Sagg2 and Lag2Sagg2 and Lag3Sagg2 and Lag4Sagg2;

# ============================================================================

def Long = ChikouL and T2B1KumoLong and T4B2KumoLong and TKL4_13 and TKL4_52 and TKL9_26 and CloseK78Long and CloseK52Long and FutureBullishCloudA and FutureBullishCloudB  ;
def LongAGG1 = chikoulagg1 and T2B1KumoLongagg1 and T4B2KumoLongagg1 and TKL4_13agg1 and TKL9_26agg1 and TKL4_52agg1 and CloseK52Longagg1 and closek78Longagg1 and FutureBullishCloudAagg1 and futureBullishCloudBagg1;
def LongAGG2 = chikoulagg2 and T2B1KumoLongagg2 and T4B2KumoLongagg2 and TKL4_13agg2 and TKL4_52agg2 and TKL9_26agg2 and CloseK52Longagg2 and closek78Longagg2 and FutureBullishCloudAagg2 and futureBullishCloudBagg2 ;

###############################
  #    pullback_Long long  #
#############################
def PullBack_Long = TKS4_52 and TKL4_13 and CloseK52Short ;
def PullBack_LongAGG1 = TKS4_52agg1 and TKL4_13agg1 and CloseK52Shortagg1 ;
def PullBack_LongAGG2 = TKS4_52agg2 and TKL4_13agg2 and CloseK52Shortagg2 ;
#########################
  #      SHORTS      #
########################
def Short = ChikouS and T2B1KumoShort and T4B2KumoShort and TKS4_13 and TKS4_52 and TKS9_26 and CloseK52Short and CloseK78Short and FutureBearishCloudA and FutureBearishCloudB;
def ShortAGG1 = ChikouSagg1 and T2B1KumoShortagg1 and T4B2KumoShortagg1 and TKS4_13agg1 and TKS4_52agg1 and TKS9_26agg1 and CloseK52Shortagg1 and CloseK78Shortagg1 and FutureBearishCloudAagg1 and futureBearishCloudBagg1;
def ShortAGG2 = ChikouSagg2 and T2B1KumoShortagg2 and T4B2KumoShortagg2 and TKS4_13agg2 and TKS4_52agg2 and TKS9_26agg2 and CloseK52Shortagg2 and CloseK78Shortagg2 and FutureBearishCloudAagg2 and futureBearishCloudBagg2;

def PullBack_Short = TKL4_52 and TKS4_13 and CloseK52Long;
def PullBack_ShortAGG1 = TKL4_52agg1 and TKS4_52agg1 and CloseK52Longagg1 ;
def PullBack_ShortAGG2 = TKL4_52agg2 and TKS4_13agg2 and CloseK52Longagg2 ;


#############################################
  #          Agreement Levels x2          #
################################################

# Longs
def Agree_TB_CloudsL = T2B1KumoLong + T4B2KumoLong;
def Agree_TB_CloudsLagg1 = T2B1KumoLongagg1 + T4B2KumoLongagg1;
def Agree_TB_CloudsLagg2 = T2B1KumoLongagg2 + T4B2KumoLongagg2;
###
def Agree_TKL = TKL4_13 + TKL4_52 + TKL9_26;
def Agree_TKLagg1 = TKL4_13agg1 + TKL4_52agg1 + TKL9_26agg1;
def Agree_TKLagg2 = TKL4_13agg2 + TKL4_52agg2 + TKL9_26agg2;
###
def Agree_CloseL = CloseK13Long + CloseK52Long + CloseK78Long;
def Agree_CloseLagg1 = CloseK13Longagg1 + CloseK52Longagg1 + CloseK78Longagg1;
def Agree_CloseLagg2 = CloseK13Longagg2 + CloseK52Longagg2 + CloseK78Longagg2;
###
def Agree_DragonL = FutureBullishCloudA + FutureBullishCloudB + FutureBullishCloudC + FutureBullishCloudD + FutureBullishCloudE;
def Agree_DragonLagg1 = FutureBullishCloudAagg1 + FutureBullishCloudBagg1 + FutureBullishCloudCagg1 + FutureBullishCloudDagg1 + FutureBullishCloudEagg1;
def Agree_DragonLagg2 = FutureBullishCloudAagg2 + FutureBullishCloudBagg2 + FutureBullishCloudCagg2 + FutureBullishCloudDagg2 + FutureBullishCloudEagg2;
###
def Agree_LagL = Lag1L + Lag2L + Lag3L + Lag4L;
def Agree_LagLagg1 = Lag1LAGG1 + Lag2LAGG1 + Lag3LAGG1 + Lag4LAGG1;
def Agree_LagLagg2 = Lag1LAGG2 + Lag2LAGG2 + Lag3LAGG2 + Lag4LAGG2;
###
def Agree_KumoL = closePriceLongCloud1 + closePriceLongCloud2 + closePriceLongCloud3 + closePriceLongCloud4 + closePriceLongCloud5;
def Agree_KumoLagg1 = closePriceLongCloud1agg1 + closePriceLongCloud2agg1 + closePriceLongCloud3agg1 + closePriceLongCloud4agg1 + closePriceLongCloud5agg1;
def Agree_KumoLagg2 = closePriceLongCloud1agg2 + closePriceLongCloud2agg2 + closePriceLongCloud3agg2 + closePriceLongCloud4agg2 + closePriceLongCloud5agg2;
###


# Shorts
def Agree_TB_CloudsS = T2B1KumoShort + T4B2KumoShort;
def Agree_TB_CloudsSagg1 = T2B1KumoShortagg1 + T4B2KumoShortagg1;
def Agree_TB_CloudsSagg2 = T2B1KumoShortagg2 + T4B2KumoShortagg2;
###
def Agree_TKS = TKS4_13 + TKS4_52 + TKS9_26;
def Agree_TKSagg1 = TKS4_13agg1 + TKS4_52agg1 + TKS9_26agg1;
def Agree_TKSagg2 = TKS4_13agg2 + TKS4_52agg2 + TKS9_26agg2;
###
def Agree_CloseS = CloseK13Short + CloseK52Short + CloseK78Short;
def Agree_CloseSagg1 = CloseK13Shortagg1 + CloseK52Shortagg1 + CloseK78Shortagg1;
def Agree_CloseSagg2 = CloseK13Shortagg2 + CloseK52Shortagg2 + CloseK78Shortagg2;
###
def Agree_DragonS = FutureBearishCloudA + FutureBearishCloudB + FutureBearishCloudC + FutureBearishCloudD + FutureBearishCloudE;
def Agree_DragonSagg1 = FutureBearishCloudAagg1 + FutureBearishCloudBagg1 + FutureBearishCloudCagg1 + FutureBearishCloudDagg1 + FutureBearishCloudEagg1;
def Agree_DragonSagg2 = FutureBearishCloudAagg2 + FutureBearishCloudBagg2 + FutureBearishCloudCagg2 + FutureBearishCloudDagg2 + FutureBearishCloudEagg2;
###
def Agree_LagS = Lag1S + Lag2S + Lag3S + Lag4S;
def Agree_LagSagg1 = Lag1Sagg1 + Lag2Sagg1 + Lag3Sagg1 + Lag4Sagg1;
def Agree_LagSagg2 = Lag1Sagg2 + Lag2Sagg2 + Lag3Sagg2 + Lag4Sagg2;
###
def Agree_KumoS = closePriceShortCloud1 + closePriceShortCloud2 + closePriceShortCloud3 + closePriceShortCloud4 + closePriceShortCloud5;
def Agree_KumoSagg1 = closePriceShortCloud1agg1 + closePriceShortCloud2agg1 + closePriceShortCloud3agg1 + closePriceShortCloud4agg1 + closePriceShortCloud5agg1;
def Agree_KumoSagg2 = closePriceShortCloud1agg2 + closePriceShortCloud2agg2 + closePriceShortCloud3agg2 + closePriceShortCloud4agg2 + closePriceShortCloud5agg2;

###
###
## Consensus_Level
def ConLevel_TBClouds = Agree_TB_CloudsL - Agree_TB_CloudsS;
def ConLevel_TBCloudsagg1 = Agree_TB_CloudsLagg1 - Agree_TB_CloudsSagg1;
def ConLevel_TBCloudsagg2 = Agree_TB_CloudsLagg2 - Agree_TB_CloudsSagg2;
###
def ConLevel_TK = Agree_TKL - Agree_TKS;
def ConLevel_TKagg1 = Agree_TKLagg1 - Agree_TKSagg1;
def ConLevel_TKagg2 = Agree_TKLagg2 - Agree_TKSagg2;
###
def ConLevel_Close = Agree_CloseL - Agree_CloseS;
def ConLevel_Closeagg1 = Agree_CloseLagg1 - Agree_CloseSagg1;
def ConLevel_Closeagg2 = Agree_CloseLagg2 - Agree_CloseSagg2;
###
def ConLevel_Dragon = Agree_DragonL - Agree_DragonS;
def ConLevel_Dragonagg1 = Agree_DragonLagg1 - Agree_DragonSagg1;
def ConLevel_Dragonagg2 = Agree_DragonLagg2 - Agree_DragonSagg2;
###
def ConLevel_Lag = Agree_LagL - Agree_LagS;
def ConLevel_Lagagg1 = Agree_LagLagg1 - Agree_LagSagg1;
def ConLevel_Lagagg2 = Agree_LagLagg2 - Agree_LagSagg2;
###
def ConLevel_Kumo = Agree_KumoL - Agree_KumoS;
def ConLevel_Kumoagg1 = Agree_KumoLagg1 - Agree_KumoSagg1;
def ConLevel_Kumoagg2 = Agree_KumoLagg2 - Agree_KumoSagg2;
###
###
## Momentum
def MomCloudsUp = ConLevel_TBClouds[1] < ConLevel_TBClouds;
def MomCloudsUpagg1 = ConLevel_TBCloudsagg1[1] < ConLevel_TBCloudsagg1;
def MomCloudsUpagg2 = ConLevel_TBCloudsagg2[1] < ConLevel_TBCloudsagg2;
###
def MomCloudsDown = ConLevel_TBClouds[1] > ConLevel_TBClouds;
def MomCloudsDownagg1 = ConLevel_TBCloudsagg1[1] > ConLevel_TBCloudsagg1;
def MomCloudsDownagg2 = ConLevel_TBCloudsagg2[1] > ConLevel_TBCloudsagg2;
###
def MomTKUp = ConLevel_TK[1] < ConLevel_TK;
def MomTKUpagg1 = ConLevel_TKagg1[1] < ConLevel_TKagg1;
def MomTKUpagg2 = ConLevel_TKagg2[1] < ConLevel_TKagg2;
###
def MomTKDown = ConLevel_TK[1] > ConLevel_TK;
def MomTKDownagg1 = ConLevel_TKagg1[1] > ConLevel_TKagg1;
def MomTKDownagg2 = ConLevel_TKagg2[1] > ConLevel_TKagg2;
###
def MomCloseUp = ConLevel_Close[1] < ConLevel_Close;
def MomCloseUpagg1 = ConLevel_Closeagg1[1] < ConLevel_Closeagg1;
def MomCloseUpagg2 = ConLevel_Closeagg2[1] < ConLevel_Closeagg2;
###
def MomCloseDown = ConLevel_Close[1] > ConLevel_Close;
def MomCloseDownagg1 = ConLevel_Closeagg1[1] > ConLevel_Closeagg1;
def MomCloseDownagg2 = ConLevel_Closeagg2[1] > ConLevel_Closeagg2;
###
def MomDragonUp = ConLevel_Dragon[1] < ConLevel_Dragon;
def MomDragonUpagg1 = ConLevel_Dragonagg1[1] < ConLevel_Dragonagg1;
def MomDragonUpagg2 = ConLevel_Dragonagg2[1] < ConLevel_Dragonagg2;
###
def MomDragonDown = ConLevel_Dragon[1] > ConLevel_Dragon;
def MomDragonDownagg1 = ConLevel_Dragonagg1[1] > ConLevel_Dragonagg1;
def MomDragonDownagg2 = ConLevel_Dragonagg2[1] > ConLevel_Dragonagg2;
###
def MomLagUp = ConLevel_Lag[1] < ConLevel_Lag;
def MomLagUpagg1 = ConLevel_Lagagg1[1] < ConLevel_Lagagg1;
def MomLagUpagg2 = ConLevel_Lagagg2[1] < ConLevel_Lagagg2;
###
def MomLagDown = ConLevel_Lag[1] > ConLevel_Lag;
def MomLagDownagg1 = ConLevel_Lagagg1[1] > ConLevel_Lagagg1;
def MomLagDownagg2 = ConLevel_Lagagg2[1] > ConLevel_Lagagg2;
###
def MomKumoUp = ConLevel_Kumo[1] < ConLevel_Kumo;
def MomKumoUpagg1 = ConLevel_Kumoagg1[1] < ConLevel_Kumoagg1;
def MomKumoUpagg2 = ConLevel_Kumoagg2[1] < ConLevel_Kumoagg2;
###
def MomKumoDown = ConLevel_Kumo[1] > ConLevel_Kumo;
def MomKumoDownagg1 = ConLevel_Kumoagg1[1] > ConLevel_Kumoagg1;
def MomKumoDownagg2 = ConLevel_Kumoagg2[1] > ConLevel_Kumoagg2;
###
###
# Total Momentum

######
def AgreeTotalL = Agree_TB_CloudsL + Agree_TKL + Agree_CloseL + Agree_DragonL + Agree_LagL + Agree_KumoL;
def AgreeTotalLagg1 = Agree_TB_CloudsLagg1 + Agree_TKLagg1 + Agree_CloseLagg1 + Agree_DragonLagg1 + Agree_LagLagg1 + Agree_KumoLagg1;
def AgreeTotalLagg2 = Agree_TB_CloudsLagg2 + Agree_TKLagg2 + Agree_CloseLagg2 + Agree_DragonLagg2 + Agree_LagLagg2 + Agree_KumoLagg2;
###
def AgreeTotalS = Agree_TB_CloudsS + Agree_TKS + Agree_CloseS + Agree_DragonS + Agree_LagS + Agree_KumoS;
def AgreeTotalSagg1 = Agree_TB_CloudsSagg1 + Agree_TKSagg1 + Agree_CloseSagg1 + Agree_DragonSagg1 + Agree_LagSagg1 + Agree_KumoSagg1;
def AgreeTotalSagg2 = Agree_TB_CloudsSagg2 + Agree_TKSagg2 + Agree_CloseSagg2 + Agree_DragonSagg2 + Agree_LagSagg2 + Agree_KumoSagg2;
###
def ConTotal = AgreeTotalL - AgreeTotalS;
def ConTotalagg1 = AgreeTotalLagg1 - AgreeTotalSagg1;
def ConTotalagg2 = AgreeTotalLagg2 - AgreeTotalSagg2;
###
def MomTotalUp = ConTotal[1] < ConTotal;
def MomTotalUpagg1 = ConTotalagg1[1] < ConTotalagg1;
def MomTotalUpagg2 = ConTotalagg2[1] < ConTotalagg2;
###
def MomTotalDown = ConTotal[1] > ConTotal;
def MomTotalDownagg1 = ConTotalagg1[1] > ConTotalagg1;
def MomTotalDownagg2 = ConTotalagg2[1] > ConTotalagg2;

#####################################
  #          combined TF           #
########################################

def AgreeTotAllTF_L = agreeTotalL + agreeTotalLagg1 + agreeTotalLagg2;

def AgreeTotAllTF_S = agreeTotalS + agreeTotalSagg1 + agreeTotalSagg2;

def ConTotalALLTF = agreetotAllTF_L - agreetotAllTF_S;

def MomTotalUpALLUp = ConTotalALLTF[1] < ConTotalALLTF;
def MomTotalUpALLDown = ConTotalALLTF[1] > ConTotalALLTF;

####################################
 #        LABELS                #
######################################
AddLabel(yes, if MomTotalUpAllUp then "** ToT = " + Round(ConTotalALLTF, 1) + "**"  else if MomTotalUpALLDown then  "** ToT = " + Round(ConTotalALLTF, 1) + "**"  else "** ToT = " + Round(ConTotalALLTF, 1) + "**", if MomTotalUpALLDown then CreateColor(191, 42, 42) else if MomTotalUpAllUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(Spacer, "     ", Color.GRAY);
###################

AddLabel(yes, if MomTotalUp then "ToT = " + Round(ConTotal, 1)  else if MomTotalDown then  "ToT = " + Round(ConTotal, 1)  else "ToT = " + Round(ConTotal, 1), if MomTotalDown then CreateColor(191, 42, 42) else if MomTotalUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(showChartlabels, if pullBack_Long then "PBL" else if Long then "TKL" else if pullBack_Short then "PBS" else if Short then "TKS"  else "", if Long or pullBack_Long then CreateColor(63, 187, 93) else if Short or pullBack_Short  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(yes, if MomCloudsUp then "T_B = " + Round(ConLevel_TBClouds, 1)  else if MomCloudsDown then  "T_B = " + Round(ConLevel_TBClouds, 1)  else "T_B = " + Round(ConLevel_TBClouds, 1), if MomCloudsDown then CreateColor(191, 42, 42) else if MomCloudsUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomTKUp then "T_K = " + Round(ConLevel_TK, 1)  else if MomTKDown then  "T_K = " + Round(ConLevel_TK, 1)  else "T_K = " + Round(ConLevel_TK, 1), if MomTKDown then CreateColor(191, 42, 42) else if MomTKUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomCloseUp then "Close = " + Round(ConLevel_Close, 1)  else if MomCloseDown then  "Close = " + Round(ConLevel_Close, 1)  else "Close = " + Round(ConLevel_Close, 1), if MomCloseDown then CreateColor(191, 42, 42) else if MomCloseUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomDragonUp then "Dragon = " + Round(ConLevel_Dragon, 1)  else if MomDragonDown then  "Dragon = " + Round(ConLevel_Dragon, 1)  else "Dragon = " + Round(ConLevel_Dragon, 1), if MomDragonDown then CreateColor(191, 42, 42) else if MomDragonUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomLagUp then "Lag = " + Round(ConLevel_Lag, 1)  else if MomLagDown then  "Lag = " + Round(ConLevel_Lag, 1)  else "Lag = " + Round(ConLevel_Lag, 1), if MomLagDown then CreateColor(191, 42, 42) else if MomLagUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomKumoUp then "Kumo = " + Round(ConLevel_Kumo, 1)  else if MomKumoDown then  "Kumo = " + Round(ConLevel_Kumo, 1)  else "Kumo = " + Round(ConLevel_Kumo, 1), if MomKumoDown then CreateColor(191, 42, 42) else if MomKumoUp then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(Spacer, "---" + time1 + "---", Color.GRAY);

########################
AddLabel(yes, if MomTotalUpAGG1 then "ToT = " + Round(ConTotalAGG1, 1)  else if MomTotalDownAGG1 then  "ToT = " + Round(ConTotalAGG1, 1)  else "ToT = " + Round(ConTotalAGG1, 1), if MomTotalDownAGG1 then CreateColor(191, 42, 42) else if MomTotalUpAGG1 then CreateColor(63, 187, 93) else Color.DARK_GRAY);

AddLabel(showChartlabels, if pullBack_Longagg1 then "PBL" else if Longagg1 then "TKL" else if pullBack_Shortagg1 then "PBS" else if Shortagg1 then "TKS"  else "   ", if Longagg1 or pullBack_Longagg1 then CreateColor(63, 187, 93) else if Shortagg1 or pullBack_Shortagg1  then CreateColor(191, 42, 42) else Color.DARK_GRAY);


AddLabel(yes, if MomCloudsUpAGG1 then "T_B = " + Round(ConLevel_TBCloudsAGG1, 1)  else if MomCloudsDownAGG1 then  "T_B = " + Round(ConLevel_TBCloudsAGG1, 1)  else "T_B = " + Round(ConLevel_TBCloudsAGG1, 1), if MomCloudsDownAGG1 then CreateColor(191, 42, 42) else if MomCloudsUpAGG1 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomTKUpAGG1 then "T_K = " + Round(ConLevel_TKAGG1, 1)  else if MomTKDownAGG1 then  "T_K = " + Round(ConLevel_TKAGG1, 1)  else "T_K = " + Round(ConLevel_TKAGG1, 1), if MomTKDownAGG1 then CreateColor(191, 42, 42) else if MomTKUpAGG1 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomCloseUpAGG1 then "Close = " + Round(ConLevel_CloseAGG1, 1)  else if MomCloseDownAGG1 then  "Close = " + Round(ConLevel_CloseAGG1, 1)  else "Close = " + Round(ConLevel_CloseAGG1, 1), if MomCloseDownAGG1 then CreateColor(191, 42, 42) else if MomCloseUpAGG1 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomDragonUpAGG1 then "Dragon = " + Round(ConLevel_DragonAGG1, 1)  else if MomDragonDownAGG1 then  "Dragon = " + Round(ConLevel_DragonAGG1, 1)  else "Dragon = " + Round(ConLevel_DragonAGG1, 1), if MomDragonDownAGG1 then CreateColor(191, 42, 42) else if MomDragonUpAGG1 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomLagUpAGG1 then "Lag = " + Round(ConLevel_LagAGG1, 1)  else if MomLagDownAGG1 then  "Lag = " + Round(ConLevel_LagAGG1, 1)  else "Lag = " + Round(ConLevel_LagAGG1, 1), if MomLagDownAGG1 then CreateColor(191, 42, 42) else if MomLagUpAGG1 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomKumoUpAGG1 then "Kumo = " + Round(ConLevel_KumoAGG1, 1)  else if MomKumoDownAGG1 then  "Kumo = " + Round(ConLevel_KumoAGG1, 1)  else "Kumo = " + Round(ConLevel_KumoAGG1, 1), if MomKumoDownAGG1 then CreateColor(191, 42, 42) else if MomKumoUpAGG1 then CreateColor(63, 187, 93) else Color.DARK_GRAY);

##################################
AddLabel(Spacer, "---" + time2 + "---", Color.GRAY);

AddLabel(yes, if MomTotalUpAGG2 then "ToT = " + Round(ConTotalAGG2, 1)  else if MomTotalDownAGG2 then  "ToT = " + Round(ConTotalAGG2, 1)  else "ToT = " + Round(ConTotalAGG2, 1), if MomTotalDownAGG2 then CreateColor(191, 42, 42) else if MomTotalUpAGG2 then CreateColor(63, 187, 93) else Color.DARK_GRAY);

AddLabel(showChartlabels, if pullBack_Longagg2 then "PBL" else if Longagg2 then "TKL" else if pullBack_Shortagg2 then "PBS" else if Shortagg2 then "TKS"  else "   ", if Longagg2 or pullBack_Longagg2 then CreateColor(63, 187, 93) else if Shortagg2 or pullBack_Shortagg2  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(yes, if MomCloudsUpAGG2 then "T_B = " + Round(ConLevel_TBCloudsAGG2, 1)  else if MomCloudsDownAGG2 then  "T_B = " + Round(ConLevel_TBCloudsAGG2, 1)  else "T_B = " + Round(ConLevel_TBCloudsAGG2, 1), if MomCloudsDownAGG2 then CreateColor(191, 42, 42) else if MomCloudsUpAGG2 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomTKUpAGG2 then "T_K = " + Round(ConLevel_TKAGG2, 1)  else if MomTKDownAGG2 then  "T_K = " + Round(ConLevel_TKAGG2, 1)  else "T_K = " + Round(ConLevel_TKAGG2, 1), if MomTKDownAGG2 then CreateColor(191, 42, 42) else if MomTKUpAGG2 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomCloseUpAGG2 then "Close = " + Round(ConLevel_CloseAGG2, 1)  else if MomCloseDownAGG2 then  "Close = " + Round(ConLevel_CloseAGG2, 1)  else "Close = " + Round(ConLevel_CloseAGG2, 1), if MomCloseDownAGG2 then CreateColor(191, 42, 42) else if MomCloseUpAGG2 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomDragonUpAGG2 then "Dragon = " + Round(ConLevel_DragonAGG2, 1)  else if MomDragonDownAGG2 then  "Dragon = " + Round(ConLevel_DragonAGG2, 1)  else "Dragon = " + Round(ConLevel_DragonAGG2, 1), if MomDragonDownAGG2 then CreateColor(191, 42, 42) else if MomDragonUpAGG2 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomLagUpAGG2 then "Lag = " + Round(ConLevel_LagAGG2, 1)  else if MomLagDownAGG2 then  "Lag = " + Round(ConLevel_LagAGG2, 1)  else "Lag = " + Round(ConLevel_LagAGG2, 1), if MomLagDownAGG2 then CreateColor(191, 42, 42) else if MomLagUpAGG2 then CreateColor(63, 187, 93) else Color.DARK_GRAY);
AddLabel(yes, if MomKumoUpAGG2 then "Kumo = " + Round(ConLevel_KumoAGG2, 1)  else if MomKumoDownAGG2 then  "Kumo = " + Round(ConLevel_KumoAGG2, 1)  else "Kumo = " + Round(ConLevel_KumoAGG2, 1), if MomKumoDownAGG2 then CreateColor(191, 42, 42) else if MomKumoUpAGG2 then CreateColor(63, 187, 93) else Color.DARK_GRAY);





################# AGG2 ###########################################################################

#AddChartBubble(sbT18_K52, Tenkan18AGG1, "T_18  " + time1,  CreateColor(99,211,146));
AddChartBubble( sbT18_K52 , Kijun52agg1, "K_52 " + Time1,  CreateColor(223, 63, 35));

#AddChartBubble(sbT18_K52, Tenkan18AGG2, "T_18  " + time2,  CreateColor(99,211,146));
AddChartBubble( sbT18_K52 , Kijun52agg2, "K_52 " + Time2,  CreateColor(223, 63, 35));




#AddLabel(showChartlabels, if PullBack_Long then "PB_L" else if PullBack_Short then "PB_S"  else "", if PullBack_Long  then CreateColor(63, 187, 93) else if PullBack_Short  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

######################### AGG1 ######################################################
#AddLabel(Spacer, "-" + Time1 + "-", Color.GRAY);
############################################################################
#AddLabel(showagg1labels, if LongAGG1 then "TKL " else if ShortAGG1 then "TKS "   else "", if LongAGG1  then CreateColor(63, 187, 93) else if ShortAGG1  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showagg1labels, if PullBack_LongAGG1 then "PB_L " else if PullBack_ShortAGG1 then "PB_S "  else "", if PullBack_LongAGG1  then CreateColor(63, 187, 93) else if PullBack_ShortAGG1  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
########################### agg2 #############################################

#AddLabel(showagg2labels, if LongAGG2 then "TKL " else if ShortAGG2 then "TKS "  else "", if LongAGG2  then CreateColor(63, 187, 93) else if ShortAGG2  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(showagg2labels, if PullBack_LongAGG2 then "PB_L " else if PullBack_ShortAGG2 then "PB_S " else "", if PullBack_LongAGG2  then CreateColor(63, 187, 93) else if PullBack_ShortAGG2  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#plot threeHGH = if long then low else Double.NaN;
#threeHGH.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
#threeHGH.SetDefaultColor(Color.BLUE);

#plot threelO = if short then high else Double.NaN;
#threelO.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
#threelO.SetDefaultColor(Color.RED);


And the same code (I hope) without MTF trend Analysis

Code:
# Dragon MTF 10-23-2022
# MTF Consensus
input Time1 = {"5 min", "10 min", "20 min", "1 Hour", "2 Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
input Time2 = {"5 min", "10 min", "20 min", "1 Hour", "2 Hour", "4 Hour", "Daily", default "Weekly", "Monthly"};
#============TIME=========================

def Agg1;

switch (Time1) {
case "5 min":
    Agg1 = AggregationPeriod.FIVE_MIN;
case "10 min":
    Agg1 = AggregationPeriod.TEN_MIN;
case "20 min":
    Agg1 = AggregationPeriod.TWENTY_MIN;
case "1 Hour":
    Agg1 = AggregationPeriod.HOUR;
case "2 Hour":
    Agg1 = AggregationPeriod.TWO_HOURS;
case "4 Hour":
    Agg1 = AggregationPeriod.FOUR_HOURS;
case "Daily":
    Agg1 = AggregationPeriod.DAY;
case "Weekly":
    Agg1 = AggregationPeriod.WEEK;
case "Monthly":
    Agg1 = AggregationPeriod.MONTH;
}
input Q = {_____, ____, default ______};

def Agg2;

switch (Time2) {
case "5 min":
    Agg2 = AggregationPeriod.FIVE_MIN;
case "10 min":
    Agg2 = AggregationPeriod.TEN_MIN;
case "20 min":
    Agg2 = AggregationPeriod.TWENTY_MIN;
case "1 Hour":
    Agg2 = AggregationPeriod.HOUR;
case "2 Hour":
    Agg2 = AggregationPeriod.TWO_HOURS;
case "4 Hour":
    Agg2 = AggregationPeriod.FOUR_HOURS;
case "Daily":
    Agg2 = AggregationPeriod.DAY;
case "Weekly":
    Agg2 = AggregationPeriod.WEEK;
case "Monthly":
    Agg2 = AggregationPeriod.MONTH;
}


#==============END TIME==================

#=============================================
input DN = Double.NaN;
input price = close;
input PlotCloudA_B = no;
input showT2_K6 = no;
input showT2agg1 = no;
input showT2agg2 = no;
input showT4 = no;
input showT4agg1 = no;
input showT4agg2 = no;
input showk13 = no;
input showk13agg1 = no;
input showk13agg2 = no;
input showT18 = no;
input showT18agg1 = no;
input showT18agg2 = no;
input showK6 = no;
input showK6agg1 = no;
input showK6agg2 = no;
input showK52 = no;
input showK52agg1 = no;
input showK52agg2 = no;

# ========================
input showcloud1KUMO = no;
input showcloud2KUMO = no;
input showcloud3KUMO = no;
input showcloud4KUMO = no;
input showcloud5KUMO = no;
input ShowAllDragonClouds = no;
input ShowCloud1_KUMOLines = no;
input ShowCloud2_KUMOLines = no;
input ShowCloud3_KUMOLines = no;
input ShowCloud4_KUMOLines = no;
input ShowCloud5_KUMOLines = no;
input plotCloud1 = no;
input plotcloud2 = no;
input ShowLagging = no;
input ShowPastKijunClouds = no;
input T2 = 3;
input T4 = 4.5;
input T9 = 9;
input T18 = 18;
input T27 = 27;
input K6 = 8;
input K13 = 13;
input K26 = 26;
input K52 = 52;
input K78 = 78;
input specificLength = 100;
def bn = BarNumber();
input showBalloons1 = {Left,  Right, default Off};
input showBalloons2 = {Left,  Right, default Off};
input showBalloons_K52 = {Left,  Right, default Off};
input showBalloons4 = {Left,  Right, default Off};
input UseTime1 = yes;
input UseTime2 = yes;
input showChartlabels = yes;
input showagg1labels = yes;
input showagg2labels = yes;
input Spacer = yes;


#def sbT4_K13 = (showBalloons1 == showBalloons1."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons1 == showBalloons1."Right" and IsNaN(close[-1]) and !IsNaN(close));

#def sbT9_K26 = (showBalloons2 == showBalloons2."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons2 == showBalloons2."Right" and IsNaN(close[-1]) and !IsNaN(close));

def sbT18_K52 = (showBalloons_K52 == showBalloons_K52."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons_K52 == showBalloons_K52."Right" and IsNaN(close[-1]) and !IsNaN(close));

#def sbT27_K78 = (showBalloons4 == showBalloons4."Left" and bn == HighestAll(bn) - specificLength) or (showBalloons4 == showBalloons4."Right" and IsNaN(close[-1]) and !IsNaN(close));
# ==================== Tenkan KiJun ===============================================


def Tenkan2 = (Highest(high, T2) + Lowest(low, T2)) / 2  ;
def Kijun6 = (Highest(high, K6) + Lowest(low, K6)) / 2;
def A1 = (Tenkan2[K6] + Kijun6[K6]) / 2;
def B1 = (Highest(high[K6], 2 * K6) + Lowest(low[K6], 2 * K6)) / 2;

def Tenkan4 = (Highest(high, T4) + Lowest(low, T4)) / 2  ;
def Kijun13 = (Highest(high, K13) + Lowest(low, K13)) / 2;
def A2 = (Tenkan4[K13] + Kijun13[K13]) / 2;
def B2 = (Highest(high[K13], 2 * K13) + Lowest(low[K13], 2 * K13)) / 2;

def Tenkan9 = (Highest(high, T9) + Lowest(low, T9)) / 2  ;
def Kijun26 = (Highest(high, K26) + Lowest(low, K26)) / 2;
def A3 = (Tenkan9[K26] + Kijun26[K26]) / 2;
def B3 = (Highest(high[K26], 2 * K26) + Lowest(low[K26], 2 * K26)) / 2;

def Tenkan18 = (Highest(high, T18) + Lowest(low, T18)) / 2;
def Kijun52 = (Highest(high, K52) + Lowest(low, K52)) / 2;
def A4 = (Tenkan18[K52] + Kijun52[K52]) / 2;
def B4 = (Highest(high[K52], 2 * K52) + Lowest(low[K52], 2 * K52)) / 2;

def Tenkan27 = (Highest(high, T27) + Lowest(low, T27)) / 2;
def Kijun78 = (Highest(high, K78) + Lowest(low, K78)) / 2;
def A5 = (Tenkan27[K78] + Kijun78[K78]) / 2;
def B5 = (Highest(high[K78], 2 * K78) + Lowest(low[K78], 2 * K78)) / 2;

def Tenkan2agg1 = (Highest(high(period = Agg1), T2) + Lowest(low(period = Agg1), T2)) / 2  ;
def Kijun6agg1 = (Highest(high(period = Agg1), K6) + Lowest(low(period = Agg1), K6)) / 2;
def A1agg1 = (Tenkan2agg1[K6] + Kijun6agg1[K6]) / 2;
def B1agg1 = (Highest(high(period = Agg1)[K6], 2 * K6) + Lowest(low(period = Agg1)[K6], 2 * K6)) / 2;

def Tenkan4agg1 = (Highest(high(period = Agg1), T4) + Lowest(low(period = Agg1), T4)) / 2  ;
def Kijun13agg1 = (Highest(high(period = Agg1), K13) + Lowest(low(period = Agg1), K13)) / 2;
def A2agg1 = (Tenkan4agg1[K13] + Kijun13agg1[K13]) / 2;
def B2agg1 = (Highest(high(period = Agg1)[K13], 2 * K13) + Lowest(low(period = Agg1)[K13], 2 * K13)) / 2;

def Tenkan9agg1 = (Highest(high(period = Agg1), T9) + Lowest(low(period = Agg1), T9)) / 2  ;
def Kijun26agg1 = (Highest(high(period = Agg1), K26) + Lowest(low(period = Agg1), K26)) / 2;
def A3agg1 = (Tenkan9agg1[K26] + Kijun26agg1[K26]) / 2;
def B3agg1 = (Highest(high(period = Agg1)[K26], 2 * K26) + Lowest(low(period = Agg1)[K26], 2 * K26)) / 2;

def Tenkan18agg1 = (Highest(high(period = Agg1), T18) + Lowest(low(period = Agg1), T18)) / 2;
def Kijun52agg1 = (Highest(high(period = Agg1), K52) + Lowest(low(period = Agg1), K52)) / 2;
def A4agg1 = (Tenkan18agg1[K52] + Kijun52agg1[K52]) / 2;
def B4agg1 = (Highest(high(period = Agg1)[K52], 2 * K52) + Lowest(low(period = Agg1)[K52], 2 * K52)) / 2;

def Tenkan27agg1 = (Highest(high(period = Agg1), T27) + Lowest(low(period = Agg1), T27)) / 2;
def Kijun78agg1 = (Highest(high(period = Agg1), K78) + Lowest(low(period = Agg1), K78)) / 2;
def A5agg1 = (Tenkan27agg1[K78] + Kijun78agg1[K78]) / 2;
def B5agg1 = (Highest(high(period = Agg1)[K78], 2 * K78) + Lowest(low(period = Agg1)[K78], 2 * K78)) / 2;

def Tenkan2agg2 = (Highest(high(period = Agg2), T2) + Lowest(low(period = Agg2), T2)) / 2  ;
def Kijun6agg2 = (Highest(high(period = Agg2), K6) + Lowest(low(period = Agg2), K6)) / 2;
def A1agg2 = (Tenkan2agg2[K6] + Kijun6agg2[K6]) / 2;
def B1agg2 = (Highest(high(period = Agg2)[K6], 2 * K6) + Lowest(low(period = Agg2)[K6], 2 * K6)) / 2;

def Tenkan4agg2 = (Highest(high(period = Agg2), T4) + Lowest(low(period = Agg2), T4)) / 2  ;
def Kijun13agg2 = (Highest(high(period = Agg2), K13) + Lowest(low(period = Agg2), K13)) / 2;
def A2agg2 = (Tenkan4agg2[K13] + Kijun13agg2[K13]) / 2;
def B2agg2 = (Highest(high(period = Agg2)[K13], 2 * K13) + Lowest(low(period = Agg2)[K13], 2 * K13)) / 2;

def Tenkan9agg2 = (Highest(high(period = Agg2), T9) + Lowest(low(period = Agg2), T9)) / 2  ;
def Kijun26agg2 = (Highest(high(period = Agg2), K26) + Lowest(low(period = Agg2), K26)) / 2;
def A3agg2 = (Tenkan9agg2[K26] + Kijun26agg2[K26]) / 2;
def B3agg2 = (Highest(high(period = Agg2)[K26], 2 * K26) + Lowest(low(period = Agg2)[K26], 2 * K26)) / 2;

def Tenkan18agg2 = (Highest(high(period = Agg2), T18) + Lowest(low(period = Agg2), T18)) / 2;
def Kijun52agg2 = (Highest(high(period = Agg2), K52) + Lowest(low(period = Agg2), K52)) / 2;
def A4agg2 = (Tenkan18agg2[K52] + Kijun52agg2[K52]) / 2;
def B4agg2 = (Highest(high(period = Agg2)[K52], 2 * K52) + Lowest(low(period = Agg2)[K52], 2 * K52)) / 2;

def Tenkan27agg2 = (Highest(high(period = Agg2), T27) + Lowest(low(period = Agg2), T27)) / 2;
def Kijun78agg2 = (Highest(high(period = Agg2), K78) + Lowest(low(period = Agg2), K78)) / 2;
def A5agg2 = (Tenkan27agg2[K78] + Kijun78agg2[K78]) / 2;
def B5agg2 = (Highest(high(period = Agg2)[K78], 2 * K78) + Lowest(low(period = Agg2)[K78], 2 * K78)) / 2;

# ============ cloud plots ===============

plot Cloud1a_1 = if plotCloud1 then A1 else Double.NaN;
Cloud1a_1.SetDefaultColor(CreateColor(136, 213, 94));
Cloud1a_1.SetLineWeight(1);
Cloud1a_1.SetStyle(Curve.LONG_DASH);

plot Cloud1B_1 = if plotCloud1 then B1 else Double.NaN;
Cloud1B_1.SetDefaultColor(CreateColor(229, 49, 5));
Cloud1B_1.SetLineWeight(1);
Cloud1B_1.SetStyle(Curve.LONG_DASH);

plot Cloud1a_2 = if plotcloud2 then A2 else Double.NaN;
Cloud1a_2.SetDefaultColor(CreateColor(136, 213, 94));
Cloud1a_2.SetLineWeight(1);
Cloud1a_2.SetStyle(Curve.LONG_DASH);

plot Cloud1B_2 = if plotcloud2 then B2 else Double.NaN;
Cloud1B_2.SetDefaultColor(CreateColor(229, 49, 5));
Cloud1B_2.SetLineWeight(1);
Cloud1B_2.SetStyle(Curve.LONG_DASH);


##################################################################
#                   Dragon Cloud Plots                          #
##################################################################
AddCloud(if showCloud1KUMO or ShowAllDragonClouds then A1 else Double.NaN, if showCloud1KUMO or ShowAllDragonClouds then B1 else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

plot Cloud1a = if  ShowCloud1_KUMOLines then A1 else Double.NaN;
Cloud1a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud1a.SetLineWeight(1);
Cloud1a.SetStyle(Curve.LONG_DASH);

plot Cloud1B = if  ShowCloud1_KUMOLines then B1 else Double.NaN;
Cloud1B.SetDefaultColor(CreateColor(229, 49, 5));
Cloud1B.SetLineWeight(1);
Cloud1B.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud2KUMO or ShowAllDragonClouds then A2 else Double.NaN, if showcloud2KUMO or ShowAllDragonClouds then B2 else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

plot Cloud2a = if  ShowCloud2_KUMOLines then A2 else Double.NaN;
Cloud2a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud2a.SetLineWeight(1);
Cloud2a.SetStyle(Curve.LONG_DASH);

plot Cloud2b = if  ShowCloud2_KUMOLines then B2 else Double.NaN;
Cloud2b.SetDefaultColor(CreateColor(229, 49, 5));
Cloud2b.SetLineWeight(1);
Cloud2b.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud3KUMO or ShowAllDragonClouds then A3 else Double.NaN, if showcloud3KUMO or ShowAllDragonClouds then B3 else Double.NaN, CreateColor(73, 196, 128), CreateColor(110, 89, 84));

AddCloud(if showcloud4KUMO or ShowAllDragonClouds then A4 else Double.NaN, if showcloud4KUMO or ShowAllDragonClouds then B4 else Double.NaN, CreateColor(36, 149, 87), CreateColor(64, 55, 52));

AddCloud(if showcloud5KUMO or ShowAllDragonClouds then A5 else Double.NaN, if showcloud5KUMO or ShowAllDragonClouds then B5 else Double.NaN, CreateColor(6, 78, 38), CreateColor(3, 3, 3));

# ============================================================================
# ====================== CHIKOU ============================================
def Chikou6 = close[-K6]  ;
def Chikou13 = close[-K13]  ;
def Chikou26 =  close[-K26]  ;
def Chikou52 =  close[-K52]  ;
def Chikou78 =  close[-K78]  ;

plot Chikou6p = if ShowLagging then close[-K6] else Double.NaN;
plot Chikou13p = if ShowLagging then close[-K13] else Double.NaN;
plot Chikou26p = if ShowLagging then close[-K26] else Double.NaN;
plot Chikou52p = if ShowLagging then close[-K52] else Double.NaN;
plot Chikou78p = if ShowLagging then close[-K78] else Double.NaN;

###########
# AGG1  #
###########

def Chikou6AGG1 = close(period = Agg1)[-K6]  ;
def Chikou13AGG1 = close(period = Agg1)[-K13]  ;
def Chikou26AGG1 =  close(period = Agg1)[-K26]  ;
def Chikou52AGG1 =  close(period = Agg1)[-K52]  ;
def Chikou78AGG1 =  close(period = Agg1)[-K78]  ;

###########
# AGG2  #
###########

def Chikou6AGG2 = close(period = Agg2)[-K6]  ;
def Chikou13AGG2 = close(period = Agg2)[-K13]  ;
def Chikou26AGG2 =  close(period = Agg2)[-K26]  ;
def Chikou52AGG2 =  close(period = Agg2)[-K52]  ;
def Chikou78AGG2 =  close(period = Agg2)[-K78]  ;

#######################################################################
#                        Past Kijun Clouds                          #
#########################################################################
AddCloud(if ShowPastKijunClouds then Chikou13p else Double.NaN, if ShowPastKijunClouds then Chikou6p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));
AddCloud(if ShowPastKijunClouds then Chikou26p else Double.NaN, if ShowPastKijunClouds then Chikou13p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));
AddCloud(if ShowPastKijunClouds then Chikou52p else Double.NaN, if ShowPastKijunClouds then Chikou26p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));
AddCloud(if ShowPastKijunClouds then Chikou78p else Double.NaN, if ShowPastKijunClouds then Chikou52p else Double.NaN, CreateColor(97, 221, 138), CreateColor(168, 102, 86));

# ============================================================================
# ================== TK PLOTS =========================================
plot T = if showT4 then Tenkan4 else Double.NaN;
plot k = if showk13 then Kijun13 else Double.NaN;
T.SetDefaultColor(CreateColor(75, 235, 175));
T.SetLineWeight(1);
T.SetStyle(Curve.FIRM);
k.SetDefaultColor(CreateColor(219, 75, 68));
k.SetLineWeight(1);
k.SetStyle(Curve.FIRM);

plot T1 = if showT2_K6 then Tenkan2 else Double.NaN;
plot k1 = if showT2_K6 then Kijun6 else Double.NaN;
T1.SetDefaultColor(CreateColor(52, 186, 136));
T1.SetLineWeight(1);
T1.SetStyle(Curve.MEDIUM_DASH);
k1.SetDefaultColor(CreateColor(255, 43, 43));
k1.SetLineWeight(1);
k1.SetStyle(Curve.MEDIUM_DASH);

plot T18p = if showT18 then Tenkan18 else Double.NaN;
plot k52p = if showK52 then Kijun52 else Double.NaN;
T18p.SetDefaultColor(CreateColor(99, 211, 146));
T18p.SetLineWeight(2);
T18p.SetStyle(Curve.FIRM);
k52p.SetDefaultColor(CreateColor(248, 41, 41));
k52p.SetLineWeight(2);
k52p.SetStyle(Curve.FIRM);

# ================= AGG1 TK ==========================================
plot TAGG1 = if showT4agg1 then Tenkan4agg1 else Double.NaN;
plot kAGG1 = if showk13agg1 then Kijun13agg1 else Double.NaN;
TAGG1.SetDefaultColor(CreateColor(75, 235, 175));
TAGG1.SetLineWeight(1);
TAGG1.SetStyle(Curve.FIRM);
kAGG1.SetDefaultColor(CreateColor(219, 75, 68));
kAGG1.SetLineWeight(1);
kAGG1.SetStyle(Curve.FIRM);

plot T1AGG1 = if showT2agg1 then Tenkan2agg1 else Double.NaN;
plot k1AGG1 = if showK6agg1 then Kijun6agg1 else Double.NaN;
T1AGG1.SetDefaultColor(CreateColor(52, 186, 136));
T1AGG1.SetLineWeight(1);
T1AGG1.SetStyle(Curve.FIRM);
k1AGG1.SetDefaultColor(CreateColor(255, 43, 43));
k1AGG1.SetLineWeight(2);
k1AGG1.SetStyle(Curve.FIRM);

plot T2agg1 = if showT18agg1 then Tenkan18agg1 else Double.NaN;
plot k2agg1 = if showK52agg1 then Kijun52agg1 else Double.NaN;
T2agg1.SetDefaultColor(CreateColor(99, 211, 146));
T2agg1.SetLineWeight(2);
T2agg1.SetStyle(Curve.LONG_DASH);
k2agg1.SetDefaultColor(CreateColor(194, 30, 30));
k2agg1.SetLineWeight(2);
k2agg1.SetStyle(Curve.LONG_DASH);

# ================= AGG2 TK ==========================================
plot TAGG2 = if showT4agg2 then Tenkan4agg2 else Double.NaN;
plot kAGG2 = if showk13agg2 then Kijun13agg2 else Double.NaN;
TAGG2.SetDefaultColor(CreateColor(75, 235, 175));
TAGG2.SetLineWeight(1);
TAGG2.SetStyle(Curve.FIRM);
kAGG2.SetDefaultColor(CreateColor(219, 75, 68));
kAGG2.SetLineWeight(1);
kAGG2.SetStyle(Curve.FIRM);

plot T1AGG2 = if showT2agg2 then Tenkan2agg2 else Double.NaN;
plot k1AGG2 = if showK6agg2 then Kijun6agg2 else Double.NaN;
T1AGG2.SetDefaultColor(CreateColor(52, 186, 136));
T1AGG2.SetLineWeight(1);
T1AGG2.SetStyle(Curve.FIRM);
k1AGG2.SetDefaultColor(CreateColor(255, 43, 43));
k1AGG2.SetLineWeight(2);
k1AGG2.SetStyle(Curve.FIRM);

plot T2agg2 = if showT18agg2 then Tenkan18agg2 else Double.NaN;
plot k2agg2 = if showK52agg2 then Kijun52agg2 else Double.NaN;
T2agg2.SetDefaultColor(CreateColor(99, 211, 146));
T2agg2.SetLineWeight(2);
T2agg2.SetStyle(Curve.LONG_DASH);
k2agg2.SetDefaultColor(CreateColor(148, 19, 19));
k2agg2.SetLineWeight(3);
k2agg2.SetStyle(Curve.LONG_DASH);
# ============== CLOUDS =====================

#AddCloud( tenkan2, kijun6,    createColor(138,223,206),      createColor(204,30,30));   #*
########################################################
#AddCloud( Tenkan4, Kijun13,     CreateColor(26, 201, 143),      CreateColor(230, 34, 34));  #*
#AddCloud( Tenkan4, Kijun52,     CreateColor(155, 233, 207),      CreateColor(255, 121, 121));  #*
######################################################

#AddCloud( tenkan2, kijun6,    createColor(127,243,212),      createColor(198,175,175));   #*
#AddCloud( tenkan4, kijun13,     CreateColor(169,248,221),      CreateColor(221,65,65));  #*
#AddCloud( tenkan4, kijun52,     CreateColor(57,186,100),      CreateColor(221,65,65));  #*

#AddCloud( A2,  B2,     CreateColor(97, 221, 138),       CreateColor(168, 102, 86));  #Cloud 1
#AddCloud( A3, B3,    CreateColor(73,196,128),      CreateColor(110,89,84));
#AddCloud( A4, B4 ,    CreateColor(36,149,87),      CreateColor(64,55,52));
#AddCloud( A5, B5 ,    CreateColor(6,78,38),      CreateColor(3,3,3));

########################################################
      #          Current cloud1a status & Breaks        #
##################################################
#def cloud1StatusAB = A1 > B1;
#def cloud1StatusABagg1 = A1agg1 > B1agg1;
#def cloud1StatusABagg2 = A1agg2 > B1agg2;

#def cloud1StatusBA = A1 < B1;
#def cloud1StatusBAagg1 = A1agg1 < B1agg1;
#def cloud1StatusBAagg2 = A1agg2 < B1agg2;

#def closePriceLongCloud1 = cloud1StatusAB and close > A1 or cloud1StatusBA and close > B1;
#def closePriceLongCloud1agg1 = cloud1StatusABagg1 and close(period = agg1) > A1agg1 or cloud1StatusBAagg1 and close(period = agg1) > B1agg1;
#def closePriceLongCloud1agg2 = cloud1StatusABagg2 and close(period = agg2) > A1agg2 or cloud1StatusBAagg2 and close(period = agg2) > B1agg2;

#def closePriceShortCloud1 = cloud1StatusAB and close < B1 or cloud1StatusBA and close < A1;
#def closePriceShortCloud1agg1 = cloud1StatusABagg1 and close(period = agg1) < B1agg1 or cloud1StatusBAagg1 and close(period = agg1) < A1agg1;
#def closePriceShortCloud1agg2 = cloud1StatusABagg2 and close(period = agg2) < B1agg2 or cloud1StatusBAagg2 and close(period = agg2) < A1agg2;
###
#def cloud2StatusAB = A2 > B2;
#def cloud2StatusABagg1 = A2agg1 > B2agg1;
#def cloud2StatusABagg2 = A2agg2 > B2agg2;

#def cloud2StatusBA = A2 < B2;
#def cloud2StatusBAagg1 = A2agg1 < B2agg1;
#def cloud2StatusBAagg2 = A2agg2 < B2agg2;

#def closePriceLongCloud2 = cloud2StatusAB and close > A2 or cloud2StatusBA and close > B2;
#def closePriceLongCloud2agg1 = cloud2StatusABagg1 and close(period = agg1) > A2agg1 or cloud2StatusBAagg1 and close(period = agg1) > B2agg1;
#def closePriceLongCloud2agg2 = cloud2StatusABagg2 and close(period = agg2) > A2agg2 or cloud2StatusBAagg2 and close(period = agg2) > B2agg2;

#def closePriceShortCloud2 = cloud2StatusAB and close < B2 or cloud2StatusBA and close < A2;
#def closePriceShortCloud2agg1 = cloud2StatusABagg1 and close(period = agg1) < B2agg1 or cloud2StatusBAagg1 and close(period = agg1) < A2agg1;
#def closePriceShortCloud2agg2 = cloud2StatusABagg2 and close(period = agg2) < B2agg2 or cloud2StatusBAagg2 and close(period = agg2) < A2agg2;
###
#def cloud3StatusAB = A3 > B3;
#def cloud3StatusABagg1 = A3agg1 > B3agg1;
#def cloud3StatusABagg2 = A3agg2 > B3agg2;

#def cloud3StatusBA = A3 < B3;
#def cloud3StatusBAagg1 = A3agg1 < B3agg1;
#def cloud3StatusBAagg2 = A3agg2 < B3agg2;

#def closePriceLongCloud3 = cloud3StatusAB and close > A3 or cloud3StatusBA and close > B3;
#def closePriceLongCloud3agg1 = cloud3StatusABagg1 and close(period = agg1) > A3agg1 or cloud3StatusBAagg1 and close(period = agg1) > B3agg1;
#def closePriceLongCloud3agg2 = cloud3StatusABagg2 and close(period = agg2) > A3agg2 or cloud3StatusBAagg2 and close(period = agg2) > B3agg2;

#def closePriceShortCloud3 = cloud3StatusAB and close < B3 or cloud3StatusBA and close < A3;
#def closePriceShortCloud3agg1 = cloud3StatusABagg1 and close(period = agg1) < B3agg1 or cloud3StatusBAagg1 and close(period = agg1) < A3agg1;
#def closePriceShortCloud3agg2 = cloud3StatusABagg2 and close(period = agg2) < B3agg2 or cloud3StatusBAagg2 and close(period = agg2) < A3agg2;
###
#def cloud4StatusAB = A4 > B4;
#def cloud4StatusABagg1 = A4agg1 > B4agg1;
#def cloud4StatusABagg2 = A4agg2 > B4agg2;

#def cloud4StatusBA = A4 < B4;
#def cloud4StatusBAagg1 = A4agg1 < B4agg1;
#def cloud4StatusBAagg2 = A4agg2 < B4agg2;

#def closePriceLongCloud4 = cloud4StatusAB and close > A4 or cloud4StatusBA and close > B4;
#def closePriceLongCloud4agg1 = cloud4StatusABagg1 and close(period = agg1) > A4agg1 or cloud4StatusBAagg1 and close(period = agg1) > B4agg1;
#def closePriceLongCloud4agg2 = cloud4StatusABagg2 and close(period = agg2) > A4agg2 or cloud4StatusBAagg2 and close(period = agg2) > B4agg2;

#def closePriceShortCloud4 = cloud4StatusAB and close < B4 or cloud4StatusBA and close < A4;
#def closePriceShortCloud4agg1 = cloud4StatusABagg1 and close(period = agg1) < B4agg1 or cloud4StatusBAagg1 and close(period = agg1) < A4agg1;
#def closePriceShortCloud4agg2 = cloud4StatusABagg2 and close(period = agg2) < B4agg2 or cloud4StatusBAagg2 and close(period = agg2) < A4agg2;
###
#def cloud5StatusAB = A5 > B5;
#def cloud5StatusABagg1 = A5agg1 > B5agg1;
#def cloud5StatusABagg2 = A5agg2 > B5agg2;

#def cloud5StatusBA = A5 < B5;
#def cloud5StatusBAagg1 = A5agg1 < B5agg1;
#def cloud5StatusBAagg2 = A5agg2 < B5agg2;

#def closePriceLongCloud5 = cloud5StatusAB and close > A5 or cloud5StatusBA and close > B5;
#def closePriceLongCloud5agg1 = cloud5StatusABagg1 and close(period = agg1) > A5agg1 or cloud5StatusBAagg1 and close(period = agg1) > B5agg1;
#def closePriceLongCloud5agg2 = cloud5StatusABagg1 and close(period = agg2) > A5agg2 or cloud5StatusBAagg2 and close(period = agg2) > B5agg2;

#def closePriceShortCloud5 = cloud5StatusAB and close < B5 or cloud5StatusBA and close < A5;
#def closePriceShortCloud5agg1 = cloud5StatusABagg1 and close(period = agg1) < B5agg1 or cloud5StatusBAagg1 and close(period = agg1) < A5agg1;
#def closePriceShortCloud5agg2 = cloud5StatusABagg2 and close(period = agg2) < B5agg2 or cloud5StatusBAagg2 and close(period = agg2) < A5agg2;

#######################################################
#            TRIGGERS                               #
#######################################################

########################################################
       #             Longs        #
##################################################
#def T2B1KumoLong = Tenkan2 > B1;
#def T2B1KumoLongagg1 = Tenkan2agg1 > B1agg1;
#def T2B1KumoLongagg2 = Tenkan2agg2 > B1agg2;
###
#def T4B2KumoLong = Tenkan4 > B2;
#def T4B2KumoLongagg1 = Tenkan4agg1 > B2agg1;
#def T4B2KumoLongagg2 = Tenkan4agg2 > B2agg2;
###
#def TKL4_13 = Tenkan4 > Kijun13;  #***
#def TKL4_13agg1 = Tenkan4agg1 > Kijun13agg1;  #***
#def TKL4_13agg2 = Tenkan4agg2 > Kijun13agg2;  #***
###
#def TKL9_26 = Tenkan9 > Kijun26;
#def TKL9_26agg1 = Tenkan9agg1 > Kijun26agg1;
#def TKL9_26agg2 = Tenkan9agg2 > Kijun26agg2;
###
#def TKL4_52 = Tenkan4 > Kijun52;
#def TKL4_52agg1 = Tenkan4agg1 > Kijun52agg1;
#def TKL4_52agg2 = Tenkan4agg2 > Kijun52agg2;
###
#def CloseK13Long = close > Kijun13;
#def CloseK13Longagg1 = close(period = Agg1) > Kijun13agg1;
#def CloseK13Longagg2 = close(period = Agg2) > Kijun13agg2;
###
#def CloseK52Long = close > Kijun52;  #***
#def CloseK52Longagg1 = close(period = Agg1) > Kijun52agg1;  #***
#def CloseK52Longagg2 = close(period = Agg2) > Kijun52agg2;  #***
###
#def CloseK78Long = close > Kijun78;
#def CloseK78Longagg1 = close(period = Agg1) > Kijun78agg1;
#def CloseK78Longagg2 = close(period = Agg2) > Kijun78agg2;
###


#def LagL = Chikou[52] > close[26];
def FutureBullishCloudA = A1[-8.66] > B1[-8.66];
def FutureBullishCloudB = A2[-13] > B2[-13];
def FutureBullishCloudC = A3[-26] > B3[-26];
def FutureBullishCloudD = A4[-52] > B4[-52];
def FutureBullishCloudE = A5[-78] > B5[-78];

def FutureBullishCloudAagg1 = A1agg1[-8.66] > B1agg1[-8.66];
def FutureBullishCloudBagg1  = A2agg1[-13] > B2agg1[-13];
def FutureBullishCloudCagg1  = A3agg1[-26] > B3agg1[-26];
def FutureBullishCloudDagg1  = A4agg1[-52] > B4agg1[-52];
def FutureBullishCloudEagg1  = A5agg1[-78] > B5agg1[-78];

def FutureBullishCloudAagg2 = A1agg2[-8.66] > B1agg2[-8.66];
def FutureBullishCloudBagg2  = A2agg2[-13] > B2agg2[-13];
def FutureBullishCloudCagg2  = A3agg2[-26] > B3agg2[-26];
def FutureBullishCloudDagg2  = A4agg2[-52] > B4agg2[-52];
def FutureBullishCloudEagg2  = A5agg2[-78] > B5agg2[-78];

def Lag1L = Chikou13[13] > chikou6[13];
def Lag2L = Chikou26[26] > chikou13[26];
def Lag3L = Chikou52[52] > chikou26[52];
def Lag4L = Chikou78[78] > chikou52[78];

def Lag1LAGG1 = Chikou13AGG1[13] > chikou6agg1[13];
def Lag2LAGG1 = Chikou26AGG1[26] > chikou13agg1[26];
def Lag3LAGG1 = Chikou52AGG1[52] > chikou26agg1[52];
def Lag4LAGG1 = Chikou78AGG1[78] > chikou52agg1[78];

def Lag1LAGG2 = Chikou13AGG2[13] > chikou6agg2[13];
def Lag2LAGG2 = Chikou26AGG2[26] > chikou13agg2[26];
def Lag3LAGG2 = Chikou52AGG2[52] > chikou26agg2[52];
def Lag4LAGG2 = Chikou78AGG2[78] > chikou52agg2[78];

def ChikouL = Lag1L and Lag2L and Lag3L and Lag4L;
def ChikouLagg1 = Lag1Lagg1 and Lag2Lagg1 and Lag3Lagg1 and Lag4Lagg1;
def ChikouLagg2 = Lag1Lagg2 and Lag2Lagg2 and Lag3Lagg2 and Lag4Lagg2;

def FutureBearishCloudA = A1[-8.66] < B1[-8.66];
def FutureBearishCloudB = A2[-13] < B2[-13];
def FutureBearishCloudC = A3[-26] < B3[-26];
def FutureBearishCloudD = A4[-52] < B4[-52];
def FutureBearishCloudE = A5[-78] < B5[-78];

def FutureBearishCloudAagg1 = A1agg1[-8.66] < B1agg1[-8.66];
def FutureBearishCloudBagg1  = A2agg1[-13] < B2agg1[-13];
def FutureBearishCloudCagg1  = A3agg1[-26] < B3agg1[-26];
def FutureBearishCloudDagg1  = A4agg1[-52] < B4agg1[-52];
def FutureBearishCloudEagg1  = A5agg1[-78] < B5agg1[-78];

def FutureBearishCloudAagg2 = A1agg2[-8.66] < B1agg2[-8.66];
def FutureBearishCloudBagg2  = A2agg2[-13] < B2agg2[-13];
def FutureBearishCloudCagg2  = A3agg2[-26] < B3agg2[-26];
def FutureBearishCloudDagg2  = A4agg2[-52] < B4agg2[-52];
def FutureBearishCloudEagg2  = A5agg2[-78] < B5agg2[-78];

def Lag1S = Chikou13[13] < chikou6[13];
def Lag2S = Chikou26[26] < chikou13[26];
def Lag3S = Chikou52[52] < chikou26[52];
def Lag4S = Chikou78[78] < chikou52[78];

def Lag1SAGG1 = Chikou13AGG1[13] < chikou6agg1[13];
def Lag2SAGG1 = Chikou26AGG1[26] < chikou13agg1[26];
def Lag3SAGG1 = Chikou52AGG1[52] < chikou26agg1[52];
def Lag4SAGG1 = Chikou78AGG1[78] < chikou52agg1[78];

def Lag1SAGG2 = Chikou13AGG2[13] < chikou6agg2[13];
def Lag2SAGG2 = Chikou26AGG2[26] < chikou13agg2[26];
def Lag3SAGG2 = Chikou52AGG2[52] < chikou26agg2[52];
def Lag4SAGG2 = Chikou78AGG2[78] < chikou52agg2[78];

def ChikouS = Lag1S and Lag2S and Lag3S and Lag4S;
def ChikouSagg1 = Lag1Sagg1 and Lag2Sagg1 and Lag3Sagg1 and Lag4Sagg1;
def ChikouSagg2 = Lag1Sagg2 and Lag2Sagg2 and Lag3Sagg2 and Lag4Sagg2;

AddLabel(Spacer, "Clouds  ", Color.GRAY);

AddLabel(showchartlabels, if FutureBullishCloudA then "A" else if FutureBearishCloudA then "A" else "", if FutureBullishCloudA then CreateColor(63, 187, 93) else if FutureBearishCloudA then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels, if FutureBullishCloudB then "B" else if FutureBearishCloudB then "B" else "", if FutureBullishCloudB then CreateColor(63, 187, 93) else if FutureBearishCloudB then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels, if FutureBullishCloudC then "C" else if FutureBearishCloudC then "C" else "", if FutureBullishCloudC then CreateColor(63, 187, 93) else if FutureBearishCloudC then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels, if FutureBullishCloudD then "D" else if FutureBearishCloudD then "D" else "", if FutureBullishCloudD then CreateColor(63, 187, 93) else if FutureBearishCloudD then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels, if FutureBullishCloudE then "E" else if FutureBearishCloudE then "E" else "", if FutureBullishCloudE then CreateColor(63, 187, 93) else if FutureBearishCloudE then CreateColor(191, 42, 42) else Color.DARK_GRAY);

#AddLabel(Spacer, "     ", color.DARK_GRAY);

#AddLabel(showchartlabels , if ChikouL then "LAG"   else if ChikouS then "LAG"   else "", if ChikouL  then CreateColor(63, 187, 93) else if ChikouS  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showchartlabels , if Lag1L then "13"   else if Lag1S then "13"   else "", if Lag1L  then CreateColor(63, 187, 93) else if Lag1S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showchartlabels , if Lag2L then "26"   else if Lag2S then "26"   else "", if Lag2L  then CreateColor(63, 187, 93) else if Lag2S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showchartlabels , if Lag3L then "52"   else if Lag3S then "52"   else "", if Lag3L  then CreateColor(63, 187, 93) else if Lag3S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showchartlabels , if Lag4L then "78"   else if Lag4S then "78"   else "", if Lag4L  then CreateColor(63, 187, 93) else if Lag4S  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(Spacer, "     ", color.DARK_GRAY);

AddLabel(showagg1Labels, if FutureBullishCloudAagg1 then "A" else if FutureBearishCloudAagg1 then "A" else "", if FutureBullishCloudAagg1 then CreateColor(63, 187, 93) else if FutureBearishCloudAagg1 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg1Labels, if FutureBullishCloudBagg1 then "B" else if FutureBearishCloudBagg1 then "B" else "", if FutureBullishCloudBagg1 then CreateColor(63, 187, 93) else if FutureBearishCloudBagg1 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg1Labels, if FutureBullishCloudCagg1 then "C" else if FutureBearishCloudCagg1 then "C" else "", if FutureBullishCloudCagg1 then CreateColor(63, 187, 93) else if FutureBearishCloudCagg1 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg1Labels, if FutureBullishCloudDagg1 then "D" else if FutureBearishCloudDagg1 then "D" else "", if FutureBullishCloudDagg1 then CreateColor(63, 187, 93) else if FutureBearishCloudDagg1 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg1Labels, if FutureBullishCloudEagg1 then "E" else if FutureBearishCloudEagg1 then "E" else "", if FutureBullishCloudEagg1 then CreateColor(63, 187, 93) else if FutureBearishCloudEagg1 then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(Spacer, "     ", color.DARK_GRAY);


AddLabel(showagg1Labels , if Lag1Lagg1 then "13"   else if Lag1Sagg1 then "13"   else "", if Lag1Lagg1  then CreateColor(63, 187, 93) else if Lag1Sagg1  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showagg1Labels , if Lag2Lagg1 then "26"   else if Lag2Sagg1 then "26"   else "", if Lag2Lagg1  then CreateColor(63, 187, 93) else if Lag2Sagg1  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showagg1Labels , if Lag3Lagg1 then "52"   else if Lag3Sagg1 then "52"   else "", if Lag3Lagg1  then CreateColor(63, 187, 93) else if Lag3Sagg1  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showagg1Labels , if Lag4Lagg1 then "78"   else if Lag4Sagg1 then "78"   else "", if Lag4Lagg1  then CreateColor(63, 187, 93) else if Lag4Sagg1  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(Spacer, "     ", color.DARK_GRAY);

AddLabel(showagg2Labels, if FutureBullishCloudAagg2 then "A" else if FutureBearishCloudAagg2 then "A" else "", if FutureBullishCloudAagg2 then CreateColor(63, 187, 93) else if FutureBearishCloudAagg2 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg2Labels, if FutureBullishCloudBagg2 then "B" else if FutureBearishCloudBagg2 then "B" else "", if FutureBullishCloudBagg2 then CreateColor(63, 187, 93) else if FutureBearishCloudBagg2 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg2Labels, if FutureBullishCloudCagg2 then "C" else if FutureBearishCloudCagg2 then "C" else "", if FutureBullishCloudCagg2 then CreateColor(63, 187, 93) else if FutureBearishCloudCagg2 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg2Labels, if FutureBullishCloudDagg2 then "D" else if FutureBearishCloudDagg2 then "D" else "", if FutureBullishCloudDagg2 then CreateColor(63, 187, 93) else if FutureBearishCloudDagg2 then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(showagg2Labels, if FutureBullishCloudEagg2 then "E" else if FutureBearishCloudEagg2 then "E" else "", if FutureBullishCloudEagg2 then CreateColor(63, 187, 93) else if FutureBearishCloudEagg2 then CreateColor(191, 42, 42) else Color.DARK_GRAY);
#AddLabel(Spacer, "     ", color.DARK_GRAY);

AddLabel(showagg2Labels , if Lag1Lagg2 then "13"   else if Lag1Sagg2 then "13"   else "", if Lag1Lagg2  then CreateColor(63, 187, 93) else if Lag1Sagg2  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showagg2Labels , if Lag2Lagg2 then "26"   else if Lag2Sagg2 then "26"   else "", if Lag2Lagg2  then CreateColor(63, 187, 93) else if Lag2Sagg2  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showagg2Labels , if Lag3Lagg2 then "52"   else if Lag3Sagg2 then "52"   else " ", if Lag3Lagg2  then CreateColor(63, 187, 93) else if Lag3Sagg2  then CreateColor(191, 42, 42) else Color.DARK_GRAY);
AddLabel(showagg2Labels , if Lag4Lagg2 then "78"   else if Lag4Sagg2 then "78"   else " ", if Lag4Lagg2  then CreateColor(63, 187, 93) else if Lag4Sagg2  then CreateColor(191, 42, 42) else Color.DARK_GRAY);

AddLabel(Spacer, "---" + time1 + "---", color.DARK_GRAY);
AddLabel(Spacer, "---" + time2 + "---", color.DARK_GRAY);
 

Attachments

  • mOEIdl2.png
    mOEIdl2.png
    148.7 KB · Views: 410
Last edited:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

As a note, on Intraday Charts, WL columns, I leave extended hours ON....I may be wrong but I view the moves AH, PM to be important for the coming day.


The labels ABCD are the Dragon (Future) clouds status "A" = the Tenkan 3 Kijun 8 which should be removed, unless you want it

The 26, 52, 78 labels = Chickou Status - What you'd see on the Histogram
 
Last edited:
One other thing I forgot to mention is when adding this indicator to the chart, other than labels, you won't see anything.

Being there are so many options, check out the settings, enabling what you wish
 
NVDA today - 1-9-2023 with Lagging histogram and Tenkan/Span B cloud
qGsVWud.png
Where did you change the setting for your "down clouds" to turn red?

FYI...I spent all weekend backtesting this, and forward tested this morning on /ES...10 ticks here, 15-20 ticks there...it was amazing that it kept me out of bad trades and I had confidence that I was trading with the prevailing trend and avoiding head fakes
 
Where did you change the setting for your "down clouds" to turn red?

FYI...I spent all weekend backtesting this, and forward tested this morning on /ES...10 ticks here, 15-20 ticks there...it was amazing that it kept me out of bad trades and I had confidence that I was trading with the prevailing trend and avoiding head fakes
That's great..Are you referring to what makes the Lagging histogram Green or red?
 
I was referring to the Kumo Clouds on the chart itself. Mine are strictly Green and Grey
Hope this is what you're looking for..In the section below

Code:
##################################################################
#                   Dragon Cloud Plots                          #
##################################################################
#AddCloud(if showCloud1KUMO or ShowAllDragonClouds then A1 else Double.NaN, if showCloud1KUMO or ShowAllDragonClouds then B1 else Double.NaN, CreateColor(97, 221, 138), CreateColor(154,150,150));

#plot Cloud1a = if  ShowCloud1_KUMOLines then A1 else Double.NaN;
#Cloud1a.SetDefaultColor(CreateColor(136, 213, 94));
#Cloud1a.SetLineWeight(1);
#Cloud1a.SetStyle(Curve.LONG_DASH);

#plot Cloud1B = if  ShowCloud1_KUMOLines then B1 else Double.NaN;
#Cloud1B.SetDefaultColor(CreateColor(229, 49, 5));
#Cloud1B.SetLineWeight(1);
#Cloud1B.SetStyle(Curve.LONG_DASH);


AddCloud(if showcloud2KUMO or ShowAllDragonClouds then A2 else Double.NaN, if showcloud2KUMO or ShowAllDragonClouds then B2 else Double.NaN, CreateColor(97, 221, 138), CreateColor(129,125,125));

plot Cloud2a = if  ShowCloud2_KUMOLines then A2 else Double.NaN;
Cloud2a.SetDefaultColor(CreateColor(136, 213, 94));
Cloud2a.SetLineWeight(1);
Cloud2a.SetStyle(Curve.LONG_DASH);

plot Cloud2b = if  ShowCloud2_KUMOLines then B2 else Double.NaN;
Cloud2b.SetDefaultColor(CreateColor(229, 49, 5));
Cloud2b.SetLineWeight(1);
Cloud2b.SetStyle(Curve.LONG_DASH);

ezOe3R2.png
 
Where did you change the setting for your "down clouds" to turn red?

FYI...I spent all weekend backtesting this, and forward tested this morning on /ES...10 ticks here, 15-20 ticks there...it was amazing that it kept me out of bad trades and I had confidence that I was trading with the prevailing trend and avoiding head fakes
Ok, I wasn't thinking...The cloud in my post #7 is not the typical Kumo, span A/B cloud..

The cloud depicted is the Tenkan 2 > Span B
Tenkan 2 = 3
Span B/Kijun = 8.66

The Dragon clouds referred to above, post #11 are the typical, Kumo, future clouds you'd see on the Ichimoku, which is what you're referring to
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
228 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top