Sector Rotation Indicator for ThinkorSwim

@BenTen Not exactly, I meant adding labels to the chart showing the performance of each sector. Below an image from the first page of this post that shows the labels, but it doesn't tell you what's happening with the sector; whether it's up or down, the percentage.

FV96OLW.png
did you ever get a response or figure this out. I tried and failed.
 

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

Last edited:
Hi, very remarkable style of graph but I have a simple question for those more experienced on sector rotation: how the information it provides can help to make money decisions that can also be done on simple individual technical analysis? to me it only makes sense to look at it collectively if i would need to choose only 1 or 2 candidates of the 9 candidates to bet on like in a horse track selecting the fastest candidate. I would appreciate if anyone here can tell me if there is other type of consideration that might make this useful?

The reason I am asking this is because along the years I have looked for many indicators that can compensate my lack of visual perception to make money decisions and my mind is overcrowded with possibilities though I know only a few indicators are needed and the rest just creates noise that can do more harm than good.
In general, it narrows down where to look and when to start looking. Especially during transitions. For example a few months back you may have zeroed in on Cannabis stocks and followed the story line as Biden pardoned possession on a federal level, created funding for more research and ideally taken profits as soon as realization hit that the SAFE banking act wasnt going to pass. If your not into selling, at this point yuo may need a new trading idea and this is a good place to start. Some people trade strictly the SPY and follow economic indicators others strictly Forex, ect. At the very least it gives a good place to start looking for trade ideas
 
@diazlaz See if this concept is workable. Idealy, to me, SPY should be at ==0 with the others rotating around it. Thoughts?
@BenTen Please copy this to its own thread...
Code:
# beta_rotation_v2
#ETF_Rotate_Lower_ED_nn 4-2019
# 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
#markos #took out out Beta 1 & 2 4-19-19 # Put Back in 6-23-19

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("time condition" = ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), "price location" = if stoch7 < 0.15 then 0 else if stoch7 > 0.85 then 1 else stoch7, text = "HealthCare", color = 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);
#mAddChartBubble(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);
#mAddChartBubble(barNumber == (lastBar - 3*flowLabelStep), -0.01,
#m"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();
#EOC
hal_rank hal_dup
SectorRotate_ED_NN

Dsy0J1F.png

here is a mod to post 1 that i think makes it easier to interpret the ranking of the stocks.

reply to post2
https://usethinkscript.com/threads/sector-rotation-indicator-for-thinkorswim.845/#post-6369

modify post 1 study , 9 symbols, to look like the post2 image.

change plot lines so they are rounded to nearest integer levels.
used branchless programming (add up number values of logical conditions)
(at approx lines 180+)
ex.
def c1 = (st1>st2)+(st1>st3)+(st1>st4)+(st1>st5)+(st1>st6)+(st1>st7)+(st1>st8)+(st1>st9)+1;


Code:
# Sector_rot_dot_lines_01a

#https://usethinkscript.com/threads/sector-rotation-indicator-for-thinkorswim.845/
#Indicators
#Sector Rotation Indicator for ThinkorSwim
#markos  Oct 11, 2019  #1
#@diazlaz See if this concept is workable. Idealy, to me, SPY should be at ==0 with the others rotating around it. Thoughts?
#@BenTen Please copy this to its own thread...

# beta_rotation_v2
#ETF_Rotate_Lower_ED_nn 4-2019
# 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
#markos #took out out Beta 1 & 2 4-19-19 # Put Back in 6-23-19

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;

####


def st1 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Cyclicals,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st2 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Technology,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st3 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Industrials,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st4 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Materials,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st5 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Energy,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st6 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Staples,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st7 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = HealthCare,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st8 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Utilities,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);

def st9 = calcStoch( data = EhlersESSfilter(
                               calcBeta(secondSymbol = Financials,
                               betaLength = BetaLength)),
                                     stochLength = StochLength);


