Sector Rotation Indicator for ThinkorSwim

See if this scan helps with what you need.

Code:
input CorrelationWithSecurity = "SPX";
input referenceDate = 20190531;
def close2 = close(CorrelationWithSecurity);

def RS = if close2 == 0 then 0 else close/close2;
#RS.setDefaultColor(GetColor(6));

def startDate = DaysFromDate(referenceDate) == 0;

addchartbubble(startDate, RS,"Start", color.RED);

def sr = CompoundValue("historical data" = RS[0], "visible data" = if startDate <= 0 then sr[1] else RS[0]);
def SRatio =  sr;
#SRatio.setDefaultColor(GetColor(5));

# use this plot statement to find bullish crossovers
#plot scan = RS[1] < SRatio[1] and RS > SRatio;

# use this plot statement to find bearish crossovers
#plot scan = RS[1] > SRatio[1] and RS < SRatio;

# use this plot statement to find stocks trending stronger than the index
plot scan =  lowest(RS - SRatio, 21) > 0;

# use this plot statement to find stocks trending weaker than the index
#plot scan =  highest(RS - SRatio, 21) < 0;

Also, use this lower study to comfirm.

Code:
declare lower;
input correlationTicker = "SPX";
input startDate = 20180928;
def beginTracking = DaysFromDate(startDate) == 0;
def correlationClose = close(symbol = correlationTicker);
def correlationPrctChange = 100 * (correlationClose / correlationClose[1] - 1);
def plottedPrctChange = 100 * (close / close[1] - 1);
def correlationDiff = plottedPrctChange - correlationPrctChange;
rec data = CompoundValue(1, if beginTracking then correlationDiff else if DaysFromDate(startDate) > 0 then data[1] + correlationDiff else 0, 0);
plot signal = data;
plot zeroline = 0;
AddVerticalLine(beginTracking, "Start", Color.YELLOW, 2);
ZeroLine.SetDefaultColor(GetColor(7));
 
See if this scan helps with what you need.

Code:
input CorrelationWithSecurity = "SPX";
input referenceDate = 20190531;
def close2 = close(CorrelationWithSecurity);

def RS = if close2 == 0 then 0 else close/close2;
#RS.setDefaultColor(GetColor(6));

def startDate = DaysFromDate(referenceDate) == 0;

addchartbubble(startDate, RS,"Start", color.RED);

def sr = CompoundValue("historical data" = RS[0], "visible data" = if startDate <= 0 then sr[1] else RS[0]);
def SRatio =  sr;
#SRatio.setDefaultColor(GetColor(5));

# use this plot statement to find bullish crossovers
#plot scan = RS[1] < SRatio[1] and RS > SRatio;

# use this plot statement to find bearish crossovers
#plot scan = RS[1] > SRatio[1] and RS < SRatio;

# use this plot statement to find stocks trending stronger than the index
plot scan =  lowest(RS - SRatio, 21) > 0;

# use this plot statement to find stocks trending weaker than the index
#plot scan =  highest(RS - SRatio, 21) < 0;

Also, use this lower study to comfirm.

Code:
declare lower;
input correlationTicker = "SPX";
input startDate = 20180928;
def beginTracking = DaysFromDate(startDate) == 0;
def correlationClose = close(symbol = correlationTicker);
def correlationPrctChange = 100 * (correlationClose / correlationClose[1] - 1);
def plottedPrctChange = 100 * (close / close[1] - 1);
def correlationDiff = plottedPrctChange - correlationPrctChange;
rec data = CompoundValue(1, if beginTracking then correlationDiff else if DaysFromDate(startDate) > 0 then data[1] + correlationDiff else 0, 0);
plot signal = data;
plot zeroline = 0;
AddVerticalLine(beginTracking, "Start", Color.YELLOW, 2);
ZeroLine.SetDefaultColor(GetColor(7));
Thank you mate, Do we need to change the date everyday?
 
No, Set both according to time agg that you wish to use.
ex. 1Y 1D =20200223 and you are all set

input referenceDate =20200223;

input startDate =20200223;
 
The layman's way. Lol I was interested to see how this would look.
Vn6xZgQ.png


If anyone one is insterested.
http://tos.mx/t71Peta
 
Hi Trendr

thank you . Did you perform any back testing with entry exit .
What are the entry exit places . If you can shoe one entry exit that would be a great help .
I wouldn't enter of these charts, they are to show you where the strength is then you would find stocks in those sectors at proper buy points (Pivots).
 
Last edited by a moderator:
Using Percent B Buckets From Edgerater to find Sector rotation, this uses 26 different index of ETF's
Code:
declare lower;
DefineGlobalColor("Buy", Color.GREEN);
DefineGlobalColor("Sell", Color.RED);
DefineGlobalColor("Neutral", Color.YELLOW);
DefineGlobalColor("Above", Color.Dark_Green);
DefineGlobalColor("Below", Color.Dark_Red);

input symbol26 = "NYA";
input symbol25 = "XAX";
input symbol24 = "IWB";
input symbol23 = "FFTY";
input symbol22 = "BOUT";
input symbol21 = "XTC";
input symbol20 = "SOX";
input symbol19 = "RUT";
input symbol18 = "RUI";
input symbol17 = "COMP:GIDS";
input symbol16 = "SPY";
input symbol15 = "QQQ";
input symbol14 = "IWM";
input symbol13 = "$DJT";
input symbol12 = "IBB";
input symbol11 = "XLY";
input symbol10 = "XLV";
input symbol9 = "XLU";
input symbol8 = "XLRE";
input symbol7 = "XLP";
input symbol6 = "XLK";
input symbol5 = "XLI";
input symbol4 = "XLF";
input symbol3 = "XLE";
input symbol2 = "XLC";
input symbol1 = "XLB";
input DotSize = 5;

