Advance/Decline For 8 Stocks

can this script
https://usethinkscript.com/threads/weighted-advance-decline-for-thinkorswim.9487/page-5#post-137506
be modified to show , mfst, aapl, nvda, amzn, meta, goog tsla, hyg ( instead of the sectors in the code )as a percentage of change from daily opening plotted against the spy and showing each stock with its lable like this above referenced code?

i don't quite understand what you want.
this doesn't compare to SPY. want to verify the math before going too far.

elaborate on what you want.


i added your stocks (next time type them in capitals)
for each, calculate a % change since day open. use that % chg as the WT in formulas

it plots 2 lines, like the original.
like the original, it has no labels

Code:
#compare_stocks_to_spy

#https://usethinkscript.com/threads/advance-decline-for-8-stocks.18018/
#Advance/Decline For 8 Stocks
#ah1144  2/20

#can this script
#https://usethinkscript.com/threads/weighted-advance-decline-for-thinkorswim.9487/page-5#post-137506
#be modified to show , mfst, aapl, nvda, amzn, meta, goog tsla, hyg ( instead of the sectors in the code )as a percentage of change from daily opening plotted against the spy and showing each stock with its lable like this above referenced code?



#https://usethinkscript.com/threads/weighted-advance-decline-for-thinkorswim.9487/page-5#post-137506
#khpro59  jan 30, 2024  #99
#This one seems to be a great match for ST's. Whether you find it useful or not is up to you, but I believe this is the accurate script (weightings need to be updated)

#Reverse Engineered Weighted A/D concept based off shadowtrader.net
###Be sure to check weightings periodically and update accordingly (https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data)
#shared to uTS 1/30/24 by khpro59

declare lower;

def bn = barnumber();
def na = double.nan;

input Open_Time = 930;


def FirstBar = if SecondsFromTime(Open_Time)[1] >= 0 and SecondsTillTime(Open_Time) >= 0 then 1 else 0;
AddVerticalLine(FirstBar, "-");


#  needs to be caps
input s1 = "MSFT";
input s2 = "AAPL";
input s3 = "NVDA";
input s4 = "AMZN";
input s5 = "META";
input s6 = "GOOG";
input s7 = "TSLA";
input s8 = "HYG";


# day open price
def s1_1 = if FirstBar then close else s1_1[1];
def s2_1 = if FirstBar then close else s2_1[1];
def s3_1 = if FirstBar then close else s3_1[1];
def s4_1 = if FirstBar then close else s4_1[1];
def s5_1 = if FirstBar then close else s5_1[1];
def s6_1 = if FirstBar then close else s6_1[1];
def s7_1 = if FirstBar then close else s7_1[1];
def s8_1 = if FirstBar then close else s8_1[1];


# % chg  since open
# s1_dayper = wt
def s1_dayper = (100*(close - s1_1)/s1_1);
def s2_dayper = (100*(close - s2_1)/s1_1);
def s3_dayper = (100*(close - s3_1)/s1_1);
def s4_dayper = (100*(close - s4_1)/s1_1);
def s5_dayper = (100*(close - s5_1)/s1_1);
def s6_dayper = (100*(close - s6_1)/s1_1);
def s7_dayper = (100*(close - s7_1)/s1_1);
def s8_dayper = (100*(close - s8_1)/s1_1);

def u = 1;
def s1_PR = if bn == 1 then u else (close(s1) - close(s1)[1]) / close(s1)[1] * s1_dayper / 100;
def s2_PR = if bn == 1 then u else (close(s2) - close(s2)[1]) / close(s2)[1] * s2_dayper / 100;
def s3_PR = if bn == 1 then u else (close(s3) - close(s3)[1]) / close(s3)[1] * s3_dayper / 100;
def s4_PR = if bn == 1 then u else (close(s4) - close(s4)[1]) / close(s4)[1] * s4_dayper / 100;
def s5_PR = if bn == 1 then u else (close(s5) - close(s5)[1]) / close(s5)[1] * s5_dayper / 100;
def s6_PR = if bn == 1 then u else (close(s6) - close(s6)[1]) / close(s6)[1] * s6_dayper / 100;
def s7_PR = if bn == 1 then u else (close(s7) - close(s7)[1]) / close(s7)[1] * s7_dayper / 100;
def s8_PR = if bn == 1 then u else (close(s8) - close(s8)[1]) / close(s8)[1] * s8_dayper / 100;


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


#input XLP_WT = 5.80;
#input XLU_WT = 2.50;
#input XLC_WT = 11.50;
#input XLF_WT = 11.20;
#input XLB_WT = 2.60;
#input XLI_WT = 8.20;
#input XLE_WT = 2.40;
#input XLRE_WT = 2.60;
#input XLV_WT = 13.40;
#input XLK_WT = 27.90;
#input XLY_WT = 11.90;