# determine interger sequence (ranking)
def c1 = (st1>st2)+(st1>st3)+(st1>st4)+(st1>st5)+(st1>st6)+(st1>st7)+(st1>st8)+(st1>st9)+1;
def c2 = (st2>st1)+(st2>st3)+(st2>st4)+(st2>st5)+(st2>st6)+(st2>st7)+(st2>st8)+(st2>st9)+1;
def c3 = (st3>st1)+(st3>st2)+(st3>st4)+(st3>st5)+(st3>st6)+(st3>st7)+(st3>st8)+(st3>st9)+1;
def c4 = (st4>st1)+(st4>st2)+(st4>st3)+(st4>st5)+(st4>st6)+(st4>st7)+(st4>st8)+(st4>st9)+1;
def c5 = (st5>st1)+(st5>st2)+(st5>st3)+(st5>st4)+(st5>st6)+(st5>st7)+(st5>st8)+(st5>st9)+1;
def c6 = (st6>st1)+(st6>st2)+(st6>st3)+(st6>st4)+(st6>st5)+(st6>st7)+(st6>st8)+(st6>st9)+1;
def c7 = (st7>st1)+(st7>st2)+(st7>st3)+(st7>st4)+(st7>st5)+(st7>st6)+(st7>st8)+(st7>st9)+1;
def c8 = (st8>st1)+(st8>st2)+(st8>st3)+(st8>st4)+(st8>st5)+(st8>st6)+(st8>st7)+(st8>st9)+1;
def c9 = (st9>st1)+(st9>st2)+(st9>st3)+(st9>st4)+(st9>st5)+(st9>st6)+(st9>st7)+(st9>st8)+1;

# remove duplicate sequence numbers
def d1 = c1;
def d2 = c2+(c2==c1);
def d3 = c3+(c3==c1)+(c3==c2);
def d4 = c4+(c4==c1)+(c4==c2)+(c4==c3);
def d5 = c5+(c5==c1)+(c5==c2)+(c5==c3)+(c5==c4);
def d6 = c6+(c6==c1)+(c6==c2)+(c6==c3)+(c6==c4)+(c6==c5);
def d7 = c7+(c7==c1)+(c7==c2)+(c7==c3)+(c7==c4)+(c7==c5)+(c7==c6);
def d8 = c8+(c8==c1)+(c8==c2)+(c8==c3)+(c8==c4)+(c8==c5)+(c8==c6)+(c8==c7);
def d9 = c9+(c9==c1)+(c9==c2)+(c9==c3)+(c9==c4)+(c9==c5)+(c9==c6)+(c9==c7)+(c9==c8);


input test1 = no;
addchartbubble(test1 and !isnan(close), 0,
c1 + "  " + d1 + "  " + st1 + "\n" +
c2 + "  " + d2 + "  " + st2 + "\n" +
c3 + "  " + d3 + "  " + st3 + "\n" +
c4 + "  " + d4 + "  " + st4 + "\n" +
c5 + "  " + d5 + "  " + st5 + "\n" +
c6 + "  " + d6 + "  " + st6 + "\n" +
c7 + "  " + d7 + "  " + st7 + "\n" +
c8 + "  " + d8 + "  " + st8 + "\n" +
c9 + "  " + d9 + "  " + st9
, color.yellow, no);


plot stoch1 = d1;
plot stoch2 = d2;
plot stoch3 = d3;
plot stoch4 = d4;
plot stoch5 = d5;
plot stoch6 = d6;
plot stoch7 = d7;
plot stoch8 = d8;
plot stoch9 = d9;


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);

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);

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);

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);

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);

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);