input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input showLabels = yes;
input showBubbles = no;
script SymbolPB {
input symbol = "";
input averageType = AverageType.Simple;
def price = close(Symbol);
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).UpperBand;
def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).LowerBand;
plot PercentB = Round((price - lowerBand) / (upperBand - lowerBand) * 100,2);
}
def s1PB = SymbolPB(symbol1);
def s2PB = SymbolPB(symbol2);
def s3PB = SymbolPB(symbol3);
def s4PB = SymbolPB(symbol4);
def s5PB = SymbolPB(symbol5);
def s6PB = SymbolPB(symbol6);
def s7PB = SymbolPB(symbol7);
def s8PB = SymbolPB(symbol8);
def s9PB = SymbolPB(symbol9);
def s10PB = SymbolPB(symbol10);
def s11PB = SymbolPB(symbol11);
def s12PB = SymbolPB(symbol12);
def s13PB = SymbolPB(symbol13);
def s14PB = SymbolPB(symbol14);
def s15PB = SymbolPB(symbol15);
def s16PB = SymbolPB(symbol16);
def s17PB = SymbolPB(symbol17);
def s18PB = SymbolPB(symbol18);
def s19PB = SymbolPB(symbol19);
def s20PB = SymbolPB(symbol20);
def s21PB = SymbolPB(symbol21);
def s22PB = SymbolPB (symbol22);
def s23PB = SymbolPB(symbol23);
def s24PB = SymbolPB(symbol24);
def s25PB = SymbolPB(symbol25);
def s26PB = SymbolPB(symbol26);
#######Plots
plot symb1 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 1 else Double.NaN;
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
symb1.SetLineWeight(DotSize);
symb1.AssignValueColor(if s1PB >= 100 then GlobalColor("Above") else if s1PB<= 0 then GlobalColor(“Below”) else if s1PB >=70  then GlobalColor(“Buy”) else if s1PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol1)[1]), 1, "1: " + symbol1, if s1PB[1] >= 100 then GlobalColor("Above") else if s1PB[1]<= 0 then GlobalColor(“Below”) else if s1PB[1] >=70  then GlobalColor(“Buy”) else if s1PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb1.HideBubble();
plot symb2 = if !IsNaN(close) and !IsNaN(close(symbol2)) then 2 else Double.NaN;
symb2.SetPaintingStrategy(PaintingStrategy.POINTS);
symb2.SetLineWeight(DotSize);
symb2.AssignValueColor(if s2PB >= 100 then GlobalColor("Above") else if s2PB<= 0 then GlobalColor(“Below”) else if s2PB >=70  then GlobalColor(“Buy”) else if s2PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol2)[5]), 2, "2: " + symbol2, if s2PB[5] >= 100 then GlobalColor("Above") else if s2PB[5]<= 0 then GlobalColor(“Below”) else if s2PB[5] >=70  then GlobalColor(“Buy”) else if s2PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb2.HideBubble();
plot symb3 = if !IsNaN(close) and !IsNaN(close(symbol3)) then 3 else Double.NaN;
symb3.SetPaintingStrategy(PaintingStrategy.POINTS);
symb3.SetLineWeight(DotSize);
symb3.AssignValueColor(if s3PB >= 100 then GlobalColor("Above") else if s3PB<= 0 then GlobalColor(“Below”) else if s3PB >=70  then GlobalColor(“Buy”) else if s3PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol3)[1]), 3, "3: " + symbol3, if s3PB[1] >= 100 then GlobalColor("Above") else if s3PB[1]<= 0 then GlobalColor(“Below”) else if s3PB[1] >=70  then GlobalColor(“Buy”) else if s3PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb3.HideBubble();
plot symb4 = if !IsNaN(close) and !IsNaN(close(symbol4)) then 4 else Double.NaN;
symb4.SetPaintingStrategy(PaintingStrategy.POINTS);
symb4.SetLineWeight(DotSize);
symb4.AssignValueColor(if s4PB >= 100 then GlobalColor("Above") else if s4PB<= 0 then GlobalColor(“Below”) else if s4PB >=70  then GlobalColor(“Buy”) else if s4PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol4)[5]), 4, "4: " + symbol4, if s4PB[5] >= 100 then GlobalColor("Above") else if s4PB[5]<= 0 then GlobalColor(“Below”) else if s4PB[5] >=70  then GlobalColor(“Buy”) else if s4PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb4.HideBubble();
plot symb5 = if !IsNaN(close) and !IsNaN(close(symbol5)) then 5 else Double.NaN;
symb5.SetPaintingStrategy(PaintingStrategy.POINTS);
symb5.SetLineWeight(DotSize);
symb5.AssignValueColor(if s5PB >= 100 then GlobalColor("Above") else if s5PB<= 0 then GlobalColor(“Below”) else if s5PB >=70  then GlobalColor(“Buy”) else if s5PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol5)[1]), 5, "5: " + symbol5, if s5PB[1] >= 100 then GlobalColor("Above") else if s5PB[1]<= 0 then GlobalColor(“Below”) else if s5PB[1] >=70  then GlobalColor(“Buy”) else if s5PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb5.HideBubble();
plot symb6 = if !IsNaN(close) and !IsNaN(close(symbol6)) then 6 else Double.NaN;
symb6.SetPaintingStrategy(PaintingStrategy.POINTS);
symb6.SetLineWeight(DotSize);
symb6.AssignValueColor(if s6PB >= 100 then GlobalColor("Above") else if s6PB<= 0 then GlobalColor(“Below”) else if s6PB >=70  then GlobalColor(“Buy”) else if s6PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol6)[5]), 6, "6: " + symbol6, if s6PB[5] >= 100 then GlobalColor("Above") else if s6PB[5]<= 0 then GlobalColor(“Below”) else if s6PB[5] >=70  then GlobalColor(“Buy”) else if s6PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb6.HideBubble();
plot symb7 = if !IsNaN(close) and !IsNaN(close(symbol7)) then 7 else Double.NaN;
symb7.SetPaintingStrategy(PaintingStrategy.POINTS);
symb7.SetLineWeight(DotSize);
symb7.AssignValueColor(if s7PB >= 100 then GlobalColor("Above") else if s7PB<= 0 then GlobalColor(“Below”) else if s7PB >=70  then GlobalColor(“Buy”) else if s7PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol7)[1]), 7, "7: " + symbol7, if s7PB[1] >= 100 then GlobalColor("Above") else if s7PB[1]<= 0 then GlobalColor(“Below”) else if s7PB[1] >=70  then GlobalColor(“Buy”) else if s7PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb7.HideBubble();
plot symb8 = if !IsNaN(close) and !IsNaN(close(symbol8)) then 8 else Double.NaN;
symb8.SetPaintingStrategy(PaintingStrategy.POINTS);
symb8.SetLineWeight(DotSize);
symb8.AssignValueColor(if s8PB >= 100 then GlobalColor("Above") else if s8PB<= 0 then GlobalColor(“Below”) else if s8PB >=70  then GlobalColor(“Buy”) else if s8PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol8)[5]), 8, "8: " + symbol8, if s8PB[5] >= 100 then GlobalColor("Above") else if s8PB[5]<= 0 then GlobalColor(“Below”) else if s8PB[5] >=70  then GlobalColor(“Buy”) else if s8PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb8.HideBubble();
plot symb9 = if !IsNaN(close) and !IsNaN(close(symbol9)) then 9 else Double.NaN;
symb9.SetPaintingStrategy(PaintingStrategy.POINTS);
symb9.SetLineWeight(DotSize);
symb9.AssignValueColor(if s9PB >= 100 then GlobalColor("Above") else if s9PB<= 0 then GlobalColor(“Below”) else if s9PB >=70  then GlobalColor(“Buy”) else if s9PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol9)[1]), 9, "9: " + symbol9, if s9PB[1] >= 100 then GlobalColor("Above") else if s9PB[1]<= 0 then GlobalColor(“Below”) else if s9PB[1] >=70  then GlobalColor(“Buy”) else if s9PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb9.HideBubble();
plot symb10 = if !IsNaN(close) and !IsNaN(close(symbol10)) then 10 else Double.NaN;
symb10.SetPaintingStrategy(PaintingStrategy.POINTS);
symb10.SetLineWeight(DotSize);
symb10.AssignValueColor(if s10PB >= 100 then GlobalColor("Above") else if s10PB<= 0 then GlobalColor(“Below”) else if s10PB >=70  then GlobalColor(“Buy”) else if s10PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol10)[5]), 10, "10: " + symbol10, if s10PB[5] >= 100 then GlobalColor("Above") else if s10PB[5]<= 0 then GlobalColor(“Below”) else if s10PB[5] >=70  then GlobalColor(“Buy”) else if s10PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb10.HideBubble();
plot symb11 = if !IsNaN(close) and !IsNaN(close(symbol11)) then 11 else Double.NaN;
symb11.SetPaintingStrategy(PaintingStrategy.POINTS);
symb11.SetLineWeight(DotSize);
symb11.AssignValueColor(if s11PB >= 100 then GlobalColor("Above") else if s11PB<= 0 then GlobalColor(“Below”) else if s11PB >=70  then GlobalColor(“Buy”) else if s11PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol11)[1]), 11, "11: " + symbol11, if s11PB[1] >= 100 then GlobalColor("Above") else if s11PB[1]<= 0 then GlobalColor(“Below”) else if s11PB[1] >=70  then GlobalColor(“Buy”) else if s11PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb11.HideBubble();
plot symb12 = if !IsNaN(close) and !IsNaN(close(symbol12)) then 13 else Double.NaN;
symb12.SetPaintingStrategy(PaintingStrategy.Triangles);
symb12.SetLineWeight(DotSize);
symb12.AssignValueColor(if s12PB >= 100 then GlobalColor("Above") else if s12PB<= 0 then GlobalColor(“Below”) else if s12PB >=70  then GlobalColor(“Buy”) else if s12PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol12)[5]), 13, "13: " + symbol12, if s12PB[5] >= 100 then GlobalColor("Above") else if s12PB[5]<= 0 then GlobalColor(“Below”) else if s12PB[5] >=70  then GlobalColor(“Buy”) else if s12PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb12.HideBubble();
plot symb13 = if !IsNaN(close) and !IsNaN(close(symbol13)) then 14 else Double.NaN;
symb13.SetPaintingStrategy(PaintingStrategy.Triangles);
symb13.SetLineWeight(DotSize);
symb13.AssignValueColor(if s13PB >= 100 then GlobalColor("Above") else if s13PB<= 0 then GlobalColor(“Below”) else if s13PB >=70  then GlobalColor(“Buy”) else if s13PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol13)[1]), 14, "14: " + symbol13, if s13PB[1] >= 100 then GlobalColor("Above") else if s13PB[1]<= 0 then GlobalColor(“Below”) else if s13PB[1] >=70  then GlobalColor(“Buy”) else if s13PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb13.HideBubble();
plot symb14 = if !IsNaN(close) and !IsNaN(close(symbol14)) then 15 else Double.NaN;
symb14.SetPaintingStrategy(PaintingStrategy.Triangles);
symb14.SetLineWeight(DotSize);
symb14.AssignValueColor(if s14PB >= 100 then GlobalColor("Above") else if s14PB<= 0 then GlobalColor(“Below”) else if s14PB >=70  then GlobalColor(“Buy”) else if s14PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol14)[5]), 15, "15: " + symbol14, if s14PB[5] >= 100 then GlobalColor("Above") else if s14PB[5]<= 0 then GlobalColor(“Below”) else if s14PB[5] >=70  then GlobalColor(“Buy”) else if s14PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb14.HideBubble();
plot symb15 = if !IsNaN(close) and !IsNaN(close(symbol15)) then 16 else Double.NaN;
symb15.SetPaintingStrategy(PaintingStrategy.Triangles);
symb15.SetLineWeight(DotSize);
symb15.AssignValueColor(if s15PB >= 100 then GlobalColor("Above") else if s15PB<= 0 then GlobalColor(“Below”) else if s15PB >=70  then GlobalColor(“Buy”) else if s15PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol15)[1]), 16, "16: " + symbol15, if s15PB[1] >= 100 then GlobalColor("Above") else if s15PB[1]<= 0 then GlobalColor(“Below”) else if s15PB[1] >=70  then GlobalColor(“Buy”) else if s15PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb15.HideBubble();
plot symb16 = if !IsNaN(close) and !IsNaN(close(symbol16)) then 17 else Double.NaN;
symb16.SetPaintingStrategy(PaintingStrategy.Triangles);
symb16.SetLineWeight(DotSize);
symb16.AssignValueColor(if s16PB >= 100 then GlobalColor("Above") else if s16PB<= 0 then GlobalColor(“Below”) else if s16PB >=70  then GlobalColor(“Buy”) else if s16PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol16)[5]), 17, "17: " + symbol16, if s16PB[5] >= 100 then GlobalColor("Above") else if s16PB[5]<= 0 then GlobalColor(“Below”) else if s16PB[5] >=70  then GlobalColor(“Buy”) else if s16PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb16.HideBubble();
plot symb17 = if !IsNaN(close) and !IsNaN(close(symbol17)) then 18 else Double.NaN;
symb17.SetPaintingStrategy(PaintingStrategy.Triangles);
symb17.SetLineWeight(DotSize);
symb17.AssignValueColor(if s17PB >= 100 then GlobalColor("Above") else if s17PB<= 0 then GlobalColor(“Below”) else if s17PB >=70  then GlobalColor(“Buy”) else if s17PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol17)[1]), 18, "18: " + symbol17, if s17PB[1] >= 100 then GlobalColor("Above") else if s17PB[1]<= 0 then GlobalColor(“Below”) else if s17PB[1] >=70  then GlobalColor(“Buy”) else if s17PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb17.HideBubble();
plot symb18 = if !IsNaN(close) and !IsNaN(close(symbol18)) then 19 else Double.NaN;
symb18.SetPaintingStrategy(PaintingStrategy.Triangles);
symb18.SetLineWeight(DotSize);
symb18.AssignValueColor(if s18PB >= 100 then GlobalColor("Above") else if s18PB<= 0 then GlobalColor(“Below”) else if s18PB >=70  then GlobalColor(“Buy”) else if s18PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol18)[5]), 19, "19: " + symbol18, if s18PB[5] >= 100 then GlobalColor("Above") else if s18PB[5]<= 0 then GlobalColor(“Below”) else if s18PB[5] >=70  then GlobalColor(“Buy”) else if s18PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb18.HideBubble();
plot symb19 = if !IsNaN(close) and !IsNaN(close(symbol19)) then 20 else Double.NaN;
symb19.SetPaintingStrategy(PaintingStrategy.Triangles);
symb19.SetLineWeight(DotSize);
symb19.AssignValueColor(if s19PB >= 100 then GlobalColor("Above") else if s19PB<= 0 then GlobalColor(“Below”) else if s19PB >=70  then GlobalColor(“Buy”) else if s19PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol19)[1]), 20, "20: " + symbol19, if s19PB[1] >= 100 then GlobalColor("Above") else if s19PB[1]<= 0 then GlobalColor(“Below”) else if s19PB[1] >=70  then GlobalColor(“Buy”) else if s19PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb19.HideBubble();
plot symb20 = if !IsNaN(close) and !IsNaN(close(symbol20)) then 21 else Double.NaN;
symb20.SetPaintingStrategy(PaintingStrategy.Triangles);
symb20.SetLineWeight(DotSize);
symb20.AssignValueColor(if s20PB >= 100 then GlobalColor("Above") else if s20PB<= 0 then GlobalColor(“Below”) else if s20PB >=70  then GlobalColor(“Buy”) else if s20PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol20)[5]), 21, "21: " + symbol20, if s20PB[5] >= 100 then GlobalColor("Above") else if s20PB[5]<= 0 then GlobalColor(“Below”) else if s20PB[5] >=70  then GlobalColor(“Buy”) else if s20PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb20.HideBubble();
plot symb21 = if !IsNaN(close) and !IsNaN(close(symbol21)) then 22 else Double.NaN;
symb21.SetPaintingStrategy(PaintingStrategy.Triangles);
symb21.SetLineWeight(DotSize);
symb21.AssignValueColor(if s21PB >= 100 then GlobalColor("Above") else if s21PB<= 0 then GlobalColor(“Below”) else if s21PB >=70  then GlobalColor(“Buy”) else if s21PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol21)[1]), 22, "22: " + symbol21, if s21PB[1] >= 100 then GlobalColor("Above") else if s21PB[1]<= 0 then GlobalColor(“Below”) else if s21PB[1] >=70  then GlobalColor(“Buy”) else if s21PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb21.HideBubble();
plot symb22 = if !IsNaN(close) and !IsNaN(close(symbol22)) then 23 else Double.NaN;
symb22.SetPaintingStrategy(PaintingStrategy.Triangles);
symb22.SetLineWeight(DotSize);
symb22.AssignValueColor(if s22PB >= 100 then GlobalColor("Above") else if s22PB<= 0 then GlobalColor(“Below”) else if s22PB >=70  then GlobalColor(“Buy”) else if s22PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol22)[5]), 23, "23: " + symbol22, if s22PB[5] >= 100 then GlobalColor("Above") else if s22PB[5]<= 0 then GlobalColor(“Below”) else if s22PB[5] >=70  then GlobalColor(“Buy”) else if s22PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb22.HideBubble();
plot symb23 = if !IsNaN(close) and !IsNaN(close(symbol23)) then 24 else Double.NaN;
symb23.SetPaintingStrategy(PaintingStrategy.Triangles);
symb23.SetLineWeight(DotSize);
symb23.AssignValueColor(if s23PB >= 100 then GlobalColor("Above") else if s23PB<= 0 then GlobalColor(“Below”) else if s23PB >=70  then GlobalColor(“Buy”) else if s23PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol23)[1]), 24, "24: " + symbol23, if s23PB[1] >= 100 then GlobalColor("Above") else if s23PB[1]<= 0 then GlobalColor(“Below”) else if s23PB[1] >=70  then GlobalColor(“Buy”) else if s23PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb23.HideBubble();
plot symb24 = if !IsNaN(close) and !IsNaN(close(symbol24)) then 25 else Double.NaN;
symb24.SetPaintingStrategy(PaintingStrategy.Triangles);
symb24.SetLineWeight(DotSize);
symb24.AssignValueColor(if s24PB >= 100 then GlobalColor("Above") else if s24PB<= 0 then GlobalColor(“Below”) else if s24PB >=70  then GlobalColor(“Buy”) else if s24PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol24)[5]), 25, "25: " + symbol24, if s24PB[5] >= 100 then GlobalColor("Above") else if s24PB[5]<= 0 then GlobalColor(“Below”) else if s24PB[5] >=70  then GlobalColor(“Buy”) else if s24PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb24.HideBubble();
plot symb25 = if !IsNaN(close) and !IsNaN(close(symbol25)) then 26 else Double.NaN;
symb25.SetPaintingStrategy(PaintingStrategy.Triangles);
symb25.SetLineWeight(DotSize);
symb25.AssignValueColor(if s25PB >= 100 then GlobalColor("Above") else if s25PB<= 0 then GlobalColor(“Below”) else if s25PB >=70  then GlobalColor(“Buy”) else if s25PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol25)[1]), 26, "26: " + symbol25, if s25PB[1] >= 100 then GlobalColor("Above") else if s25PB[1]<= 0 then GlobalColor(“Below”) else if s25PB[1] >=70  then GlobalColor(“Buy”) else if s25PB[1] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
Symb25.HideBubble();
plot symb26 = if !IsNaN(close) and !IsNaN(close(symbol26)) then 27 else Double.NaN;
symb26.SetPaintingStrategy(PaintingStrategy.Triangles);
symb26.SetLineWeight(DotSize);
symb26.AssignValueColor(if s26PB >= 100 then GlobalColor("Above") else if s26PB<= 0 then GlobalColor(“Below”) else if s26PB >=70  then GlobalColor(“Buy”) else if s26PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol26)[5]), 27, "27: " + symbol26, if s26PB[5] >= 100 then GlobalColor("Above") else if s26PB[5]<= 0 then GlobalColor(“Below”) else if s26PB[5] >=70  then GlobalColor(“Buy”) else if s26PB[5] <30 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb26.HideBubble();
plot spacer0 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 0.5 else Double.NaN;
plot spacer1 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 1.5 else Double.NaN;
plot spacer2 = if !IsNaN(close) and !IsNaN(close(symbol2)) then 2.5 else Double.NaN;
plot spacer3 = if !IsNaN(close) and !IsNaN(close(symbol3)) then 3.5 else Double.NaN;
plot spacer4 = if !IsNaN(close) and !IsNaN(close(symbol4)) then 4.5 else Double.NaN;
plot spacer5 = if !IsNaN(close)  and !IsNaN(close(symbol5)) then 5.5 else Double.NaN;
plot spacer6 = if !IsNaN(close) and !IsNaN(close(symbol6)) then 6.5 else Double.NaN;
plot spacer7 = if !IsNaN(close) and !IsNaN(close(symbol7)) then 7.5 else Double.NaN;
plot spacer8 = if !IsNaN(close) and !IsNaN(close(symbol8)) then 8.5 else Double.NaN;
plot spacer9 = if !IsNaN(close) and !IsNaN(close(symbol9)) then 9.5 else Double.NaN;
plot spacer10 = if !IsNaN(close) and !IsNaN(close(symbol10)) then 10.5 else Double.NaN;
plot spacer11 = if !IsNaN(close)  and !IsNaN(close(symbol11)) then 11.5 else Double.NaN;
plot spacer12 = if !IsNaN(close) and !IsNaN(close(symbol12)) then 12.5 else Double.NaN;
plot spacer13 = if !IsNaN(close) and !IsNaN(close(symbol13)) then 13.5 else Double.NaN;
plot spacer14 = if !IsNaN(close) and !IsNaN(close(symbol14)) then 14.5 else Double.NaN;
plot spacer15 = if !IsNaN(close) and !IsNaN(close(symbol15)) then 15.5 else Double.NaN;
plot spacer16 = if !IsNaN(close) and !IsNaN(close(symbol16)) then 16.5 else Double.NaN;
plot spacer17 = if !IsNaN(close) and !IsNaN(close(symbol17)) then 17.5 else Double.NaN;
plot spacer18 = if !IsNaN(close) and !IsNaN(close(symbol18)) then 18.5 else Double.NaN;
plot spacer19 = if !IsNaN(close) and !IsNaN(close(symbol19)) then 19.5 else Double.NaN;
plot spacer20 = if !IsNaN(close) and !IsNaN(close(symbol20)) then 20.5 else Double.NaN;
plot spacer21 = if !IsNaN(close)  and !IsNaN(close(symbol21)) then 21.5 else Double.NaN;
plot spacer22 = if !IsNaN(close) and !IsNaN(close(symbol22)) then 22.5 else Double.NaN;
plot spacer23 = if !IsNaN(close) and !IsNaN(close(symbol23)) then 23.5 else Double.NaN;
plot spacer24 = if !IsNaN(close) and !IsNaN(close(symbol24)) then 24.5 else Double.NaN;
plot spacer25 = if !IsNaN(close) and !IsNaN(close(symbol25)) then 25.5 else Double.NaN;
plot spacer26 = if !IsNaN(close) and !IsNaN(close(symbol26)) then 26.5 else Double.NaN;

spacer0.SetDefaultColor(Color.GRAY);
spacer1.SetDefaultColor(Color.GRAY);
spacer2.SetDefaultColor(Color.GRAY);
spacer3.SetDefaultColor(Color.GRAY);
spacer4.SetDefaultColor(Color.GRAY);
spacer5.SetDefaultColor(Color.GRAY);
spacer6.SetDefaultColor(Color.GRAY);
spacer7.SetDefaultColor(Color.GRAY);
spacer8.SetDefaultColor(Color.GRAY);
spacer9.SetDefaultColor(Color.GRAY);
spacer10.SetDefaultColor(Color.GRAY);
spacer11.SetDefaultColor(Color.GRAY);
spacer12.SetDefaultColor(Color.GRAY);
spacer13.SetDefaultColor(Color.GRAY);
spacer14.SetDefaultColor(Color.GRAY);
spacer15.SetDefaultColor(Color.GRAY);
spacer16.SetDefaultColor(Color.GRAY);
spacer17.SetDefaultColor(Color.GRAY);
spacer18.SetDefaultColor(Color.GRAY);
spacer19.SetDefaultColor(Color.GRAY);
spacer20.SetDefaultColor(Color.GRAY);
spacer21.SetDefaultColor(Color.GRAY);
spacer22.SetDefaultColor(Color.GRAY);
spacer23.SetDefaultColor(Color.GRAY);
spacer24.SetDefaultColor(Color.GRAY);
spacer25.SetDefaultColor(Color.GRAY);
spacer26.SetDefaultColor(Color.GRAY);