#def XLP_PRnow = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * XLP_WT / 100;
#def XLU_PRnow = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * XLU_WT / 100;
#def XLC_PRnow = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * XLC_WT / 100;
#def XLF_PRnow = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * XLF_WT / 100;
#def XLB_PRnow = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * XLB_WT / 100;
#def XLI_PRnow = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * XLI_WT / 100;
#def XLE_PRnow = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * XLE_WT / 100;
#def XLRE_PRnow = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * XLRE_WT / 100;
#def XLV_PRnow = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * XLV_WT / 100;
#def XLK_PRnow = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * XLK_WT / 100;
#def XLY_PRnow = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * XLY_WT / 100;

#def CAD = XLP_PRnow + XLU_PRnow + XLC_PRnow + XLF_PRnow + XLB_PRnow + XLI_PRnow + XLE_PRnow + XLRE_PRnow + XLV_PRnow + XLK_PRnow + XLY_PRnow;


def cad = s1_pr + s2_pr + s3_pr + s4_pr + s5_pr + s6_pr + s7_pr + s8_pr;

def Divider = 6.5 * 60 / GetAggregationPeriod() * 200 * 500;

def notFirstBar = if SecondsFromTime(Open_Time) >= 0 and SecondsFromTime(Open_Time)[1] >= 0 then 1 else 0;
#addverticalline(notfirstbar, "-");



def X = if GetAggregationPeriod() == AggregationPeriod.MIN then 70000
 else if GetAggregationPeriod() == AggregationPeriod.TWO_MIN then 60000
 else if GetAggregationPeriod() == AggregationPeriod.THREE_MIN then 55000
 else if GetAggregationPeriod() == AggregationPeriod.FOUR_MIN then 50000
 else if GetAggregationPeriod() == AggregationPeriod.FIVE_MIN then 45000
 else if GetAggregationPeriod() == AggregationPeriod.TEN_MIN then 37500
 else if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN then 35000
 else if GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN then 32500
 else if GetAggregationPeriod() == AggregationPeriod.HOUR then 27500
 else Double.NaN;


def CT = if  GetDay() != GetDay()[1] then 0 else if notFirstBar then CT[1] + CAD else 0;
plot Weighted_AD = if !IsNaN(CAD) then CT * X else Double.NaN;


plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
Weighted_AD.DefineColor(“Positive”, Color.MAGENTA);
Weighted_AD.DefineColor(“Negative”, Color.ORANGE);
Weighted_AD.AssignValueColor(if Weighted_AD >= Weighted_AD [1] then Weighted_AD.Color(“Positive”) else Weighted_AD.Color(“Negative”));


#def CAD2 = 11 * (XLP_PRnow / XLP_WT + XLU_PRnow / XLU_WT + XLC_PRnow / XLC_WT + XLF_PRnow / XLF_WT + XLB_PRnow / XLB_WT + XLI_PRnow / XLI_WT + XLE_PRnow / XLE_WT + XLRE_PRnow / XLRE_WT + XLV_PRnow / XLV_WT + XLK_PRnow / XLK_WT + XLY_PRnow / XLY_WT);

#   XLU_PRnow / wt   =   s1_pr/s1_dayper
def cad2 = 8 * (s1_pr/s1_dayper + s2_pr/s2_dayper + s3_pr/s3_dayper + s4_pr/s4_dayper + s5_pr/s5_dayper + s6_pr/s6_dayper + s7_pr/s7_dayper + s8_pr/s8_dayper );

def CT2 = if  GetDay() != GetDay()[1] then 0 else if notFirstBar then CT2[1] + CAD2 else 0;

plot Non_Weighted_AD = if !IsNaN(CAD2) then CT2 * X
 else Double.NaN;


addchartbubble(0, 0,
 s1_dayper + "\n" +
 ((close(s1) - close(s1)[1]) / close(s1)[1] ) + "\n" +
 s1_pr + "\n" +
 CAD + "\n" +
 CT + "\n" +
 X + "\n" +
 Weighted_AD  + "\n"
, color.yellow, yes);

#
 

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

i don't quite understand what you want.
this doesn't compare to SPY. want to verify the math before going too far.

elaborate on what you want.


i added your stocks (next time type them in capitals)
for each, calculate a % change since day open. use that % chg as the WT in formulas

it plots 2 lines, like the original.
like the original, it has no labels

Code:
#compare_stocks_to_spy

#https://usethinkscript.com/threads/advance-decline-for-8-stocks.18018/
#Advance/Decline For 8 Stocks
#ah1144  2/20