stoch7.SetDefaultColor(CreateColor(180, 80, 180));
stoch7.SetLineWeight(4);
stoch7.SetPaintingStrategy(PaintingStrategy.LINE);
stoch7.HideBubble();
AddLabel(ShowOverlay, " HealthCare ", CreateColor(180, 80, 180));
AddChartBubble("time condition" = ShowOverlay and IsNaN(close[-1]) and !IsNaN(close), "price location" = if stoch7 < 0.15 then 0 else if stoch7 > 0.85 then 1 else stoch7, text = "HealthCare", color = CreateColor(180, 80, 180), stoch7 > 0.5);



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);



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);
#mAddChartBubble(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);
#mAddChartBubble(barNumber == (lastBar - 3*flowLabelStep), -0.01,
#m"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;
plot one = if barNumber > (lastBar + 7) then double.nan else 9;
one.SetDefaultColor(createColor(20, 70, 20));
one.SetStyle(Curve.Long_Dash);
one.SetLineWeight(5);
one.HideBubble();
#EOC
#

line plots, rounded to nearest integer
boom7vi.jpg
 
Last edited:
Saw this on easycators, seems pretty cool and something i'd like to toy around with if anyone has a script for something like this? I have plenty of sector labels but I thought this would be cool to be able to see, i'd love to run some tests on something like this. Thanks in advance!


2023-04-20_11h45_07.png
 
This is a very interesting indicator here. I've done a lot of work on weightings with the S&P and QQQ's utilizing RTD and a couple of sources that are readily available on the interweb via python. (Don't get too impressed - I'm nowhere near an accomplished python coder yet...)

Here's what I know though:

At this link:

https://www.sectorspdrs.com/

You can see the weighting of all of the "X Funds".

1701438894112.png


So, I've started to work toward incorporating those into this indicator. The plan is to put this information on the chart bubbles along with probably abbreviating the sector names a little more and adding the "X" symbol.

1701438742246.png


I haven't kept a close watch on the adjustment of the weightings of these funds but the S&P weightings for each name DO adjust daily, thus the use of input for this. I think I'm going to track these somewhere each day next week just to see the pace of change.

I'll update here once this is complete. I see XLRE and XLC need to be added as well...
 
What I would be interested in is taking correlated ETF's. For example QQQ, XLK, VUG, for the Megacaps or VNQ, XLRE, IYR for real estate. and then looking at the top stock holdings and tracking the % weights of the stocks within the ETF's over time to determine if that particular stock is being accumulated or distributed by the large funds.
However, I do not know where to find the top holdings of ETF's within TOS, much less coding a strategy to monitor the weighting of these stocks within the ETFs.

Any ideas?
 
What I would be interested in is taking correlated ETF's. For example QQQ, XLK, VUG, for the Megacaps or VNQ, XLRE, IYR for real estate. and then looking at the top stock holdings and tracking the % weights of the stocks within the ETF's over time to determine if that particular stock is being accumulated or distributed by the large funds.
However, I do not know where to find the top holdings of ETF's within TOS, much less coding a strategy to monitor the weighting of these stocks within the ETFs.

Any ideas?

Unfortunately, the ToS does not provide a breakdown of the top holdings of ETF's.
A workaround would be to create a manual watchlist table of the top holdings.
And then manually calculate weights for those holdings in a script, similar to this thread:
https://usethinkscript.com/threads/weighted-advance-decline-for-thinkorswim.9487/
 
I was trying to use the sector rotation indicator last week as an alternative to a tool that Barchart has. The Barchart tool just shows a percentage change of each sector on a table, no chart study. But the usethinkscript.com study uses the Stochastic to smooth or just apply the data. Is there a way to just set the study to display the percentage change each day with no smoothing? Possibly I missed an explanation here on this topic and what I want is impractical or unusable. Also, what is the "beta" on the study? Please advise. Thanks from the Ring and the Pinion, both of us.
 
I just pulled up The Ringer Indicator. I dont understand how to use this indicator. Can you please help me, I want to understand. Thanks
Thank you for posting link to the Ringer script, very nice. RSMK compares instrument to SPY or relative strength. You can change it but only one comparison. Ringer allows multiple indexes. I really don't think I'd be able to explain all the possible ways to use the ringer script.
 
Hello Gurus, Good to see sector lables, is there a way we can make a watchlist column to see which sector is doing good at this minute when we watch it at 5 min time frame , like money flowing in?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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