spacer0.HideBubble();
spacer1.HideBubble();
spacer2.HideBubble();
spacer3.HideBubble();
spacer4.HideBubble();
spacer5.HideBubble();
spacer6.HideBubble();
spacer7.HideBubble();
spacer8.HideBubble();
spacer9.HideBubble();
spacer10.HideBubble();
spacer11.HideBubble();
spacer12.HideBubble();
spacer13.HideBubble();
spacer14.HideBubble();
spacer15.HideBubble();
spacer16.HideBubble();
spacer17.HideBubble();
spacer18.HideBubble();
spacer19.HideBubble();
spacer20.HideBubble();
spacer21.HideBubble();
spacer22.HideBubble();
spacer23.HideBubble();
spacer24.HideBubble();
spacer25.HideBubble();
spacer26.HideBubble();
spacer0.HideTitle();
spacer1.HideTitle();
spacer2.HideTitle();
spacer3.HideTitle();
spacer4.HideTitle();
spacer5.HideTitle();
spacer6.HideTitle();
spacer7.HideTitle();
spacer8.HideTitle();
spacer9.HideTitle();
spacer10.HideTitle();
spacer11.HideTitle();
spacer12.HideTitle();
spacer13.HideTitle();
spacer14.HideTitle();
spacer15.HideTitle();
spacer16.HideTitle();
spacer17.HideTitle();
spacer18.HideTitle();
spacer19.HideTitle();
spacer20.HideTitle();
spacer21.HideTitle();
spacer22.HideTitle();
spacer23.HideTitle();
spacer24.HideTitle();
spacer25.HideTitle();
spacer26.HideTitle();
AddLabel(1, "Pct B ", Color.ORANGE);
AddLabel(showLabels == yes,"1:" + symbol1 +  s1PB + “%”, if s1PB >= 100 then GlobalColor("Above") else if s1PB<= 0 then GlobalColor(“Below”) else if s1PB >=70  then GlobalColor(“Buy”) else if s1PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"2:" + symbol2 +  s2PB + “%”, if s2PB >= 100 then GlobalColor("Above") else if s2PB<= 0 then GlobalColor(“Below”) else if s2PB >=70  then GlobalColor(“Buy”) else if s2PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"3:" + symbol3 +  s3PB + “%”, if s3PB >= 100 then GlobalColor("Above") else if s3PB<= 0 then GlobalColor(“Below”) else if s3PB >=70  then GlobalColor(“Buy”) else if s3PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"4:" + symbol4 +  s4PB + “%”, if s4PB >= 100 then GlobalColor("Above") else if s4PB<= 0 then GlobalColor(“Below”) else if s4PB >=70  then GlobalColor(“Buy”) else if s4PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"5:" + symbol5 +  s5PB + “%”, if s5PB >= 100 then GlobalColor("Above") else if s5PB<= 0 then GlobalColor(“Below”) else if s5PB >=70  then GlobalColor(“Buy”) else if s5PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"6:" + symbol6 +  s6PB + “%”, if s6PB >= 100 then GlobalColor("Above") else if s6PB<= 0 then GlobalColor(“Below”) else if s6PB >=70  then GlobalColor(“Buy”) else if s6PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"7:" + symbol7 +  s1PB + “%”, if s7PB >= 100 then GlobalColor("Above") else if s7PB<= 0 then GlobalColor(“Below”) else if s7PB >=70  then GlobalColor(“Buy”) else if s7PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"8:" + symbol8 +  s8PB + “%”, if s8PB >= 100 then GlobalColor("Above") else if s8PB<= 0 then GlobalColor(“Below”) else if s8PB >=70  then GlobalColor(“Buy”) else if s8PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"9:" + symbol9 +  s9PB + “%”, if s9PB >= 100 then GlobalColor("Above") else if s9PB<= 0 then GlobalColor(“Below”) else if s9PB >=70  then GlobalColor(“Buy”) else if s9PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"10:" + symbol10 +  s10PB + “%”, if s10PB >= 100 then GlobalColor("Above") else if s10PB<= 0 then GlobalColor(“Below”) else if s10PB >=70  then GlobalColor(“Buy”) else if s10PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"11:" + symbol11 +  s11PB + “%”, if s11PB >= 100 then GlobalColor("Above") else if s11PB<= 0 then GlobalColor(“Below”) else if s11PB >=70  then GlobalColor(“Buy”) else if s11PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"13:" + symbol12 +  s12PB + “%”, if s12PB >= 100 then GlobalColor("Above") else if s12PB<= 0 then GlobalColor(“Below”) else if s12PB >=70  then GlobalColor(“Buy”) else if s12PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"14:" + symbol13 +  s13PB + “%”, if s13PB >= 100 then GlobalColor("Above") else if s13PB<= 0 then GlobalColor(“Below”) else if s13PB >=70  then GlobalColor(“Buy”) else if s13PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"15:" + symbol14 +  s14PB + “%”, if s14PB >= 100 then GlobalColor("Above") else if s14PB<= 0 then GlobalColor(“Below”) else if s14PB >=70  then GlobalColor(“Buy”) else if s14PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"16:" + symbol15 +  s15PB + “%”, if s15PB >= 100 then GlobalColor("Above") else if s15PB<= 0 then GlobalColor(“Below”) else if s15PB >=70  then GlobalColor(“Buy”) else if s15PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"17:" + symbol16 +  s16PB + “%”, if s16PB >= 100 then GlobalColor("Above") else if s16PB<= 0 then GlobalColor(“Below”) else if s16PB >=70  then GlobalColor(“Buy”) else if s16PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"18:" + symbol17 +  s17PB + “%”, if s17PB >= 100 then GlobalColor("Above") else if s17PB<= 0 then GlobalColor(“Below”) else if s17PB >=70  then GlobalColor(“Buy”) else if s17PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"19:" + symbol18 +  s18PB + “%”, if s18PB >= 100 then GlobalColor("Above") else if s18PB<= 0 then GlobalColor(“Below”) else if s18PB >=70  then GlobalColor(“Buy”) else if s18PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"20:" + symbol19 +  s19PB + “%”, if s19PB >= 100 then GlobalColor("Above") else if s19PB<= 0 then GlobalColor(“Below”) else if s19PB >=70  then GlobalColor(“Buy”) else if s19PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"21:" + symbol20 +  s20PB + “%”, if s20PB >= 100 then GlobalColor("Above") else if s20PB<= 0 then GlobalColor(“Below”) else if s20PB >=70  then GlobalColor(“Buy”) else if s20PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"22:" + symbol21 +  s21PB + “%”, if s21PB >= 100 then GlobalColor("Above") else if s21PB<= 0 then GlobalColor(“Below”) else if s21PB >=70  then GlobalColor(“Buy”) else if s21PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"23:" + symbol22 +  s22PB + “%”, if s22PB >= 100 then GlobalColor("Above") else if s22PB<= 0 then GlobalColor(“Below”) else if s22PB >=70  then GlobalColor(“Buy”) else if s22PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"24:" + symbol23 +  s23PB + “%”, if s23PB >= 100 then GlobalColor("Above") else if s23PB<= 0 then GlobalColor(“Below”) else if s23PB >=70  then GlobalColor(“Buy”) else if s23PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"25:" + symbol24 +  s24PB + “%”, if s24PB >= 100 then GlobalColor("Above") else if s24PB<= 0 then GlobalColor(“Below”) else if s24PB >=70  then GlobalColor(“Buy”) else if s24PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"26:" + symbol25 +  s25PB + “%”, if s25PB >= 100 then GlobalColor("Above") else if s25PB<= 0 then GlobalColor(“Below”) else if s25PB >=70  then GlobalColor(“Buy”) else if s25PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes,"27:" + symbol26 +  s26PB + “%”, if s26PB >= 100 then GlobalColor("Above") else if s26PB<= 0 then GlobalColor(“Below”) else if s26PB >=70  then GlobalColor(“Buy”) else if s26PB <30 then GlobalColor(“Sell") else GlobalColor("Neutral"));
 
Using Percent B Bandwidth Woodie from Edgerater to find sector rotation
Code:
declare lower;
DefineGlobalColor("Buy", Color.GREEN);
DefineGlobalColor("Sell", Color.RED);
DefineGlobalColor("Neutral", Color.YELLOW);

input symbol26 = "NYA";
input symbol25 = "XAX";
input symbol24 = "IWB";
input symbol23 = "FFTY";
input symbol22 = "BOUT";
input symbol21 = "XTC";
input symbol20 = "SOX";
input symbol19 = "RUT";
input symbol18 = "RUI";
input symbol17 = "COMP:GIDS";
input symbol16 = "SPY";
input symbol15 = "QQQ";
input symbol14 = "IWM";
input symbol13 = "$DJT";
input symbol12 = "IBB";
input symbol11 = "XLY";
input symbol10 = "XLV";
input symbol9 = "XLU";
input symbol8 = "XLRE";
input symbol7 = "XLP";
input symbol6 = "XLK";
input symbol5 = "XLI";
input symbol4 = "XLF";
input symbol3 = "XLE";
input symbol2 = "XLC";
input symbol1 = "XLB";
input DotSize = 5;
input showLabels = yes;
input showBubbles = no;
script PBW {
    input symbol = "";
    def price = close(symbol);
    input displace = 0;
    input length = 20;
    input Num_Dev_Dn = -2.0;
    input Num_Dev_up = 2.0;
    input averageType = AverageType.SIMPLE;
    def upperBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).UpperBand;
    def lowerBand = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).LowerBand;
    def midLine = BollingerBands(price, displace, length, Num_Dev_Dn, Num_Dev_up, averageType).MidLine;
    def Bandwidth = (upperBand - lowerBand) / midLine;
    plot PercentBW = Round(((price - lowerBand) / (upperBand - lowerBand) * Bandwidth) * 100,2);

}