#can this script
#https://usethinkscript.com/threads/weighted-advance-decline-for-thinkorswim.9487/page-5#post-137506
#be modified to show , mfst, aapl, nvda, amzn, meta, goog tsla, hyg ( instead of the sectors in the code )as a percentage of change from daily opening plotted against the spy and showing each stock with its lable like this above referenced code?



#https://usethinkscript.com/threads/weighted-advance-decline-for-thinkorswim.9487/page-5#post-137506
#khpro59  jan 30, 2024  #99
#This one seems to be a great match for ST's. Whether you find it useful or not is up to you, but I believe this is the accurate script (weightings need to be updated)

#Reverse Engineered Weighted A/D concept based off shadowtrader.net
###Be sure to check weightings periodically and update accordingly (https://www.spglobal.com/spdji/en/indices/equity/sp-500/#data)
#shared to uTS 1/30/24 by khpro59

declare lower;

def bn = barnumber();
def na = double.nan;

input Open_Time = 930;


def FirstBar = if SecondsFromTime(Open_Time)[1] >= 0 and SecondsTillTime(Open_Time) >= 0 then 1 else 0;
AddVerticalLine(FirstBar, "-");


#  needs to be caps
input s1 = "MSFT";
input s2 = "AAPL";
input s3 = "NVDA";
input s4 = "AMZN";
input s5 = "META";
input s6 = "GOOG";
input s7 = "TSLA";
input s8 = "HYG";


# day open price
def s1_1 = if FirstBar then close else s1_1[1];
def s2_1 = if FirstBar then close else s2_1[1];
def s3_1 = if FirstBar then close else s3_1[1];
def s4_1 = if FirstBar then close else s4_1[1];
def s5_1 = if FirstBar then close else s5_1[1];
def s6_1 = if FirstBar then close else s6_1[1];
def s7_1 = if FirstBar then close else s7_1[1];
def s8_1 = if FirstBar then close else s8_1[1];


# % chg  since open
# s1_dayper = wt
def s1_dayper = (100*(close - s1_1)/s1_1);
def s2_dayper = (100*(close - s2_1)/s1_1);
def s3_dayper = (100*(close - s3_1)/s1_1);
def s4_dayper = (100*(close - s4_1)/s1_1);
def s5_dayper = (100*(close - s5_1)/s1_1);
def s6_dayper = (100*(close - s6_1)/s1_1);
def s7_dayper = (100*(close - s7_1)/s1_1);
def s8_dayper = (100*(close - s8_1)/s1_1);

def u = 1;
def s1_PR = if bn == 1 then u else (close(s1) - close(s1)[1]) / close(s1)[1] * s1_dayper / 100;
def s2_PR = if bn == 1 then u else (close(s2) - close(s2)[1]) / close(s2)[1] * s2_dayper / 100;
def s3_PR = if bn == 1 then u else (close(s3) - close(s3)[1]) / close(s3)[1] * s3_dayper / 100;
def s4_PR = if bn == 1 then u else (close(s4) - close(s4)[1]) / close(s4)[1] * s4_dayper / 100;
def s5_PR = if bn == 1 then u else (close(s5) - close(s5)[1]) / close(s5)[1] * s5_dayper / 100;
def s6_PR = if bn == 1 then u else (close(s6) - close(s6)[1]) / close(s6)[1] * s6_dayper / 100;
def s7_PR = if bn == 1 then u else (close(s7) - close(s7)[1]) / close(s7)[1] * s7_dayper / 100;
def s8_PR = if bn == 1 then u else (close(s8) - close(s8)[1]) / close(s8)[1] * s8_dayper / 100;


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


#input XLP_WT = 5.80;
#input XLU_WT = 2.50;
#input XLC_WT = 11.50;
#input XLF_WT = 11.20;
#input XLB_WT = 2.60;
#input XLI_WT = 8.20;
#input XLE_WT = 2.40;
#input XLRE_WT = 2.60;
#input XLV_WT = 13.40;
#input XLK_WT = 27.90;
#input XLY_WT = 11.90;