def s1PB = PBW(symbol1);
def s2PB = PBW(symbol2);
def s3PB = PBW(symbol3);
def s4PB = PBW(symbol4);
def s5PB = PBW(symbol5);
def s6PB = PBW(symbol6);
def s7PB = PBW(symbol7);
def s8PB = PBW(symbol8);
def s9PB = PBW(symbol9);
def s10PB = PBW(symbol10);
def s11PB = PBW(symbol11);
def s12PB = PBW(symbol12);
def s13PB = PBW(symbol13);
def s14PB = PBW(symbol14);
def s15PB = PBW(symbol15);
def s16PB = PBW(symbol16);
def s17PB = PBW(symbol17);
def s18PB = PBW(symbol18);
def s19PB = PBW(symbol19);
def s20PB = PBW(symbol20);
def s21PB = PBW(symbol21);
def s22PB = PBW(symbol22);
def s23PB = PBW(symbol23);
def s24PB = PBW(symbol24);
def s25PB = PBW(symbol25);
def s26PB = PBW(symbol26);
#######Plots
plot symb1 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 1 else Double.NaN;
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
symb1.SetLineWeight(DotSize);
symb1.AssignValueColor(if s1PB >= 3.5  then GlobalColor(“Buy”) else if s1PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol1)[1]), 1, "1: " + symbol1, if s1PB[1] >= 3.5  then GlobalColor(“Buy”) else if s1PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb1.HideBubble();
plot symb2 = if !IsNaN(close) and !IsNaN(close(symbol2)) then 2 else Double.NaN;
symb2.SetPaintingStrategy(PaintingStrategy.POINTS);
symb2.SetLineWeight(DotSize);
symb2.AssignValueColor(if s2PB >= 3.5  then GlobalColor(“Buy”) else if s2PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol2)[5]), 2, "2: " + symbol2, if s2PB[5] >= 3.5  then GlobalColor(“Buy”) else if s2PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb2.HideBubble();
plot symb3 = if !IsNaN(close) and !IsNaN(close(symbol3)) then 3 else Double.NaN;
symb3.SetPaintingStrategy(PaintingStrategy.POINTS);
symb3.SetLineWeight(DotSize);
symb3.AssignValueColor(if s3PB >= 3.5  then GlobalColor(“Buy”) else if s3PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol3)[1]), 3, "3: " + symbol3, if s3PB[1] >= 3.5  then GlobalColor(“Buy”) else if s3PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb3.HideBubble();
plot symb4 = if !IsNaN(close) and !IsNaN(close(symbol4)) then 4 else Double.NaN;
symb4.SetPaintingStrategy(PaintingStrategy.POINTS);
symb4.SetLineWeight(DotSize);
symb4.AssignValueColor(if s4PB >= 3.5  then GlobalColor(“Buy”) else if s4PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol4)[5]), 4, "4: " + symbol4, if s4PB[5] >= 3.5  then GlobalColor(“Buy”) else if s4PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb4.HideBubble();
plot symb5 = if !IsNaN(close) and !IsNaN(close(symbol5)) then 5 else Double.NaN;
symb5.SetPaintingStrategy(PaintingStrategy.POINTS);
symb5.SetLineWeight(DotSize);
symb5.AssignValueColor(if s5PB >= 3.5  then GlobalColor(“Buy”) else if s5PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol5)[1]), 5, "5: " + symbol5, if s5PB[1] >= 3.5  then GlobalColor(“Buy”) else if s5PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb5.HideBubble();
plot symb6 = if !IsNaN(close) and !IsNaN(close(symbol6)) then 6 else Double.NaN;
symb6.SetPaintingStrategy(PaintingStrategy.POINTS);
symb6.SetLineWeight(DotSize);
symb6.AssignValueColor(if s6PB >= 3.5  then GlobalColor(“Buy”) else if s6PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol6)[5]), 6, "6: " + symbol6, if s6PB[5] >= 3.5  then GlobalColor(“Buy”) else if s6PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb6.HideBubble();
plot symb7 = if !IsNaN(close) and !IsNaN(close(symbol7)) then 7 else Double.NaN;
symb7.SetPaintingStrategy(PaintingStrategy.POINTS);
symb7.SetLineWeight(DotSize);
symb7.AssignValueColor(if s7PB >= 3.5  then GlobalColor(“Buy”) else if s7PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol7)[1]), 7, "7: " + symbol7, if s7PB[1] >= 3.5  then GlobalColor(“Buy”) else if s7PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb7.HideBubble();
plot symb8 = if !IsNaN(close) and !IsNaN(close(symbol8)) then 8 else Double.NaN;
symb8.SetPaintingStrategy(PaintingStrategy.POINTS);
symb8.SetLineWeight(DotSize);
symb8.AssignValueColor(if s8PB >= 3.5  then GlobalColor(“Buy”) else if s8PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol8)[5]), 8, "8: " + symbol8, if s8PB[5] >= 3.5  then GlobalColor(“Buy”) else if s8PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb8.HideBubble();
plot symb9 = if !IsNaN(close) and !IsNaN(close(symbol9)) then 9 else Double.NaN;
symb9.SetPaintingStrategy(PaintingStrategy.POINTS);
symb9.SetLineWeight(DotSize);
symb9.AssignValueColor(if s9PB >= 3.5  then GlobalColor(“Buy”) else if s9PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol9)[1]), 9, "9: " + symbol9, if s9PB[1] >= 3.5  then GlobalColor(“Buy”) else if s9PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb9.HideBubble();
plot symb10 = if !IsNaN(close) and !IsNaN(close(symbol10)) then 10 else Double.NaN;
symb10.SetPaintingStrategy(PaintingStrategy.POINTS);
symb10.SetLineWeight(DotSize);
symb10.AssignValueColor(if s10PB >= 3.5  then GlobalColor(“Buy”) else if s10PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol10)[5]), 10, "10: " + symbol10, if s10PB[5] >= 3.5  then GlobalColor(“Buy”) else if s10PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb10.HideBubble();
plot symb11 = if !IsNaN(close) and !IsNaN(close(symbol11)) then 11 else Double.NaN;
symb11.SetPaintingStrategy(PaintingStrategy.POINTS);
symb11.SetLineWeight(DotSize);
symb11.AssignValueColor(if s11PB >= 3.5  then GlobalColor(“Buy”) else if s11PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol11)[1]), 11, "11: " + symbol11, if s11PB[1] >= 3.5  then GlobalColor(“Buy”) else if s11PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb11.HideBubble();
plot symb12 = if !IsNaN(close) and !IsNaN(close(symbol12)) then 13 else Double.NaN;
symb12.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb12.SetLineWeight(DotSize);
symb12.AssignValueColor(if s12PB >= 3.5  then GlobalColor(“Buy”) else if s12PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol12)[5]), 13, "13: " + symbol12, if s12PB[5] >= 3.5  then GlobalColor(“Buy”) else if s12PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb12.HideBubble();
plot symb13 = if !IsNaN(close) and !IsNaN(close(symbol13)) then 14 else Double.NaN;
symb13.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb13.SetLineWeight(DotSize);
symb13.AssignValueColor(if s13PB >= 3.5  then GlobalColor(“Buy”) else if s13PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol13)[1]), 14, "14: " + symbol13, if s13PB[1] >= 3.5  then GlobalColor(“Buy”) else if s13PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb13.HideBubble();
plot symb14 = if !IsNaN(close) and !IsNaN(close(symbol14)) then 15 else Double.NaN;
symb14.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb14.SetLineWeight(DotSize);
symb14.AssignValueColor(if s14PB >= 3.5  then GlobalColor(“Buy”) else if s14PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol14)[5]), 15, "15: " + symbol14, if s14PB[5] >= 3.5  then GlobalColor(“Buy”) else if s14PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb14.HideBubble();
plot symb15 = if !IsNaN(close) and !IsNaN(close(symbol15)) then 16 else Double.NaN;
symb15.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb15.SetLineWeight(DotSize);
symb15.AssignValueColor(if s15PB >= 3.5  then GlobalColor(“Buy”) else if s15PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol15)[1]), 16, "16: " + symbol15, if s15PB[1] >= 3.5  then GlobalColor(“Buy”) else if s15PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb15.HideBubble();
plot symb16 = if !IsNaN(close) and !IsNaN(close(symbol16)) then 17 else Double.NaN;
symb16.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb16.SetLineWeight(DotSize);
symb16.AssignValueColor(if s16PB >= 3.5 then GlobalColor(“Buy”) else if s16PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol16)[5]), 17, "17: " + symbol16, if s16PB[5] >= 3.5 then GlobalColor(“Buy”) else if s16PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb16.HideBubble();
plot symb17 = if !IsNaN(close) and !IsNaN(close(symbol17)) then 18 else Double.NaN;
symb17.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb17.SetLineWeight(DotSize);
symb17.AssignValueColor(if s17PB >= 3.5  then GlobalColor(“Buy”) else if s17PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol17)[1]), 18, "18: " + symbol17, if s17PB[1] >= 3.5 then GlobalColor(“Buy”) else if s17PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb17.HideBubble();
plot symb18 = if !IsNaN(close) and !IsNaN(close(symbol18)) then 19 else Double.NaN;
symb18.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb18.SetLineWeight(DotSize);
symb18.AssignValueColor(if s18PB >= 3.5 then GlobalColor(“Buy”) else if s18PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol18)[5]), 19, "19: " + symbol18, if s18PB[5] >= 3.5  then GlobalColor(“Buy”) else if s18PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb18.HideBubble();
plot symb19 = if !IsNaN(close) and !IsNaN(close(symbol19)) then 20 else Double.NaN;
symb19.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb19.SetLineWeight(DotSize);
symb19.AssignValueColor(if s19PB >= 3.5  then GlobalColor(“Buy”) else if s19PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol19)[1]), 20, "20: " + symbol19, if s19PB[1] >= 3.5  then GlobalColor(“Buy”) else if s19PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb19.HideBubble();
plot symb20 = if !IsNaN(close) and !IsNaN(close(symbol20)) then 21 else Double.NaN;
symb20.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb20.SetLineWeight(DotSize);
symb20.AssignValueColor(if s20PB >= 3.5  then GlobalColor(“Buy”) else if s20PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol20)[5]), 21, "21: " + symbol20, if s20PB[5] >= 3.5  then GlobalColor(“Buy”) else if s20PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb20.HideBubble();
plot symb21 = if !IsNaN(close) and !IsNaN(close(symbol21)) then 22 else Double.NaN;
symb21.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb21.SetLineWeight(DotSize);
symb21.AssignValueColor(if s21PB >= 3.5  then GlobalColor(“Buy”) else if s21PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol21)[1]), 22, "22: " + symbol21, if s21PB[1] >= 3.5  then GlobalColor(“Buy”) else if s21PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb21.HideBubble();
plot symb22 = if !IsNaN(close) and !IsNaN(close(symbol22)) then 23 else Double.NaN;
symb22.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb22.SetLineWeight(DotSize);
symb22.AssignValueColor(if s22PB >= 3.5  then GlobalColor(“Buy”) else if s22PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol22)[5]), 23, "23: " + symbol22, if s22PB[5] >= 3.5  then GlobalColor(“Buy”) else if s22PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb22.HideBubble();
plot symb23 = if !IsNaN(close) and !IsNaN(close(symbol23)) then 24 else Double.NaN;
symb23.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb23.SetLineWeight(DotSize);
symb23.AssignValueColor(if s23PB >= 3.5  then GlobalColor(“Buy”) else if s23PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol23)[1]), 24, "24: " + symbol23, if s23PB[1] >= 3.5  then GlobalColor(“Buy”) else if s23PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb23.HideBubble();
plot symb24 = if !IsNaN(close) and !IsNaN(close(symbol24)) then 25 else Double.NaN;
symb24.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb24.SetLineWeight(DotSize);
symb24.AssignValueColor(if s24PB >= 3.5  then GlobalColor(“Buy”) else if s24PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol24)[5]), 25, "25: " + symbol24, if s24PB[5] >= 3.5  then GlobalColor(“Buy”) else if s24PB[5] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb24.HideBubble();
plot symb25 = if !IsNaN(close) and !IsNaN(close(symbol25)) then 26 else Double.NaN;
symb25.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb25.SetLineWeight(DotSize);
symb25.AssignValueColor(if s25PB >= 3.5 then GlobalColor(“Buy”) else if s25PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol25)[1]), 26, "26: " + symbol25, if s25PB[1] >= 3.5  then GlobalColor(“Buy”) else if s25PB[1] <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb25.HideBubble();
plot symb26 = if !IsNaN(close) and !IsNaN(close(symbol26)) then 27 else Double.NaN;
symb26.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb26.SetLineWeight(DotSize);
symb26.AssignValueColor(if s26PB >= 3.5  then GlobalColor(“Buy”) else if s26PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddChartBubble(showBubbles and IsNaN(close) and !IsNaN(close[4]) and !IsNaN(close(symbol26)[5]), 27, "27: " + symbol26, if s26PB[5] >= 3.5  then GlobalColor(“Buy”) else if s26PB[5] < 1 then GlobalColor(“Sell") else GlobalColor("Neutral"), yes);
symb26.HideBubble();
plot spacer0 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 0.5 else Double.NaN;
plot spacer1 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 1.5 else Double.NaN;
plot spacer2 = if !IsNaN(close) and !IsNaN(close(symbol2)) then 2.5 else Double.NaN;
plot spacer3 = if !IsNaN(close) and !IsNaN(close(symbol3)) then 3.5 else Double.NaN;
plot spacer4 = if !IsNaN(close) and !IsNaN(close(symbol4)) then 4.5 else Double.NaN;
plot spacer5 = if !IsNaN(close)  and !IsNaN(close(symbol5)) then 5.5 else Double.NaN;
plot spacer6 = if !IsNaN(close) and !IsNaN(close(symbol6)) then 6.5 else Double.NaN;
plot spacer7 = if !IsNaN(close) and !IsNaN(close(symbol7)) then 7.5 else Double.NaN;
plot spacer8 = if !IsNaN(close) and !IsNaN(close(symbol8)) then 8.5 else Double.NaN;
plot spacer9 = if !IsNaN(close) and !IsNaN(close(symbol9)) then 9.5 else Double.NaN;
plot spacer10 = if !IsNaN(close) and !IsNaN(close(symbol10)) then 10.5 else Double.NaN;
plot spacer11 = if !IsNaN(close)  and !IsNaN(close(symbol11)) then 11.5 else Double.NaN;
plot spacer12 = if !IsNaN(close) and !IsNaN(close(symbol12)) then 12.5 else Double.NaN;
plot spacer13 = if !IsNaN(close) and !IsNaN(close(symbol13)) then 13.5 else Double.NaN;
plot spacer14 = if !IsNaN(close) and !IsNaN(close(symbol14)) then 14.5 else Double.NaN;
plot spacer15 = if !IsNaN(close) and !IsNaN(close(symbol15)) then 15.5 else Double.NaN;
plot spacer16 = if !IsNaN(close) and !IsNaN(close(symbol16)) then 16.5 else Double.NaN;
plot spacer17 = if !IsNaN(close) and !IsNaN(close(symbol17)) then 17.5 else Double.NaN;
plot spacer18 = if !IsNaN(close) and !IsNaN(close(symbol18)) then 18.5 else Double.NaN;
plot spacer19 = if !IsNaN(close) and !IsNaN(close(symbol19)) then 19.5 else Double.NaN;
plot spacer20 = if !IsNaN(close) and !IsNaN(close(symbol20)) then 20.5 else Double.NaN;
plot spacer21 = if !IsNaN(close)  and !IsNaN(close(symbol21)) then 21.5 else Double.NaN;
plot spacer22 = if !IsNaN(close) and !IsNaN(close(symbol22)) then 22.5 else Double.NaN;
plot spacer23 = if !IsNaN(close) and !IsNaN(close(symbol23)) then 23.5 else Double.NaN;
plot spacer24 = if !IsNaN(close) and !IsNaN(close(symbol24)) then 24.5 else Double.NaN;
plot spacer25 = if !IsNaN(close) and !IsNaN(close(symbol25)) then 25.5 else Double.NaN;
plot spacer26 = if !IsNaN(close) and !IsNaN(close(symbol26)) then 26.5 else Double.NaN;

spacer0.SetDefaultColor(Color.GRAY);
spacer1.SetDefaultColor(Color.GRAY);
spacer2.SetDefaultColor(Color.GRAY);
spacer3.SetDefaultColor(Color.GRAY);
spacer4.SetDefaultColor(Color.GRAY);
spacer5.SetDefaultColor(Color.GRAY);
spacer6.SetDefaultColor(Color.GRAY);
spacer7.SetDefaultColor(Color.GRAY);
spacer8.SetDefaultColor(Color.GRAY);
spacer9.SetDefaultColor(Color.GRAY);
spacer10.SetDefaultColor(Color.GRAY);
spacer11.SetDefaultColor(Color.GRAY);
spacer12.SetDefaultColor(Color.GRAY);
spacer13.SetDefaultColor(Color.GRAY);
spacer14.SetDefaultColor(Color.GRAY);
spacer15.SetDefaultColor(Color.GRAY);
spacer16.SetDefaultColor(Color.GRAY);
spacer17.SetDefaultColor(Color.GRAY);
spacer18.SetDefaultColor(Color.GRAY);
spacer19.SetDefaultColor(Color.GRAY);
spacer20.SetDefaultColor(Color.GRAY);
spacer21.SetDefaultColor(Color.GRAY);
spacer22.SetDefaultColor(Color.GRAY);
spacer23.SetDefaultColor(Color.GRAY);
spacer24.SetDefaultColor(Color.GRAY);
spacer25.SetDefaultColor(Color.GRAY);
spacer26.SetDefaultColor(Color.GRAY);

spacer0.HideBubble();
spacer1.HideBubble();
spacer2.HideBubble();
spacer3.HideBubble();
spacer4.HideBubble();
spacer5.HideBubble();
spacer6.HideBubble();
spacer7.HideBubble();
spacer8.HideBubble();
spacer9.HideBubble();
spacer10.HideBubble();
spacer11.HideBubble();
spacer12.HideBubble();
spacer13.HideBubble();
spacer14.HideBubble();
spacer15.HideBubble();
spacer16.HideBubble();
spacer17.HideBubble();
spacer18.HideBubble();
spacer19.HideBubble();
spacer20.HideBubble();
spacer21.HideBubble();
spacer22.HideBubble();
spacer23.HideBubble();
spacer24.HideBubble();
spacer25.HideBubble();
spacer26.HideBubble();
spacer0.HideTitle();
spacer1.HideTitle();
spacer2.HideTitle();
spacer3.HideTitle();
spacer4.HideTitle();
spacer5.HideTitle();
spacer6.HideTitle();
spacer7.HideTitle();
spacer8.HideTitle();
spacer9.HideTitle();
spacer10.HideTitle();
spacer11.HideTitle();
spacer12.HideTitle();
spacer13.HideTitle();
spacer14.HideTitle();
spacer15.HideTitle();
spacer16.HideTitle();
spacer17.HideTitle();
spacer18.HideTitle();
spacer19.HideTitle();
spacer20.HideTitle();
spacer21.HideTitle();
spacer22.HideTitle();
spacer23.HideTitle();
spacer24.HideTitle();
spacer25.HideTitle();
spacer26.HideTitle();

AddLabel(1, "PctBxBW ", Color.ORANGE);
AddLabel(showLabels == yes, "1:" + symbol1 +  s1PB + “%”, if s1PB >= 3.5  then GlobalColor(“Buy”) else if s1PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "2:" + symbol2 +  s2PB + “%”, if s2PB >= 3.5  then GlobalColor(“Buy”) else if s2PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "3:" + symbol3 +  s3PB + “%”, if s3PB >= 3.5  then GlobalColor(“Buy”) else if s3PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "4:" + symbol4 +  s4PB + "%",if s4PB >= 3.5  then GlobalColor(“Buy”) else if s4PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "5:" + symbol5 +  s5PB + “%”, if s5PB >= 3.5  then GlobalColor(“Buy”) else if s5PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "6:" + symbol6 +  s6PB + “%”, if s6PB >= 3.5  then GlobalColor(“Buy”) else if s6PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "7:" + symbol7 +  s1PB + “%”, if s7PB >= 3.5  then GlobalColor(“Buy”) else if s7PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "8:" + symbol8 +  s8PB + “%”, if s8PB >= 3.5  then GlobalColor(“Buy”) else if s8PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "9:" + symbol9 +  s9PB + “%”, if s9PB >= 3.5  then GlobalColor(“Buy”) else if s9PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "10:" + symbol10 +  s10PB + “%”, if s10PB >= 3.5  then GlobalColor(“Buy”) else if s10PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "11:" + symbol11 +  s11PB + “%”, if s11PB >= 3.5  then GlobalColor(“Buy”) else if s11PB <=1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "13:" + symbol12 +  s12PB + “%”, if s12PB >= 3.5  then GlobalColor(“Buy”) else if s12PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "14:" + symbol13 +  s13PB + “%”, if s13PB >= 3.5  then GlobalColor(“Buy”) else if s13PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "15:" + symbol14 +  s14PB + “%”, if s14PB >= 3.5  then GlobalColor(“Buy”) else if s14PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "16:" + symbol15 +  s15PB + “%”, if s15PB >= 3.5  then GlobalColor(“Buy”) else if s15PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "17:" + symbol16 +  s16PB + “%”, if s16PB >= 3.5  then GlobalColor(“Buy”) else if s16PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "18:" + symbol17 +  s17PB + “%”, if s17PB >= 3.5  then GlobalColor(“Buy”) else if s17PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "19:" + symbol18 +  s18PB + “%”, if s18PB >= 3.5  then GlobalColor(“Buy”) else if s18PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "20:" + symbol19 +  s19PB + “%”, if s19PB >= 3.5  then GlobalColor(“Buy”) else if s19PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "21:" + symbol20 +  s20PB + “%”, if s20PB >= 3.5  then GlobalColor(“Buy”) else if s20PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "22:" + symbol21 +  s21PB + “%”, if s21PB >= 3.5  then GlobalColor(“Buy”) else if s21PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "23:" + symbol22 +  s22PB + “%”, if s22PB >= 3.5  then GlobalColor(“Buy”) else if s22PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "24:" + symbol23 +  s23PB + “%”, if s23PB >= 3.5  then GlobalColor(“Buy”) else if s23PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "25:" + symbol24 +  s24PB + “%”, if s24PB >= 3.5  then GlobalColor(“Buy”) else if s24PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "26:" + symbol25 +  s25PB + “%”, if s25PB >= 3.5  then GlobalColor(“Buy”) else if s25PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
AddLabel(showLabels == yes, "27:" + symbol26 +  s26PB + “%”, if s26PB >= 3.5  then GlobalColor(“Buy”) else if s26PB <= 1 then GlobalColor(“Sell") else GlobalColor("Neutral"));
 
Using HK_4_EMA_Rank for sector rotation
Code:
declare lower;
input symbol26 = "NYA";
input symbol25 = "XAX";
input symbol24 = "IWB";
input symbol23 = "FFTY";
input symbol22 = "BOUT";
input symbol21 = "XTC";
input symbol20 = "SOX";
input symbol19 = "RUT";
input symbol18 = "RUI";
input symbol17 = "COMP:GIDS";
input symbol16 = "SPY";
input symbol15 = "QQQ";
input symbol14 = "IWM";
input symbol13 = "$DJT";
input symbol12 = "IBB";
input symbol11 = "XLY";
input symbol10 = "XLV";
input symbol9 = "XLU";
input symbol8 = "XLRE";
input symbol7 = "XLP";
input symbol6 = "XLK";
input symbol5 = "XLI";
input symbol4 = "XLF";
input symbol3 = "XLE";
input symbol2 = "XLC";
input symbol1 = "XLB";
input Length1 = 3;
input Length2 = 6;
input Length3 = 9;
input Length4 = 12;
input Length5 = 15;
input Length6 = 30;
input Length7 = 45;
input Length8 = 60;
input averageType = AverageType.EXPONENTIAL;
input lookback = 21;
input smoothingPeriod = 10;
input showLabels = yes;
DefineGlobalColor("ALong", Color.CYAN);
DefineGlobalColor("AShort", Color.MAGENTA);
DefineGlobalColor("Buy", Color.GREEN);
DefineGlobalColor("Sell", Color.RED);
DefineGlobalColor("Neutral", Color.YELLOW);

input DotSize = 3;

script SymbolRank_AXL {
    input symbol = "";
    def price1 = (close(symbol) + open(symbol)) / 2;
    input Length1 = 3;
    input Length2 = 6;
    input Length3 = 9;
    input Length4 = 12;
    input Length5 = 15;
    input Length6 = 30;
    input Length7 = 45;
    input Length8 = 60;
    input averageType = AverageType.EXPONENTIAL;
    def D1 = MovingAverage(averageType, price1, Length1);
    def D2 = MovingAverage(averageType, price1, Length2);
    def D3 = MovingAverage(averageType, price1, Length3);
    def D4 = MovingAverage(averageType, price1, Length4);
    def W1 = MovingAverage(averageType, price1, Length5);
    def W2 = MovingAverage(averageType, price1, Length6);
    def W3 = MovingAverage(averageType, price1, Length7);
    def W4 = MovingAverage(averageType, price1, Length8);
    def DCondition1 = If(D1 > D2 and D2 > D3 and D3 > D4, 5,
 If((D1 > D2 and D2 > D4 and D4 > D3) or (D1 > D3 and D3 > D2 and D2 > D4) or
(D2 > D1 and D1 > D3 and D3 > D4), 4, If(D2 > D1 and D1 > D4 and D4 > D3, 3,
If((D1 > D3 and D3 > D4 and D4 > D2) or ( D1 > D4 and D4 > D2 and D2 > D3)  or
(D2 > D3 and D3 > D1 and D1 > D4)  or (D3 > D1 and D1 > D2 and D2 > D4) , 2,
If((D1 > D4 and D4 > D3 and D3 > D2) or (D3 > D2 and D2 > D1 and D1 > D4), 1, 0)))));
    def DCondition2 = If(D4 > D3 and D3 > D2 and D2 > D1, -5,
If((D3 > D4 and D4 > D2 and D2 > D1) or (D4 > D2 and D2 > D3 and D3 > D1) or
(D4 > D3 and D3 > D1 and D1 > D2), -4, If(D3 > D4 and D4 > D1 and D1 > D2, -3,
If((D2 > D4 and D4 > D3 and D3 > D1) or (D3 > D2 and D2 > D4 and D4 > D1)  or
(D4 > D1 and D1 > D3 and D3 > D2)  or (D4 > D2 and D2 > D1 and D1 > D3) , -2,
If((D2 > D3 and D3 > D4 and D4 > D1) or (D4 > D1 and D1 > D2 and D2 > D3), -1, 0)))));
    def WCondition1 = If(W1 > W2 and W2 > W3 and W3 > W4, 50,
 If((W1 > W2 and W2 > W4 and W4 > W3) or (W1 > W3 and W3 > W2 and W2 > W4) or
(W2 > W1 and W1 > W3 and W3 > W4), 40, If(W2 > W1 and W1 > W4 and W4 > W3, 30,
If((W1 > W3 and W3 > W4 and W4 > W2) or ( W1 > W4 and W4 > W2 and W2 > W3)  or
(W2 > W3 and W3 > W1 and W1 > W4)  or (W3 > W1 and W1 > W2 and W2 > W4) , 20,
If((W1 > W4 and W4 > W3 and W3 > W2) or (W3 > W2 and W2 > W1 and W1 > W4), 10, 0)))));
    def WCondition2 = If(W4 > W3 and W3 > W2 and W2 > W1, -50,
If((W3 > W4 and W4 > W2 and W2 > W1) or (W4 > W2 and W2 > W3 and W3 > W1) or
(W4 > W3 and W3 > W1 and W1 > W2), -40, If(W3 > W4 and W4 > W1 and W1 > W2, -30,
If((W2 > W4 and W4 > W3 and W3 > W1) or (W3 > W2 and W2 > W4 and W4 > W1)  or
(W4 > W1 and W1 > W3 and W3 > W2)  or (W4 > W2 and W2 > W1 and W1 > W3) , -20,
If((W2 > W3 and W3 > W4 and W4 > W1) or (W4 > W1 and W1 > W2 and W2 > W3), -10, 0)))));
    def WT = (WCondition1 + WCondition2);
    def TT = (WCondition1 + WCondition2 + DCondition1 + DCondition2);
#####signals
    plot AXL = TT crosses above WT;
}
script SymbolRank_AXS {
    input symbol = "";
    def price1 = (close(symbol) + open(symbol)) / 2;
    input Length1 = 3;
    input Length2 = 6;
    input Length3 = 9;
    input Length4 = 12;
    input Length5 = 15;
    input Length6 = 30;
    input Length7 = 45;
    input Length8 = 60;
    input averageType = AverageType.EXPONENTIAL;
    def D1 = MovingAverage(averageType, price1, Length1);
    def D2 = MovingAverage(averageType, price1, Length2);
    def D3 = MovingAverage(averageType, price1, Length3);
    def D4 = MovingAverage(averageType, price1, Length4);
    def W1 = MovingAverage(averageType, price1, Length5);
    def W2 = MovingAverage(averageType, price1, Length6);
    def W3 = MovingAverage(averageType, price1, Length7);
    def W4 = MovingAverage(averageType, price1, Length8);
    def DCondition1 = If(D1 > D2 and D2 > D3 and D3 > D4, 5,
 If((D1 > D2 and D2 > D4 and D4 > D3) or (D1 > D3 and D3 > D2 and D2 > D4) or
(D2 > D1 and D1 > D3 and D3 > D4), 4, If(D2 > D1 and D1 > D4 and D4 > D3, 3,
If((D1 > D3 and D3 > D4 and D4 > D2) or ( D1 > D4 and D4 > D2 and D2 > D3)  or
(D2 > D3 and D3 > D1 and D1 > D4)  or (D3 > D1 and D1 > D2 and D2 > D4) , 2,
If((D1 > D4 and D4 > D3 and D3 > D2) or (D3 > D2 and D2 > D1 and D1 > D4), 1, 0)))));
    def DCondition2 = If(D4 > D3 and D3 > D2 and D2 > D1, -5,
If((D3 > D4 and D4 > D2 and D2 > D1) or (D4 > D2 and D2 > D3 and D3 > D1) or
(D4 > D3 and D3 > D1 and D1 > D2), -4, If(D3 > D4 and D4 > D1 and D1 > D2, -3,
If((D2 > D4 and D4 > D3 and D3 > D1) or (D3 > D2 and D2 > D4 and D4 > D1)  or
(D4 > D1 and D1 > D3 and D3 > D2)  or (D4 > D2 and D2 > D1 and D1 > D3) , -2,
If((D2 > D3 and D3 > D4 and D4 > D1) or (D4 > D1 and D1 > D2 and D2 > D3), -1, 0)))));
    def WCondition1 = If(W1 > W2 and W2 > W3 and W3 > W4, 50,
 If((W1 > W2 and W2 > W4 and W4 > W3) or (W1 > W3 and W3 > W2 and W2 > W4) or
(W2 > W1 and W1 > W3 and W3 > W4), 40, If(W2 > W1 and W1 > W4 and W4 > W3, 30,
If((W1 > W3 and W3 > W4 and W4 > W2) or ( W1 > W4 and W4 > W2 and W2 > W3)  or
(W2 > W3 and W3 > W1 and W1 > W4)  or (W3 > W1 and W1 > W2 and W2 > W4) , 20,
If((W1 > W4 and W4 > W3 and W3 > W2) or (W3 > W2 and W2 > W1 and W1 > W4), 10, 0)))));
    def WCondition2 = If(W4 > W3 and W3 > W2 and W2 > W1, -50,
If((W3 > W4 and W4 > W2 and W2 > W1) or (W4 > W2 and W2 > W3 and W3 > W1) or
(W4 > W3 and W3 > W1 and W1 > W2), -40, If(W3 > W4 and W4 > W1 and W1 > W2, -30,
If((W2 > W4 and W4 > W3 and W3 > W1) or (W3 > W2 and W2 > W4 and W4 > W1)  or
(W4 > W1 and W1 > W3 and W3 > W2)  or (W4 > W2 and W2 > W1 and W1 > W3) , -20,
If((W2 > W3 and W3 > W4 and W4 > W1) or (W4 > W1 and W1 > W2 and W2 > W3), -10, 0)))));
    def WT = (WCondition1 + WCondition2);
    def TT = (WCondition1 + WCondition2 + DCondition1 + DCondition2);
#####signals
    plot AXS = TT crosses below WT;
}
script SymbolRank_ALong {
    input symbol = "";
    def price1 = (close(symbol) + open(symbol)) / 2;
    input Length1 = 3;
    input Length2 = 6;
    input Length3 = 9;
    input Length4 = 12;
    input Length5 = 15;
    input Length6 = 30;
    input Length7 = 45;
    input Length8 = 60;
    input averageType = AverageType.EXPONENTIAL;
    def D1 = MovingAverage(averageType, price1, Length1);
    def D2 = MovingAverage(averageType, price1, Length2);
    def D3 = MovingAverage(averageType, price1, Length3);
    def D4 = MovingAverage(averageType, price1, Length4);
    def W1 = MovingAverage(averageType, price1, Length5);
    def W2 = MovingAverage(averageType, price1, Length6);
    def W3 = MovingAverage(averageType, price1, Length7);
    def W4 = MovingAverage(averageType, price1, Length8);
    def DCondition1 = If(D1 > D2 and D2 > D3 and D3 > D4, 5,
 If((D1 > D2 and D2 > D4 and D4 > D3) or (D1 > D3 and D3 > D2 and D2 > D4) or
(D2 > D1 and D1 > D3 and D3 > D4), 4, If(D2 > D1 and D1 > D4 and D4 > D3, 3,
If((D1 > D3 and D3 > D4 and D4 > D2) or ( D1 > D4 and D4 > D2 and D2 > D3)  or
(D2 > D3 and D3 > D1 and D1 > D4)  or (D3 > D1 and D1 > D2 and D2 > D4) , 2,
If((D1 > D4 and D4 > D3 and D3 > D2) or (D3 > D2 and D2 > D1 and D1 > D4), 1, 0)))));
    def DCondition2 = If(D4 > D3 and D3 > D2 and D2 > D1, -5,
If((D3 > D4 and D4 > D2 and D2 > D1) or (D4 > D2 and D2 > D3 and D3 > D1) or
(D4 > D3 and D3 > D1 and D1 > D2), -4, If(D3 > D4 and D4 > D1 and D1 > D2, -3,
If((D2 > D4 and D4 > D3 and D3 > D1) or (D3 > D2 and D2 > D4 and D4 > D1)  or
(D4 > D1 and D1 > D3 and D3 > D2)  or (D4 > D2 and D2 > D1 and D1 > D3) , -2,
If((D2 > D3 and D3 > D4 and D4 > D1) or (D4 > D1 and D1 > D2 and D2 > D3), -1, 0)))));
    def WCondition1 = If(W1 > W2 and W2 > W3 and W3 > W4, 50,
 If((W1 > W2 and W2 > W4 and W4 > W3) or (W1 > W3 and W3 > W2 and W2 > W4) or
(W2 > W1 and W1 > W3 and W3 > W4), 40, If(W2 > W1 and W1 > W4 and W4 > W3, 30,
If((W1 > W3 and W3 > W4 and W4 > W2) or ( W1 > W4 and W4 > W2 and W2 > W3)  or
(W2 > W3 and W3 > W1 and W1 > W4)  or (W3 > W1 and W1 > W2 and W2 > W4) , 20,
If((W1 > W4 and W4 > W3 and W3 > W2) or (W3 > W2 and W2 > W1 and W1 > W4), 10, 0)))));
    def WCondition2 = If(W4 > W3 and W3 > W2 and W2 > W1, -50,
If((W3 > W4 and W4 > W2 and W2 > W1) or (W4 > W2 and W2 > W3 and W3 > W1) or
(W4 > W3 and W3 > W1 and W1 > W2), -40, If(W3 > W4 and W4 > W1 and W1 > W2, -30,
If((W2 > W4 and W4 > W3 and W3 > W1) or (W3 > W2 and W2 > W4 and W4 > W1)  or
(W4 > W1 and W1 > W3 and W3 > W2)  or (W4 > W2 and W2 > W1 and W1 > W3) , -20,
If((W2 > W3 and W3 > W4 and W4 > W1) or (W4 > W1 and W1 > W2 and W2 > W3), -10, 0)))));
    def WT = (WCondition1 + WCondition2);
    def TT = (WCondition1 + WCondition2 + DCondition1 + DCondition2);
#####signals
    plot ALong = TT > WT;
}
script SymbolRank_AShort {
    input symbol = "";
    def price1 = (close(symbol) + open(symbol)) / 2;
    input Length1 = 3;
    input Length2 = 6;
    input Length3 = 9;
    input Length4 = 12;
    input Length5 = 15;
    input Length6 = 30;
    input Length7 = 45;
    input Length8 = 60;
    input averageType = AverageType.EXPONENTIAL;
    def D1 = MovingAverage(averageType, price1, Length1);
    def D2 = MovingAverage(averageType, price1, Length2);
    def D3 = MovingAverage(averageType, price1, Length3);
    def D4 = MovingAverage(averageType, price1, Length4);
    def W1 = MovingAverage(averageType, price1, Length5);
    def W2 = MovingAverage(averageType, price1, Length6);
    def W3 = MovingAverage(averageType, price1, Length7);
    def W4 = MovingAverage(averageType, price1, Length8);
    def DCondition1 = If(D1 > D2 and D2 > D3 and D3 > D4, 5,
 If((D1 > D2 and D2 > D4 and D4 > D3) or (D1 > D3 and D3 > D2 and D2 > D4) or
(D2 > D1 and D1 > D3 and D3 > D4), 4, If(D2 > D1 and D1 > D4 and D4 > D3, 3,
If((D1 > D3 and D3 > D4 and D4 > D2) or ( D1 > D4 and D4 > D2 and D2 > D3)  or
(D2 > D3 and D3 > D1 and D1 > D4)  or (D3 > D1 and D1 > D2 and D2 > D4) , 2,
If((D1 > D4 and D4 > D3 and D3 > D2) or (D3 > D2 and D2 > D1 and D1 > D4), 1, 0)))));
    def DCondition2 = If(D4 > D3 and D3 > D2 and D2 > D1, -5,
If((D3 > D4 and D4 > D2 and D2 > D1) or (D4 > D2 and D2 > D3 and D3 > D1) or
(D4 > D3 and D3 > D1 and D1 > D2), -4, If(D3 > D4 and D4 > D1 and D1 > D2, -3,
If((D2 > D4 and D4 > D3 and D3 > D1) or (D3 > D2 and D2 > D4 and D4 > D1)  or
(D4 > D1 and D1 > D3 and D3 > D2)  or (D4 > D2 and D2 > D1 and D1 > D3) , -2,
If((D2 > D3 and D3 > D4 and D4 > D1) or (D4 > D1 and D1 > D2 and D2 > D3), -1, 0)))));
    def WCondition1 = If(W1 > W2 and W2 > W3 and W3 > W4, 50,
 If((W1 > W2 and W2 > W4 and W4 > W3) or (W1 > W3 and W3 > W2 and W2 > W4) or
(W2 > W1 and W1 > W3 and W3 > W4), 40, If(W2 > W1 and W1 > W4 and W4 > W3, 30,
If((W1 > W3 and W3 > W4 and W4 > W2) or ( W1 > W4 and W4 > W2 and W2 > W3)  or
(W2 > W3 and W3 > W1 and W1 > W4)  or (W3 > W1 and W1 > W2 and W2 > W4) , 20,
If((W1 > W4 and W4 > W3 and W3 > W2) or (W3 > W2 and W2 > W1 and W1 > W4), 10, 0)))));
    def WCondition2 = If(W4 > W3 and W3 > W2 and W2 > W1, -50,
If((W3 > W4 and W4 > W2 and W2 > W1) or (W4 > W2 and W2 > W3 and W3 > W1) or
(W4 > W3 and W3 > W1 and W1 > W2), -40, If(W3 > W4 and W4 > W1 and W1 > W2, -30,
If((W2 > W4 and W4 > W3 and W3 > W1) or (W3 > W2 and W2 > W4 and W4 > W1)  or
(W4 > W1 and W1 > W3 and W3 > W2)  or (W4 > W2 and W2 > W1 and W1 > W3) , -20,
If((W2 > W3 and W3 > W4 and W4 > W1) or (W4 > W1 and W1 > W2 and W2 > W3), -10, 0)))));
    def WT = (WCondition1 + WCondition2);
    def TT = (WCondition1 + WCondition2 + DCondition1 + DCondition2);
#####signals
    plot AShort = TT < WT;
}
def s1R1 = SymbolRank_ALong(symbol1);
def s2R1 = SymbolRank_ALong(symbol2);
def s3R1 = SymbolRank_ALong(symbol3);
def s4R1 = SymbolRank_ALong(symbol4);
def s5R1 = SymbolRank_ALong (symbol5);
def s6R1 = SymbolRank_ALong (symbol6);
def s7R1 = SymbolRank_ALong (symbol7);
def s8R1 = SymbolRank_ALong (symbol8);
def s9R1 = SymbolRank_ALong (symbol9);
def s10R1 = SymbolRank_ALong (symbol10);
def s11R1 = SymbolRank_ALong (symbol11);
def s12R1 = SymbolRank_ALong (symbol12);
def s13R1 = SymbolRank_ALong (symbol13);
def s14R1 = SymbolRank_ALong (symbol14);
def s15R1 = SymbolRank_ALong (symbol15);
def s16R1 = SymbolRank_ALong (symbol16);
def s17R1 = SymbolRank_ALong (symbol17);
def s18R1 = SymbolRank_ALong (symbol18);
def s19R1 = SymbolRank_ALong (symbol19);
def s20R1 = SymbolRank_ALong (symbol20);
def s21R1 = SymbolRank_ALong (symbol21);
def s22R1 = SymbolRank_ALong (symbol22);
def s23R1 = SymbolRank_ALong (symbol23);
def s24R1 = SymbolRank_ALong (symbol24);
def s25R1 = SymbolRank_ALong (symbol25);
def s26R1 = SymbolRank_ALong (symbol26);

def s1R2 = SymbolRank_AShort(symbol1);
def s2R2 = SymbolRank_AShort(symbol2);
def s3R2 = SymbolRank_AShort(symbol3);
def s4R2 = SymbolRank_AShort(symbol4);
def s5R2 = SymbolRank_AShort (symbol5);
def s6R2 = SymbolRank_AShort (symbol6);
def s7R2 = SymbolRank_AShort (symbol7);
def s8R2 = SymbolRank_AShort (symbol8);
def s9R2 = SymbolRank_AShort(symbol9);
def s10R2 = SymbolRank_AShort (symbol10);
def s11R2 = SymbolRank_AShort (symbol11);
def s12R2 = SymbolRank_AShort (symbol12);
def s13R2 = SymbolRank_AShort (symbol13);
def s14R2 = SymbolRank_AShort (symbol14);
def s15R2 = SymbolRank_AShort (symbol15);
def s16R2 = SymbolRank_AShort (symbol16);
def s17R2 = SymbolRank_AShort (symbol17);
def s18R2 = SymbolRank_AShort (symbol18);
def s19R2 = SymbolRank_AShort(symbol19);
def s20R2 = SymbolRank_AShort (symbol20);
def s21R2 = SymbolRank_AShort (symbol21);
def s22R2 = SymbolRank_AShort (symbol22);
def s23R2 = SymbolRank_AShort (symbol23);
def s24R2 = SymbolRank_AShort (symbol24);
def s25R2 = SymbolRank_AShort (symbol25);
def s26R2 = SymbolRank_AShort (symbol26);

def s1R3 = SymbolRank_AXS(symbol1);
def s2R3 = SymbolRank_AXS(symbol2);
def s3R3 = SymbolRank_AXS(symbol3);
def s4R3 = SymbolRank_AXS(symbol4);
def s5R3 = SymbolRank_AXS (symbol5);
def s6R3 = SymbolRank_AXS (symbol6);
def s7R3 = SymbolRank_AXS (symbol7);
def s8R3 = SymbolRank_AXS (symbol8);
def s9R3 = SymbolRank_AXS(symbol9);
def s10R3 = SymbolRank_AXS (symbol10);
def s11R3 = SymbolRank_AXS (symbol11);
def s12R3 = SymbolRank_AXS (symbol12);
def s13R3 = SymbolRank_AXS (symbol13);
def s14R3 = SymbolRank_AXS (symbol14);
def s15R3 = SymbolRank_AXS (symbol15);
def s16R3 = SymbolRank_AXS (symbol16);
def s17R3 = SymbolRank_AXS (symbol17);
def s18R3 = SymbolRank_AXS (symbol18);
def s19R3 = SymbolRank_AXS(symbol19);
def s20R3 = SymbolRank_AXS (symbol20);
def s21R3 = SymbolRank_AXS (symbol21);
def s22R3 = SymbolRank_AXS (symbol22);
def s23R3 = SymbolRank_AXS (symbol23);
def s24R3 = SymbolRank_AXS (symbol24);
def s25R3 = SymbolRank_AXS (symbol25);
def s26R3 = SymbolRank_AXS (symbol26);

def s1R4 = SymbolRank_AXL(symbol1);
def s2R4 = SymbolRank_AXL(symbol2);
def s3R4 = SymbolRank_AXL(symbol3);
def s4R4 = SymbolRank_AXL(symbol4);
def s5R4 = SymbolRank_AXL (symbol5);
def s6R4 = SymbolRank_AXL (symbol6);
def s7R4 = SymbolRank_AXL (symbol7);
def s8R4 = SymbolRank_AXL (symbol8);
def s9R4 = SymbolRank_AXL(symbol9);
def s10R4 = SymbolRank_AXL (symbol10);
def s11R4 = SymbolRank_AXL (symbol11);
def s12R4 = SymbolRank_AXL (symbol12);
def s13R4 = SymbolRank_AXL (symbol13);
def s14R4 = SymbolRank_AXL (symbol14);
def s15R4 = SymbolRank_AXL (symbol15);
def s16R4 = SymbolRank_AXL (symbol16);
def s17R4 = SymbolRank_AXL (symbol17);
def s18R4 = SymbolRank_AXL (symbol18);
def s19R4 = SymbolRank_AXL(symbol19);
def s20R4 = SymbolRank_AXL (symbol20);
def s21R4 = SymbolRank_AXL (symbol21);
def s22R4 = SymbolRank_AXL (symbol22);
def s23R4 = SymbolRank_AXL (symbol23);
def s24R4 = SymbolRank_AXL (symbol24);
def s25R4 = SymbolRank_AXL (symbol25);
def s26R4 = SymbolRank_AXL (symbol26);


#######Plots

plot symb1 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 1 else Double.NaN;
symb1.SetPaintingStrategy(PaintingStrategy.POINTS);
symb1.SetLineWeight(DotSize);
symb1.AssignValueColor(if s1R4 == 1 then GlobalColor("Buy") else if s1R3 == 1 then GlobalColor(“Sell”) else if s1R2 == 1 then GlobalColor(“AShort”) else if s1R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol1)[1]), 1, "1: " + symbol1, if s1R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb1.HideBubble();

plot symb2 = if !IsNaN(close) and !IsNaN(close(symbol2)) then 2 else Double.NaN;
symb2.SetPaintingStrategy(PaintingStrategy.POINTS);
symb2.SetLineWeight(DotSize);
symb2.AssignValueColor(if s2R4 == 1 then GlobalColor("Buy") else if s2R3 == 1 then GlobalColor(“Sell”) else if s2R2 == 1 then GlobalColor(“AShort”) else if s2R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol2)[5]), 2, "2: " + symbol2, if s2R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb2.HideBubble();

plot symb3 = if !IsNaN(close) and !IsNaN(close(symbol3)) then 3 else Double.NaN;
symb3.SetPaintingStrategy(PaintingStrategy.POINTS);
symb3.SetLineWeight(DotSize);
symb3.AssignValueColor(if s3R4 == 1 then GlobalColor("Buy") else if s3R3 == 1 then GlobalColor(“Sell”) else if s3R2 == 1 then GlobalColor(“AShort”) else if s3R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol3)[1]), 3, "3: " + symbol3, if s3R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb3.HideBubble();

plot symb4 = if !IsNaN(close) and !IsNaN(close(symbol4)) then 4 else Double.NaN;
symb4.SetPaintingStrategy(PaintingStrategy.POINTS);
symb4.SetLineWeight(DotSize);
symb4.AssignValueColor(if s4R4 == 1 then GlobalColor("Buy") else if s4R3 == 1 then GlobalColor(“Sell”) else if s4R2 == 1 then GlobalColor(“AShort”) else if s4R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol4)[5]), 4, "4: " + symbol4, if s4R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb4.HideBubble();

plot symb5 = if !IsNaN(close) and !IsNaN(close(symbol5)) then 5 else Double.NaN;
symb5.SetPaintingStrategy(PaintingStrategy.POINTS);
symb5.SetLineWeight(DotSize);
symb5.AssignValueColor(if s5R4 == 1 then GlobalColor("Buy") else if s5R3 == 1 then GlobalColor(“Sell”) else if s5R2 == 1 then GlobalColor(“AShort”) else if s5R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol5)[1]), 5, "5: " + symbol1, if s5R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb5.HideBubble();

plot symb6 = if !IsNaN(close) and !IsNaN(close(symbol6)) then 6 else Double.NaN;
symb6.SetPaintingStrategy(PaintingStrategy.POINTS);
symb6.SetLineWeight(DotSize);
symb6.AssignValueColor(if s6R4 == 1 then GlobalColor("Buy") else if s6R3 == 1 then GlobalColor(“Sell”) else if s6R2 == 1 then GlobalColor(“AShort”) else if s6R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol6)[5]), 6, "6: " + symbol6, if s6R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb6.HideBubble();

plot symb7 = if !IsNaN(close) and !IsNaN(close(symbol7)) then 7 else Double.NaN;
symb7.SetPaintingStrategy(PaintingStrategy.POINTS);
symb7.SetLineWeight(DotSize);
symb7.AssignValueColor(if s7R4 == 1 then GlobalColor("Buy") else if s7R3 == 1 then GlobalColor(“Sell”) else if s7R2 == 1 then GlobalColor(“AShort”) else if s7R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol7)[1]), 7, "7: " + symbol7, if s7R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb7.HideBubble();

plot symb8 = if !IsNaN(close) and !IsNaN(close(symbol8)) then 8 else Double.NaN;
symb8.SetPaintingStrategy(PaintingStrategy.POINTS);
symb8.SetLineWeight(DotSize);
symb8.AssignValueColor(if s8R4 == 1 then GlobalColor("Buy") else if s8R3 == 1 then GlobalColor(“Sell”) else if s8R2 == 1 then GlobalColor(“AShort”) else if s8R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol8)[5]), 8, "8: " + symbol8, if s8R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb8.HideBubble();

plot symb9 = if !IsNaN(close) and !IsNaN(close(symbol9)) then 9 else Double.NaN;
symb9.SetPaintingStrategy(PaintingStrategy.POINTS);
symb9.SetLineWeight(DotSize);
symb9.AssignValueColor(if s9R4 == 1 then GlobalColor("Buy") else if s9R3 == 1 then GlobalColor(“Sell”) else if s9R2 == 1 then GlobalColor(“AShort”) else if s9R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol9)[1]), 9, "9: " + symbol9, if s9R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb9.HideBubble();
plot symb10 = if !IsNaN(close) and !IsNaN(close(symbol10)) then 10 else Double.NaN;
symb10.SetPaintingStrategy(PaintingStrategy.POINTS);
symb10.SetLineWeight(DotSize);
symb10.AssignValueColor(if s10R4 == 1 then GlobalColor("Buy") else if s10R3 == 1 then GlobalColor(“Sell”) else if s10R2 == 1 then GlobalColor(“AShort”) else if s10R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol10)[5]), 10, "10: " + symbol10, if s10R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb10.HideBubble();
plot symb11 = if !IsNaN(close) and !IsNaN(close(symbol11)) then 11 else Double.NaN;
symb11.SetPaintingStrategy(PaintingStrategy.POINTS);
symb11.SetLineWeight(DotSize);
symb11.AssignValueColor(if s11R4 == 1 then GlobalColor("Buy") else if s11R3 == 1 then GlobalColor(“Sell”) else if s11R2 == 1 then GlobalColor(“AShort”) else if s11R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol11)[1]), 11, "11: " + symbol1, if s11R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb11.HideBubble();