#def XLP_PRnow = (close("XLP") - close("XLP")[1]) / close("XLP")[1] * XLP_WT / 100;
#def XLU_PRnow = (close("XLU") - close("XLU")[1]) / close("XLU")[1] * XLU_WT / 100;
#def XLC_PRnow = (close("XLC") - close("XLC")[1]) / close("XLC")[1] * XLC_WT / 100;
#def XLF_PRnow = (close("XLF") - close("XLF")[1]) / close("XLF")[1] * XLF_WT / 100;
#def XLB_PRnow = (close("XLB") - close("XLB")[1]) / close("XLB")[1] * XLB_WT / 100;
#def XLI_PRnow = (close("XLI") - close("XLI")[1]) / close("XLI")[1] * XLI_WT / 100;
#def XLE_PRnow = (close("XLE") - close("XLE")[1]) / close("XLE")[1] * XLE_WT / 100;
#def XLRE_PRnow = (close("XLRE") - close("XLRE")[1]) / close("XLRE")[1] * XLRE_WT / 100;
#def XLV_PRnow = (close("XLV") - close("XLV")[1]) / close("XLV")[1] * XLV_WT / 100;
#def XLK_PRnow = (close("XLK") - close("XLK")[1]) / close("XLK")[1] * XLK_WT / 100;
#def XLY_PRnow = (close("XLY") - close("XLY")[1]) / close("XLY")[1] * XLY_WT / 100;

#def CAD = XLP_PRnow + XLU_PRnow + XLC_PRnow + XLF_PRnow + XLB_PRnow + XLI_PRnow + XLE_PRnow + XLRE_PRnow + XLV_PRnow + XLK_PRnow + XLY_PRnow;


def cad = s1_pr + s2_pr + s3_pr + s4_pr + s5_pr + s6_pr + s7_pr + s8_pr;

def Divider = 6.5 * 60 / GetAggregationPeriod() * 200 * 500;

def notFirstBar = if SecondsFromTime(Open_Time) >= 0 and SecondsFromTime(Open_Time)[1] >= 0 then 1 else 0;
#addverticalline(notfirstbar, "-");



def X = if GetAggregationPeriod() == AggregationPeriod.MIN then 70000
 else if GetAggregationPeriod() == AggregationPeriod.TWO_MIN then 60000
 else if GetAggregationPeriod() == AggregationPeriod.THREE_MIN then 55000
 else if GetAggregationPeriod() == AggregationPeriod.FOUR_MIN then 50000
 else if GetAggregationPeriod() == AggregationPeriod.FIVE_MIN then 45000
 else if GetAggregationPeriod() == AggregationPeriod.TEN_MIN then 37500
 else if GetAggregationPeriod() == AggregationPeriod.FIFTEEN_MIN then 35000
 else if GetAggregationPeriod() == AggregationPeriod.THIRTY_MIN then 32500
 else if GetAggregationPeriod() == AggregationPeriod.HOUR then 27500
 else Double.NaN;


def CT = if  GetDay() != GetDay()[1] then 0 else if notFirstBar then CT[1] + CAD else 0;
plot Weighted_AD = if !IsNaN(CAD) then CT * X else Double.NaN;


plot zero = 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
Weighted_AD.DefineColor(“Positive”, Color.MAGENTA);
Weighted_AD.DefineColor(“Negative”, Color.ORANGE);
Weighted_AD.AssignValueColor(if Weighted_AD >= Weighted_AD [1] then Weighted_AD.Color(“Positive”) else Weighted_AD.Color(“Negative”));


#def CAD2 = 11 * (XLP_PRnow / XLP_WT + XLU_PRnow / XLU_WT + XLC_PRnow / XLC_WT + XLF_PRnow / XLF_WT + XLB_PRnow / XLB_WT + XLI_PRnow / XLI_WT + XLE_PRnow / XLE_WT + XLRE_PRnow / XLRE_WT + XLV_PRnow / XLV_WT + XLK_PRnow / XLK_WT + XLY_PRnow / XLY_WT);

#   XLU_PRnow / wt   =   s1_pr/s1_dayper
def cad2 = 8 * (s1_pr/s1_dayper + s2_pr/s2_dayper + s3_pr/s3_dayper + s4_pr/s4_dayper + s5_pr/s5_dayper + s6_pr/s6_dayper + s7_pr/s7_dayper + s8_pr/s8_dayper );

def CT2 = if  GetDay() != GetDay()[1] then 0 else if notFirstBar then CT2[1] + CAD2 else 0;

plot Non_Weighted_AD = if !IsNaN(CAD2) then CT2 * X
 else Double.NaN;


addchartbubble(0, 0,
 s1_dayper + "\n" +
 ((close(s1) - close(s1)[1]) / close(s1)[1] ) + "\n" +
 s1_pr + "\n" +
 CAD + "\n" +
 CT + "\n" +
 X + "\n" +
 Weighted_AD  + "\n"
, color.yellow, yes);

#
Thanks for the reply
my thought was to have a quick visual glance at these 8 stocks to see if they were up or down from the opening each new day, ( not previous days close ) and reference them to my spx trading to help determine overall trend whether a short or long and strength by seeing percentage up or down from opening of that day.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
396 Online
Create Post

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