plot symb12 = if !IsNaN(close) and !IsNaN(close(symbol12)) then 13 else Double.NaN;
symb12.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb12.SetLineWeight(DotSize);
symb12.AssignValueColor(if s12R4 == 1 then GlobalColor("Buy") else if s12R3 == 1 then GlobalColor(“Sell”) else if s12R2 == 1 then GlobalColor(“AShort”) else if s12R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol12)[1]), 13, "13: " + symbol12, if s12R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb12.HideBubble();
plot symb13 = if !IsNaN(close) and !IsNaN(close(symbol13)) then 14 else Double.NaN;
symb13.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb13.SetLineWeight(DotSize);
symb13.AssignValueColor(if s13R4 == 1 then GlobalColor("Buy") else if s13R3 == 1 then GlobalColor(“Sell”) else if s13R2 == 1 then GlobalColor(“AShort”) else if s13R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol13)[5]), 14, "14: " + symbol13, if s13R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb13.HideBubble();
plot symb14 = if !IsNaN(close) and !IsNaN(close(symbol14)) then 15 else Double.NaN;
symb14.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb14.SetLineWeight(DotSize);
symb14.AssignValueColor(if s14R4 == 1 then GlobalColor("Buy") else if s14R3 == 1 then GlobalColor(“Sell”) else if s14R2 == 1 then GlobalColor(“AShort”) else if s14R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol14)[1]), 15, "15: " + symbol14, if s14R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb14.HideBubble();
plot symb15 = if !IsNaN(close) and !IsNaN(close(symbol15)) then 16 else Double.NaN;
symb15.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb15.SetLineWeight(DotSize);
symb15.AssignValueColor(if s15R4 == 1 then GlobalColor("Buy") else if s15R3 == 1 then GlobalColor(“Sell”) else if s15R2 == 1 then GlobalColor(“AShort”) else if s15R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol15)[5]), 16, "16: " + symbol15, if s15R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb15.HideBubble();
plot symb16 = if !IsNaN(close) and !IsNaN(close(symbol16)) then 17 else Double.NaN;
symb16.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb16.SetLineWeight(DotSize);
symb16.AssignValueColor(if s16R4 == 1 then GlobalColor("Buy") else if s16R3 == 1 then GlobalColor(“Sell”) else if s16R2 == 1 then GlobalColor(“AShort”) else if s16R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol16)[1]), 17, "17: " + symbol16, if s16R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
symb16.HideBubble();
plot symb17 = if !IsNaN(close) and !IsNaN(close(symbol17)) then 18 else Double.NaN;
symb17.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb17.SetLineWeight(DotSize);
symb17.AssignValueColor(if s17R4 == 1 then GlobalColor("Buy") else if s17R3 == 1 then GlobalColor(“Sell”) else if s17R2 == 1 then GlobalColor(“AShort”) else if s17R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol17)[5]), 18, "18: " + symbol17, if s17R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb17.HideBubble();

plot symb18 = if !IsNaN(close) and !IsNaN(close(symbol18)) then 19 else Double.NaN;
symb18.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb18.SetLineWeight(DotSize);
symb18.AssignValueColor(if s18R4 == 1 then GlobalColor("Buy") else if s18R3 == 1 then GlobalColor(“Sell”) else if s18R2 == 1 then GlobalColor(“AShort”) else if s18R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol18)[1]), 19, "19: " + symbol18, if s18R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb18.HideBubble();

plot symb19 = if !IsNaN(close) and !IsNaN(close(symbol19)) then 20 else Double.NaN;
symb19.SetPaintingStrategy(PaintingStrategy.Triangles);
symb19.SetLineWeight(DotSize);
symb19.AssignValueColor(if s19R4 == 1 then GlobalColor("Buy") else if s19R3 == 1 then GlobalColor(“Sell”) else if s19R2 == 1 then GlobalColor(“AShort”) else if s19R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol19)[5]), 20, "20: " + symbol19, if s19R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb19.HideBubble();
plot symb20 = if !IsNaN(close) and !IsNaN(close(symbol20)) then 21 else Double.NaN;
symb20.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb20.SetLineWeight(DotSize);
symb20.AssignValueColor(if s20R4 == 1 then GlobalColor("Buy") else if s20R3 == 1 then GlobalColor(“Sell”) else if s20R2 == 1 then GlobalColor(“AShort”) else if s20R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol20)[1]), 21, "21: " + symbol20, if s20R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb20.HideBubble();
plot symb21 = if !IsNaN(close) and !IsNaN(close(symbol21)) then 22 else Double.NaN;
symb21.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb21.SetLineWeight(DotSize);
symb21.AssignValueColor(if s21R4 == 1 then GlobalColor("Buy") else if s21R3 == 1 then GlobalColor(“Sell”) else if s21R2 == 1 then GlobalColor(“AShort”) else if s21R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol21)[5]), 22, "22: " + symbol21, if s21R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb21.HideBubble();

plot symb22 = if !IsNaN(close) and !IsNaN(close(symbol22)) then 23 else Double.NaN;
symb22.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb22.SetLineWeight(DotSize);
symb22.AssignValueColor(if s22R4 == 1 then GlobalColor("Buy") else if s22R3 == 1 then GlobalColor(“Sell”) else if s22R2 == 1 then GlobalColor(“AShort”) else if s22R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol22)[1]), 23, "23: " + symbol22, if s22R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb22.HideBubble();
plot symb23 = if !IsNaN(close) and !IsNaN(close(symbol23)) then 24 else Double.NaN;
symb23.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb23.SetLineWeight(DotSize);
symb23.AssignValueColor(if s23R4 == 1 then GlobalColor("Buy") else if s23R3 == 1 then GlobalColor(“Sell”) else if s23R2 == 1 then GlobalColor(“AShort”) else if s23R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol23)[5]), 24, "24: " + symbol23, if s23R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb23.HideBubble();
plot symb24 = if !IsNaN(close) and !IsNaN(close(symbol24)) then 25 else Double.NaN;
symb24.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb24.SetLineWeight(DotSize);
symb24.AssignValueColor(if s24R4 == 1 then GlobalColor("Buy") else if s24R3 == 1 then GlobalColor(“Sell”) else if s24R2 == 1 then GlobalColor(“AShort”) else if s24R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol24)[1]), 25, "25: " + symbol24, if s24R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb24.HideBubble();
plot symb25 = if !IsNaN(close) and !IsNaN(close(symbol25)) then 26 else Double.NaN;
symb25.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb25.SetLineWeight(DotSize);
symb25.AssignValueColor(if s25R4 == 1 then GlobalColor("Buy") else if s25R3 == 1 then GlobalColor(“Sell”) else if s25R2 == 1 then GlobalColor(“AShort”) else if s25R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close[4]) and !IsNaN(close[5]) and !IsNaN(close(symbol25)[5]), 26, "26: " + symbol25, if s25R1[5] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb25.HideBubble();
plot symb26 = if !IsNaN(close) and !IsNaN(close(symbol26)) then 27 else Double.NaN;
symb26.SetPaintingStrategy(PaintingStrategy.TRIANGLES);
symb26.SetLineWeight(DotSize);
symb26.AssignValueColor(if s26R4 == 1 then GlobalColor("Buy") else if s26R3 == 1 then GlobalColor(“Sell”) else if s26R2 == 1 then GlobalColor(“AShort”) else if s26R1 == 1 then GlobalColor(“ALong") else GlobalColor("Neutral"));
AddChartBubble(showLabels and IsNaN(close) and !IsNaN(close[1]) and !IsNaN(close(symbol26)[1]), 27, "27: " + symbol26, if s26R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"), yes);
Symb26.HideBubble();

plot spacer0 = if !IsNaN(close) and !IsNaN(close(symbol10)) then 10.5 else Double.NaN;
plot spacer1 = if !IsNaN(close) and !IsNaN(close(symbol1)) then 1.5 else Double.NaN;
plot spacer2 = if !IsNaN(close) and !IsNaN(close(symbol2)) then 2.5 else Double.NaN;
plot spacer3 = if !IsNaN(close) and !IsNaN(close(symbol3)) then 3.5 else Double.NaN;
plot spacer4 = if !IsNaN(close) and !IsNaN(close(symbol4)) then 4.5 else Double.NaN;
plot spacer5 = if !IsNaN(close)  and !IsNaN(close(symbol5)) then 5.5 else Double.NaN;
plot spacer6 = if !IsNaN(close) and !IsNaN(close(symbol6)) then 6.5 else Double.NaN;
plot spacer7 = if !IsNaN(close) and !IsNaN(close(symbol7)) then 7.5 else Double.NaN;
plot spacer8 = if !IsNaN(close) and !IsNaN(close(symbol8)) then 8.5 else Double.NaN;
plot spacer9 = if !IsNaN(close) and !IsNaN(close(symbol9)) then 9.5 else Double.NaN;
plot spacer10 = if !IsNaN(close) and !IsNaN(close(symbol10)) then 10.5 else Double.NaN;
plot spacer11 = if !IsNaN(close)  and !IsNaN(close(symbol11)) then 11.5 else Double.NaN;
plot spacer12 = if !IsNaN(close) and !IsNaN(close(symbol12)) then 12.5 else Double.NaN;
plot spacer13 = if !IsNaN(close) and !IsNaN(close(symbol13)) then 13.5 else Double.NaN;
plot spacer14 = if !IsNaN(close) and !IsNaN(close(symbol14)) then 14.5 else Double.NaN;
plot spacer15 = if !IsNaN(close) and !IsNaN(close(symbol15)) then 15.5 else Double.NaN;
plot spacer16 = if !IsNaN(close) and !IsNaN(close(symbol16)) then 16.5 else Double.NaN;
plot spacer17 = if !IsNaN(close) and !IsNaN(close(symbol17)) then 17.5 else Double.NaN;
plot spacer18 = if !IsNaN(close) and !IsNaN(close(symbol18)) then 18.5 else Double.NaN;
plot spacer19 = if !IsNaN(close) and !IsNaN(close(symbol19)) then 19.5 else Double.NaN;
plot spacer20 = if !IsNaN(close) and !IsNaN(close(symbol20)) then 20.5 else Double.NaN;
plot spacer21 = if !IsNaN(close)  and !IsNaN(close(symbol21)) then 21.5 else Double.NaN;
plot spacer22 = if !IsNaN(close) and !IsNaN(close(symbol22)) then 22.5 else Double.NaN;
plot spacer23 = if !IsNaN(close) and !IsNaN(close(symbol23)) then 23.5 else Double.NaN;
plot spacer24 = if !IsNaN(close) and !IsNaN(close(symbol24)) then 24.5 else Double.NaN;
plot spacer25 = if !IsNaN(close) and !IsNaN(close(symbol25)) then 25.5 else Double.NaN;
plot spacer26 = if !IsNaN(close) and !IsNaN(close(symbol26)) then 26.5 else Double.NaN;

spacer0.SetDefaultColor(Color.GRAY);
spacer1.SetDefaultColor(Color.GRAY);
spacer2.SetDefaultColor(Color.GRAY);
spacer3.SetDefaultColor(Color.GRAY);
spacer4.SetDefaultColor(Color.GRAY);
spacer5.SetDefaultColor(Color.GRAY);
spacer6.SetDefaultColor(Color.GRAY);
spacer7.SetDefaultColor(Color.GRAY);
spacer8.SetDefaultColor(Color.GRAY);
spacer9.SetDefaultColor(Color.GRAY);
spacer10.SetDefaultColor(Color.GRAY);
spacer11.SetDefaultColor(Color.GRAY);
spacer12.SetDefaultColor(Color.GRAY);
spacer13.SetDefaultColor(Color.GRAY);
spacer14.SetDefaultColor(Color.GRAY);
spacer15.SetDefaultColor(Color.GRAY);
spacer16.SetDefaultColor(Color.GRAY);
spacer17.SetDefaultColor(Color.GRAY);
spacer18.SetDefaultColor(Color.GRAY);
spacer19.SetDefaultColor(Color.GRAY);
spacer20.SetDefaultColor(Color.GRAY);
spacer21.SetDefaultColor(Color.GRAY);
spacer22.SetDefaultColor(Color.GRAY);
spacer23.SetDefaultColor(Color.GRAY);
spacer24.SetDefaultColor(Color.GRAY);
spacer25.SetDefaultColor(Color.GRAY);
spacer26.SetDefaultColor(Color.GRAY);

spacer0.HideBubble();
spacer1.HideBubble();
spacer2.HideBubble();
spacer3.HideBubble();
spacer4.HideBubble();
spacer5.HideBubble();
spacer6.HideBubble();
spacer7.HideBubble();
spacer8.HideBubble();
spacer9.HideBubble();
spacer10.HideBubble();
spacer11.HideBubble();
spacer12.HideBubble();
spacer13.HideBubble();
spacer14.HideBubble();
spacer15.HideBubble();
spacer16.HideBubble();
spacer17.HideBubble();
spacer18.HideBubble();
spacer19.HideBubble();
spacer20.HideBubble();
spacer21.HideBubble();
spacer22.HideBubble();
spacer23.HideBubble();
spacer24.HideBubble();
spacer25.HideBubble();
spacer26.HideBubble();
spacer0.HideTitle();
spacer1.HideTitle();
spacer2.HideTitle();
spacer3.HideTitle();
spacer4.HideTitle();
spacer5.HideTitle();
spacer6.HideTitle();
spacer7.HideTitle();
spacer8.HideTitle();
spacer9.HideTitle();
spacer10.HideTitle();
spacer11.HideTitle();
spacer12.HideTitle();
spacer13.HideTitle();
spacer14.HideTitle();
spacer15.HideTitle();
spacer16.HideTitle();
spacer17.HideTitle();
spacer18.HideTitle();
spacer19.HideTitle();
spacer20.HideTitle();
spacer21.HideTitle();
spacer22.HideTitle();
spacer23.HideTitle();
spacer24.HideTitle();
spacer25.HideTitle();
spacer26.HideTitle();

DefineGlobalColor("Pre_Cyan", CreateColor(50, 200, 255)) ;
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
DefineGlobalColor("LabelRed",  CreateColor(225, 0, 0)) ;

input BetaLength = 21;
input StochLength = 34;
input showOverlay = yes;

AddLabel(1, "R-Beta/Stoch (" + BetaLength + "," + StochLength + ") ", Color.LIGHT_GRAY);


script calcBeta {
    input secondSymbol = "XLF";
    input refSymbol = "SPX";
    input betaLength = 21;
    input returnLength = 1;

    def refPrice = close(refSymbol);
    def primary = if refPrice[returnLength] == 0
                then 0
                else (refPrice - refPrice[returnLength]) / refPrice[returnLength] * 100;
    def secondPrice = close(secondSymbol);
    def secondary = if secondPrice[returnLength] == 0
                  then 0
                  else (secondPrice - secondPrice[returnLength]) / secondPrice[returnLength] * 100;
    plot Beta = Covariance(secondary, primary, betaLength) / Sqr(StDev(primary, betaLength));
}

script EhlersESSfilter {
    input price = close;
    input length = 8;
    def ESS_coeff_0 = Exp(-Double.Pi * Sqrt(2) / length);
    def ESS_coeff_2 = 2 * ESS_coeff_0 * Cos(Sqrt(2) * Double.Pi / length);
    def ESS_coeff_3 = - Sqr(ESS_coeff_0);
    def ESS_coeff_1 = 1 - ESS_coeff_2 - ESS_coeff_3;
    def ESS_filter = if IsNaN(price + price[1]) then
                      ESS_filter[1]
                 else ESS_coeff_1 * (price + price[1]) / 2 +
                      ESS_coeff_2 * ESS_filter[1] +
                      ESS_coeff_3 * ESS_filter[2];
    plot Smooth_Filter =
         if BarNumber() <  length then
              price
         else if !IsNaN(price) then
              ESS_filter
         else Double.NaN;
}

script calcStoch {
    input data = close;
    input StochLength = 21;
    def stochasticValue = ((data - Lowest(data, StochLength)) / (Highest(data, StochLength) - Lowest(data, StochLength)));
    plot stoch = stochasticValue;
}

####
def upStochLimit = 0.95;
def lowStockLimit = 0.05;

def stoch1 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol1, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "1:" + Symbol1,
if stoch1 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch1 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch1 >= stoch1[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch2 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol2, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "2:" + Symbol2,
if stoch2 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch2 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch2 >= stoch2[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch3 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol3, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "3:" + Symbol3,
if stoch3 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch3 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch3 >= stoch3[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch4 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol4, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "4:" + Symbol4,
if stoch4 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch4 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch4 >= stoch4[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch5 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol5, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "5:" + Symbol5,
if stoch5 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch5 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch5 >= stoch5[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch6 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol6, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "6:" + Symbol6,
if stoch6 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch6 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch6 >= stoch6[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch7 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol7, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "7:" + Symbol7,
if stoch7 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch7 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch7 >= stoch7[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch8 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol8, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "8:" + Symbol8,
if stoch8 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch8 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch8 >= stoch8[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch9 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol9, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "9:" + Symbol9,
if stoch9 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch9 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch9 >= stoch9[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch10 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol10, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "10:" + Symbol10,
if stoch10 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch10 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch10 >= stoch10[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch11 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol11, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "11:" + Symbol11,
if stoch11 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch11 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch11 >= stoch11[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch12 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol12, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "13:" + Symbol12,
if stoch12 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch12 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch12 >= stoch12[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch13 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol13, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "14:" + Symbol13,
if stoch13 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch13 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch13 >= stoch13[1] then GlobalColor("LabelGreen") else Color.VIOLET);
def stoch14 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol14, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "15:" + Symbol14,
if stoch14 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch14 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch14 >= stoch14[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch15 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol15, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "16:" + Symbol15,
if stoch15 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch15 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch15 >= stoch15[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch16 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol16, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "17:" + Symbol16,
if stoch16 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch16 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch16 >= stoch16[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch17 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol17, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "18:" + Symbol17,
if stoch17 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch17 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch17 >= stoch17[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch18 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol18, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "19:" + Symbol18,
if stoch18 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch18 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch18 >= stoch18[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch19 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol19, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "20:" + Symbol19,
if stoch19 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch19 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch19 >= stoch19[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch20 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol20, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "21:" + Symbol20,
if stoch20 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch20 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch20 >= stoch20[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch21 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol21, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "22:" + Symbol21,
if stoch21 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch21 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch21 >= stoch21[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch22 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol22, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "23:" + Symbol22,
if stoch22 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch22 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch22 >= stoch22[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch23 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol23, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "24:" + Symbol23,
if stoch23 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch23 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch23 >= stoch23[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch24 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol24, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "25:" + Symbol24,
if stoch24 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch24 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch24 >= stoch24[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch25 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol25, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "26:" + Symbol25,
if stoch25 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch25 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch25 >= stoch25[1] then GlobalColor("LabelGreen") else Color.VIOLET);

def stoch26 = calcStoch( data = EhlersESSfilter( calcBeta(secondSymbol = Symbol26, betaLength = betaLength) ), stochLength = StochLength);
AddLabel(showOverlay, "27:" + Symbol26,
if stoch26 <= lowStockLimit then GlobalColor("LabelRed") else
if stoch26 >= upStochLimit  then GlobalColor("Pre_Cyan") else
if stoch26 >= stoch26[1] then GlobalColor("LabelGreen") else Color.VIOLET);


script SymbolSectorP {

    input symb = "";
    def c = close(symbol = symb, period = AggregationPeriod.DAY);
    def PctChg = (c / c[1]) - 1;
    plot pct = Round(PctChg,4)*100;
}
def s1SectP = SymbolSectorP(symbol1);
def s2SectP = SymbolSectorP(symbol2);
def s3SectP = SymbolSectorP(symbol3);
def s4SectP = SymbolSectorP(symbol4);
def s5SectP = SymbolSectorP(symbol5);
def s6SectP = SymbolSectorP(symbol6);
def s7SectP = SymbolSectorP(symbol7);
def s8SectP = SymbolSectorP(symbol8);
def s9SectP = SymbolSectorP(symbol9);
def s10SectP = SymbolSectorP(symbol10);
def s11SectP = SymbolSectorP(symbol11);
def s12SectP = SymbolSectorP(symbol12);
def s13SectP = SymbolSectorP(symbol13);
def s14SectP = SymbolSectorP(symbol14);
def s15SectP = SymbolSectorP(symbol15);
def s16SectP = SymbolSectorP(symbol16);
def s17SectP = SymbolSectorP(symbol17);
def s18SectP = SymbolSectorP(symbol18);
def s19SectP = SymbolSectorP(symbol19);
def s20SectP = SymbolSectorP(symbol20);
def s21SectP = SymbolSectorP(symbol21);
def s22SectP = SymbolSectorP(symbol22);
def s23SectP = SymbolSectorP(symbol23);
def s24SectP = SymbolSectorP(symbol24);
def s25SectP = SymbolSectorP(symbol25);
def s26SectP = SymbolSectorP(symbol26);
AddLabel(1, "S&P Sector Performance", Color.ORANGE);
AddLabel(showLabels == yes,"1:" + symbol1 +  s1SectP + “%”, if s1SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"2:" + symbol2 +  s2SectP + “%”, if s2SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"3:" + symbol3 +  s3SectP + “%”, if s3SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"4:" + symbol4 +  s4SectP + “%”, if s4SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"5:" + symbol5 +  s5SectP + “%”, if s5SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"6:" + symbol6 +  s6SectP + “%”, if s6SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"7:" + symbol7 +  s7SectP + “%”, if s7SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"8:" + symbol8 +  s8SectP + “%”, if s8SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"9:" + symbol9 +  s9SectP + “%”, if s9SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"10:" + symbol10 +  s10SectP + “%”, if s10SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"11:" + symbol11 +  s11SectP + “%”, if s11SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"13:" + symbol12 +  s12SectP + “%”, if s12SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"14:" + symbol13 +  s13SectP + “%”, if s13SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"15:" + symbol14 +  s14SectP + “%”, if s14SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"16:" + symbol15 +  s15SectP + “%”, if s15SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"17:" + symbol16 +  s16SectP + “%”, if s16SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"18:" + symbol17 +  s17SectP + “%”, if s17SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"19:" + symbol18 +  s18SectP + “%”, if s18SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"20:" + symbol19 +  s19SectP + “%”, if s19SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"21:" + symbol20 +  s20SectP + “%”, if s20SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"22:" + symbol21 +  s21SectP + “%”, if s21SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"23:" + symbol22 +  s22SectP + “%”, if s22SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"24:" + symbol23 +  s23SectP + “%”, if s23SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"25:" + symbol24 +  s24SectP + “%”, if s24SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"26:" + symbol25 +  s25SectP + “%”, if s25SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));
AddLabel(showLabels == yes,"27:" + symbol26 +  s26SectP + “%”, if s26SectP > 0 then GlobalColor("Buy") else GlobalColor("Sell"));

script SymbolROC {
    input symbol = "";
    def price = close(symbol);
    input lookback = 21;
    input smoothingPeriod = 10;
    plot SymbolROC = Round(ExpAverage(100 * ((price - price [lookback]) / price [lookback]), smoothingPeriod), 1) ;
}
def s1ROC = SymbolROC(symbol1);
def s2ROC = SymbolROC(symbol2);
def s3ROC = SymbolROC(symbol3);
def s4ROC = SymbolROC(symbol4);
def s5ROC = SymbolROC(symbol5);
def s6ROC = SymbolROC(symbol6);
def s7ROC = SymbolROC(symbol7);
def s8ROC = SymbolROC(symbol8);
def s9ROC = SymbolROC(symbol9);
def s10ROC = SymbolROC(symbol10);
def s11ROC = SymbolROC(symbol11);
def s12ROC = SymbolROC(symbol12);
def s13ROC = SymbolROC(symbol13);
def s14ROC = SymbolROC(symbol14);
def s15ROC = SymbolROC(symbol15);
def s16ROC = SymbolROC(symbol16);
def s17ROC = SymbolROC(symbol17);
def s18ROC = SymbolROC(symbol18);
def s19ROC = SymbolROC(symbol19);
def s20ROC = SymbolROC(symbol20);
def s21ROC = SymbolROC(symbol21);
def s22ROC = SymbolROC(symbol22);
def s23ROC = SymbolROC(symbol23);
def s24ROC = SymbolROC(symbol24);
def s25ROC = SymbolROC(symbol25);
def s26ROC = SymbolROC(symbol26);

AddLabel(ShowLabels == Yes, lookback +" Period ROC " + smoothingPeriod + " Sm",  Color.WHITE);
AddLabel(showLabels == yes,"1:" + symbol1 +  s1ROC + “%”, if s1R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "2: " + symbol2 +  s2ROC + “%”, if s2R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "3: " + symbol3 +  s3ROC + “%”, if s3R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "4: " + symbol4 +  s4ROC + “%”, if s4R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "5: " + symbol5 +  s5ROC + “%”, if s5R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "6: " + symbol6 +  s6ROC + “%”, if s6R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "7: " + symbol7 +  s7ROC + “%”, if s7R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "8: " + symbol8 +  s8ROC + “%”, if s8R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "9: " + symbol9 +  s9ROC + “%”, if s9R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "10: " + symbol10 +  s10ROC + “%”, if s10R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "11: " + symbol11 +  s11ROC + “%”, if s11R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "13: " + symbol12 +  s12ROC + “%”, if s12R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "14: " + symbol13 +  s13ROC + “%”, if s13R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "15: " + symbol14 +  s14ROC + “%”, if s14R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "16: " + symbol15 +  s15ROC + “%”, if s15R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "17: " + symbol16 +  s16ROC + “%”, if s16R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "18: " + symbol17 +  s17ROC + “%”, if s17R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "19: " + symbol18 +  s18ROC + “%”, if s18R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "20: " + symbol19 +  s19ROC + “%”, if s19R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "21: " + symbol20 +  s20ROC + “%”, if s20R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "22: " + symbol21 +  s21ROC + “%”, if s21R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "23: " + symbol22 +  s22ROC + “%”, if s22R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "24: " + symbol23 +  s23ROC + “%”, if s23R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "25: " + symbol24 +  s24ROC + “%”, if s24R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "26: " + symbol25 +  s25ROC + “%”, if s25R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
AddLabel(showLabels == yes, "27: " + symbol26 +  s16ROC + “%”, if s26R1[1] > 0 then GlobalColor("ALong") else GlobalColor("AShort"));
 
Very Amazing.
Ultimately, It would be good to have it in this format but I believe that Market Scholars (Former Investools folks) do this in Excel. For ±$3000/year!!
6UthVy0.png
Such a custom indicator sounds like a great way to get people to subscribe to premium.
 
https%3A//i.imgur.com/awFxvbu.png[/img]']
awFxvbu.png



I FOUND THIS CODE FOR IT ON A THINKSCRIPT CLOUD AND TRIED INSERTING IT ON THINKORSWIM BUT FOR SOME REASON IT GIVES ME A WARNING SIGN AS IF SOMETHING IS WRONG WITH THE CODE.
OBVIOUSLY I TRIED REMOVING THE TOP SECTION THAT EXPLAINS THE INDICATOR BUT STILL NOTHING


# beta_rotation_v2

# from 4/4/2019 chat room:
# 06:37 Mobius: johnny - To find rotation quickly - Use primary ETF's in a watchlist with 2 columns first column is Correlation to SPX second is a stochastic of Beta, if Beta is 1 or close to 1 that ETF is moving at the fastest momentum in that range and if correlation is with SPX .85 or better it's moving with SPX cor# daily start with 13,34 as starting point
declare lower;

input BetaLength = 21;
input StochLength =34;
input showBeta = No;
input showOverlay = Yes;

input Cyclicals = "XLY";
input Technology = "XLK";
input Industrials = "XLI";
input Materials = "XLB";
input Energy = "XLE";
input Staples = "XLP";
input HealthCare = "XLV";
input Utilities = "XLU";
input Financials = "XLF";

#------------------------------
#----purple colors
defineglobalColor(“PlumMedium“, createColor(221, 160, 221));
defineglobalColor(“Orchid“, createColor(218, 130, 214));
defineglobalColor(“MediumOrchid“, createColor(186, 85, 211));
defineglobalColor(“MediumPurple“, createColor(147, 112, 219));
defineglobalColor(“DarkOrchid“, createColor(153, 50, 204));


plot Scriptlabel = Double.NaN;
Scriptlabel.SetDefaultColor(CreateColor (0, 0, 0));

def Agg = GetAggregationPeriod();

#--------------------date start
addLabel(1, getMonth() + "/" +
getDayOfMonth(getYyyyMmDd()) + "/" +
AsPrice(getYear()), GlobalColor("PlumMedium"));
#--------------------date end

#addLabel(1, " Ticker: '" + GetSymbol() + "' ", GlobalColor("Orchid"));

addLabel(1, "Agg: " +
( if Agg == 60000 then "1 Min"
else if Agg == 120000 then "2 Min"
else if Agg == 180000 then "3 Min"
else if Agg == 240000 then "4 Min"
else if Agg == 300000 then "5 Min"
else if Agg == 600000 then "10 Min"
else if Agg == 900000 then "15 Min"
else if Agg == 1800000 then "30 Min"
else if Agg == 3600000 then "1 Hour"
else if Agg == 7200000 then "2 Hour"
else if Agg == 14400000 then "4 Hours"
else if Agg == 86400000 then "1 Day"
else if Agg == 604800000 then "1 Week"
else if Agg == 2592000000 then "1 Month"
else (Agg / 1000 / 60) + "Minutes") +
" (" + (if Agg<=23400000
then 23400000/Agg
else 86400000/Agg)+ ")"
, GlobalColor("MediumPurple"));
#addLabel(1, BarNumber() + " Bars", GlobalColor("DarkOrchid"));

#-----------------------------
#-----------------------------

addLabel(1,"Rotation Beta/Stochastic (" + betaLength + "," +stochLength + ") ", color.Light_Gray);


script calcBeta {
input secondSymbol = "XLF";
input refSymbol = "SPX";
input betaLength = 21;
input returnLength = 1;

def refPrice = close(refSymbol);
def primary = if refPrice[returnLength] == 0
then 0
else (refPrice - refPrice[returnLength]) /
refPrice[returnLength] * 100;
def secondPrice = close(secondSymbol);
def secondary = if secondPrice[returnLength] == 0
then 0
else (secondPrice - secondPrice[returnLength]) /
secondPrice[returnLength] * 100;
plot Beta = covariance(secondary, primary, betaLength) /
Sqr(stdev(primary, betaLength));
}

script EhlersESSfilter {
input price = close;
input length = 8;
def ESS_coeff_0 = Exp(-Double.Pi * Sqrt(2) / length);
def ESS_coeff_2 = 2 * ESS_coeff_0 * Cos(Sqrt(2) * Double.Pi / length);
def ESS_coeff_3 = - Sqr(ESS_coeff_0);
def ESS_coeff_1 = 1 - ESS_coeff_2 - ESS_coeff_3;
def ESS_filter = if IsNaN(price + price[1]) then
ESS_filter[1]
else ESS_coeff_1 * (price + price[1]) / 2 +
ESS_coeff_2 * ESS_filter[1] +
ESS_coeff_3 * ESS_filter[2];
plot Smooth_Filter =
if barnumber() < length then
price
else if !IsNaN(price) then
ESS_filter
else Double.NaN;
}

script calcStoch {
input data = close;
input StochLength = 21;
def stochasticValue = ((data - lowest(data, StochLength)) /
(highest(data, StochLength) - lowest(data, StochLength)));
plot stoch = stochasticValue;
}

plot beta1 = if showBeta then calcBeta(Cyclicals) else Double.NaN;
plot beta2 = if showBeta then calcBeta(Technology) else Double.NaN;

plot stoch1 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Cyclicals,
betaLength = BetaLength)),
stochLength = StochLength);
stoch1.SetDefaultColor(Color.VIOLET);
stoch1.SetLineWeight(2);
stoch1.SetPaintingStrategy(PaintingStrategy.LINE_VS_SQUARES);
stoch1.HideBubble();
AddLabel(ShowOverlay, " Cyclicals ", Color.VIOLET);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch1 < 0.15 then 0 else if stoch1 > 0.85 then 1 else stoch1, "Cyclicals", Color.VIOLET, stoch1 > 0.5);

plot stoch2 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Technology,
betaLength = BetaLength)),
stochLength = StochLength);
stoch2.SetDefaultColor(CreateColor(90, 160, 120));
stoch2.SetLineWeight(5);
stoch2.SetStyle(Curve.LONG_DASH);
stoch2.HideBubble();
AddLabel(ShowOverlay, " Techology ", CreateColor(90, 160, 120));
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch2 < 0.15 then 0 else if stoch2 > 0.85 then 1 else stoch2, "Technology", CreateColor(90, 160, 120), stoch2 > 0.5);

plot stoch3 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Industrials,
betaLength = BetaLength)),
stochLength = StochLength);
stoch3.SetDefaultColor(Color.MAGENTA);
stoch3.SetLineWeight(5);
stoch3.SetStyle(Curve.SHORT_DASH);
stoch3.HideBubble();
AddLabel(ShowOverlay, " Industrials ", Color.MAGENTA);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch3 < 0.15 then 0 else if stoch3 > 0.85 then 1 else stoch3, "Industrials", Color.MAGENTA, stoch3 > 0.5);

plot stoch4 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Materials,
betaLength = BetaLength)),
stochLength = StochLength);
stoch4.SetDefaultColor(Color.CYAN);
stoch4.SetLineWeight(2);
stoch4.SetPaintingStrategy(PaintingStrategy.LINE);
stoch4.HideBubble();
AddLabel(ShowOverlay, " Materials ", Color.CYAN);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch4 < 0.15 then 0 else if stoch4 > 0.85 then 1 else stoch4, "Materials", Color.CYAN, stoch4 > 0.5);

plot stoch5 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Energy,
betaLength = BetaLength)),
stochLength = StochLength);
stoch5.SetDefaultColor(Color.YELLOW);
stoch5.SetLineWeight(1);
stoch5.SetPaintingStrategy(PaintingStrategy.Line_vs_POINTS);
stoch5.HideBubble();
AddLabel(ShowOverlay, " Energy ", Color.YELLOW);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch5 < 0.15 then 0 else if stoch5 > 0.85 then 1 else stoch5, "Energy", Color.YELLOW, stoch5 > 0.5);

plot stoch6 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Staples,
betaLength = BetaLength)),
stochLength = StochLength);
stoch6.SetDefaultColor(CreateColor(80, 180, 70));
stoch6.SetLineWeight(2);
stoch6.SetPaintingStrategy(PaintingStrategy.LINE_VS_TRIANGLES);
stoch6.HideBubble();
AddLabel(ShowOverlay, " Staples ", CreateColor(80, 180, 70));
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch6 < 0.15 then 0 else if stoch6 > 0.85 then 1 else stoch6, "Staples", CreateColor(80, 180, 70), stoch6 > close);

plot stoch7 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = HealthCare,
betaLength = BetaLength)),
stochLength = StochLength);
stoch7.SetDefaultColor(CreateColor(180, 80, 180));
stoch7.SetLineWeight(4);
stoch7.SetPaintingStrategy(PaintingStrategy.LINE);
stoch7.HideBubble();
AddLabel(ShowOverlay, " HealthCare ", CreateColor(180, 80, 180));
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch7 < 0.15 then 0 else if stoch7 > 0.85 then 1 else stoch7, "HealthCare", CreateColor(180, 80, 180), stoch7 > 0.5);

plot stoch8 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Utilities,
betaLength = BetaLength)),
stochLength = StochLength);
stoch8.SetDefaultColor(Color.ORANGE);
stoch8.SetLineWeight(2);
stoch8.SetPaintingStrategy(PaintingStrategy.LINE);
stoch8.HideBubble();
AddLabel(ShowOverlay, " Utilities ", Color.ORANGE);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close[0]), if stoch8 < 0.15 then 0 else if stoch8 > 0.85 then 1 else stoch8, "Utilities", Color.ORANGE, stoch8 > 0.5);

plot stoch9 = calcStoch(
data = EhlersESSfilter(
calcBeta(secondSymbol = Financials,
betaLength = BetaLength)),
stochLength = StochLength);
stoch9.SetDefaultColor(Color.PINK);
stoch9.SetLineWeight(2);
stoch9.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
stoch9.HideBubble();
AddLabel(ShowOverlay, " Financials ", Color.PINK);
AddChartBubble(ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), if stoch9 < 0.15 then 0 else if stoch9 > 0.85 then 1 else stoch9, "Financials", Color.PINK, stoch9 > 0.5);

#----------------------------------------------
def barNumber = BarNumber();
def endBar = if !IsNaN(close) and IsNaN(close[-1]) then barNumber else endBar[1];
def lastBar = HighestAll(endBar);
input flowLabelStep = 40;
addLabel(1,"Last Bar = " + lastBar, color.Light_Gray);
DefineGlobalColor("YellowGreen", CreateColor(90, 140, 5));
AddChartBubble(barNumber == (lastBar - flowLabelStep), 1.01,
"M O N E Y F L O W S I N", globalColor("YellowGreen"), 1);
AddChartBubble(barNumber == (lastBar - 2*flowLabelStep), 1.01,
"M O N E Y F L O W S I N", globalColor("YellowGreen"), 1);
AddChartBubble(barNumber == (lastBar - 3*flowLabelStep), 1.01,
"M O N E Y F L O W S I N", globalColor("YellowGreen"), 1);

DefineGlobalColor("Cinamon", CreateColor(200, 10, 40));
AddChartBubble(barNumber == (lastBar - flowLabelStep), -0.01,
"M O N E Y F L O W S O U T", globalColor("Cinamon"), 0);
AddChartBubble(barNumber == (lastBar - 2*flowLabelStep), -0.01,
"M O N E Y F L O W S O U T", globalColor("Cinamon"), 0);
AddChartBubble(barNumber == (lastBar - 3*flowLabelStep), -0.01,
"M O N E Y F L O W S O U T", globalColor("Cinamon"), 0);

#plot zero = if isNaN(close) then double.nan else 0;
plot zero = if barNumber > (lastBar + 7) then double.nan else 0;
zero.SetDefaultColor(createColor(90, 20, 20));
zero.SetStyle(Curve.Long_Dash);
zero.SetLineWeight(5);
zero.HideBubble();
plot one = if barNumber > (lastBar + 7) then double.nan else 1;
one.SetDefaultColor(createColor(20, 70, 20));
one.SetStyle(Curve.Long_Dash);
one.SetLineWeight(5);
one.HideBubble();
 
https%3A//i.imgur.com/awFxvbu.png[/img]']
awFxvbu.png



I FOUND THIS CODE FOR IT ON A THINKSCRIPT CLOUD AND TRIED INSERTING IT ON THINKORSWIM BUT FOR SOME REASON IT GIVES ME A WARNING SIGN AS IF SOMETHING IS WRONG WITH THE CODE.
OBVIOUSLY I TRIED REMOVING THE TOP SECTION THAT EXPLAINS THE INDICATOR BUT STILL NOTHING
Here ya go: see the first post in this thread; read the next 5 pages for the pros and cons of this indicator
 
need to add Bonds/T-Bills to this
We are limited to plotting ETFs.
These are the ETFs associated with the sectors that are plotting currently:
input Cyclicals = "XLY";
input Technology = "XLK";
input Industrials = "XLI";
input Materials = "XLB";
input Energy = "XLE";
input Staples = "XLP";
input HealthCare = "XLV";
input Utilities = "XLU";
input Financials = "XLF";

You can add any additional ETFs that you would like.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
411 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