Add a column to a Watchlist that shows the PEG Ratio

Stockleed

New member
Is there a way to add a column to a watchlist or write a code in ThinkorSwim, that shows the PEG Radio in the Watchlist column

The PEG Ratio formula = PEG = Share Price / Earnings per share / Earnings per Share growth rate

Unfortunately, I am not smart enough to add this formula to TOS. Any help would be greatly appreciated


peg-ratio-formula.png


EXAMPLE
Screenshot-2022-07-27-084723.png

Any help would be greatly appreciated
 
Solution
Is there a way to add a column to a watchlist or write a code in ThinkorSwim, that shows the PEG Radio in the Watchlist column

The PEG Ratio formula = PEG = Share Price / Earnings per share / Earnings per Share growth rate

Unfortunately, I am not smart enough to add this formula to TOS. Any help would be greatly appreciated


PEG ratio

i think this is right. someone can look it over.
i used the formulas from investopedia (link below)

i don't think fundamental functions work in a column. i tried to copy this to a column study and it gave an error.
i suspect it was this line.
def eps_yr = round(EarningsPerShareTTM (fiscalPeriod = FiscalPeriod.YEAR), 2);
i tried removing the parameter and setting the time to year, but...
Is there a way to add a column to a watchlist or write a code in ThinkorSwim, that shows the PEG Radio in the Watchlist column

The PEG Ratio formula = PEG = Share Price / Earnings per share / Earnings per Share growth rate

Unfortunately, I am not smart enough to add this formula to TOS. Any help would be greatly appreciated


PEG ratio

i think this is right. someone can look it over.
i used the formulas from investopedia (link below)

i don't think fundamental functions work in a column. i tried to copy this to a column study and it gave an error.
i suspect it was this line.
def eps_yr = round(EarningsPerShareTTM (fiscalPeriod = FiscalPeriod.YEAR), 2);
i tried removing the parameter and setting the time to year, but it didn't work.


this is a lower chart study, with labels

Ruby:
# peg_ratio_lower_0

# https://usethinkscript.com/threads/add-a-column-to-a-watchlist-that-shows-the-peg-ratio.12043/
#Add a column to a Watchlist that shows the PEG Ratio

declare lower;

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

def isyear = if GetLastYear() == GetYear() then 1 else 0;
def isprevyear = if GetLastYear() == GetYear()+1 then 1 else 0;

def eps_yr = round(EarningsPerShareTTM (fiscalPeriod = FiscalPeriod.YEAR), 2);
def eps_prev_yr = if bn == 1 then 0 else if  isprevyear then eps_yr else eps_prev_yr[1];


# formulas from investopedia , see below

# PE_ratio = share price / EPS
# Earnings growth rate = 100 * (( EPS this year / EPS last year ) - 1)
# PEG ratio = PE ratio / Earnings growth rate

def share = close;
def pe_ratio = (share / eps_yr);
def earnings_growth_rate = 100 * ((eps_yr / eps_prev_yr) - 1);
def peg_ratio = (pe_ratio / earnings_growth_rate);


addlabel(1, "EPS this year " + eps_yr, color.yellow);
addlabel(1, "EPS previous year " + eps_prev_yr, color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "PE ratio " + pe_ratio, color.yellow);
addlabel(1, "Earnings growth rate " + earnings_growth_rate, color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "PEG ratio " + peg_ratio, color.yellow);



#--------------------------------
# test stuff

input test1_lines = no;
plot zeps = eps_yr;
zeps.setdefaultcolor(color.yellow);
zeps.setHiding(!test1_lines);

plot zpeps = eps_prev_yr;
zpeps.setdefaultcolor(color.magenta);
zpeps.setHiding(!test1_lines);


input test2_bubbles = no;
#addchartbubble(test2_bubbles, 0, isyear, (if isyear then color.yellow else color.gray), yes);
addchartbubble(test2_bubbles, 0, isprevyear, (if isprevyear then color.yellow else color.gray), no);



#https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Stock-Fundamentals/EarningsPerShareTTM
#EarningsPerShareTTM

#EarningsPerShareTTM ( Symbol symbol, int fiscalPeriod);    

#Default values:

#symbol: current symbol
#fiscalPeriod: FiscalPeriod.YEAR
#Description
#The EarningsPerShareTTM function returns the value of trailing 12-month earnings per share for the specified symbol. The trailing 12-month earnings per share is calculated as the ratio of company's profit to the number of its outstanding shares of common stock over the last 12 months. By default, the value is returned for the currently selected symbol and based on the annual reporting data. To specify a different symbol for this function, modify the value of the symbol input parameter. To use quarterly data instead of annual, assign the fiscalPeriod.QUARTER constant to the fiscalPeriod input parameter.




#https://www.investopedia.com/terms/p/pegratio.asp
#According to well-known investor Peter Lynch, a company's P/E and expected growth should be equal, which denotes a fairly valued company and supports a PEG ratio of 1.0. When a company's PEG exceeds 1.0, it's considered overvalued while a stock with a PEG of less than 1.0 is considered undervalued.


#Example of How to Use the PEG Ratio
#The PEG ratio provides useful information to compare companies and see which stock might be the better choice for an investor's needs, as follows.

#Assume the following data for two hypothetical companies, Company A and Company B:

#Company A:
#Price per share = $46
#EPS this year = $2.09
#EPS last year = $1.74

#Company B
#Price per share = $80
#EPS this year = $2.67
#EPS last year = $1.78

#Given this information, the following data can be calculated for each company.

#Company A
#P/E ratio = $46 / $2.09 = 22
#Earnings growth rate = ($2.09 / $1.74) - 1 = 20%
#PEG ratio = 22 / 20 = 1.1

#Company B
#P/E ratio = $80 / $2.67 = 30
#Earnings growth rate = ($2.67 / $1.78) - 1 = 50%
#PEG ratio = 30 / 50 = 0.6

#Many investors may look at Company A and find it more attractive since it has a lower P/E ratio between the two companies. But compared to Company B, it doesn't have a high enough growth rate to justify its P/E. Company B is trading at a discount to its growth rate and investors purchasing it are paying less per unit of earnings growth.

#

5 labels
TVpEgB5.jpg



https://www.investopedia.com/terms/p/pegratio.asp

https://tlc.thinkorswim.com/center/...ctions/Stock-Fundamentals/EarningsPerShareTTM
 
Solution

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

Thank you so much halcyonguy! Really appreciate your help. This website/Forum needs more members like YOU
PEG ratio

i think this is right. someone can look it over.
i used the formulas from investopedia (link below)

i don't think fundamental functions work in a column. i tried to copy this to a column study and it gave an error.
i suspect it was this line.
def eps_yr = round(EarningsPerShareTTM (fiscalPeriod = FiscalPeriod.YEAR), 2);
i tried removing the parameter and setting the time to year, but it didn't work.


this is a lower chart study, with labels

Ruby:
# peg_ratio_lower_0

# https://usethinkscript.com/threads/add-a-column-to-a-watchlist-that-shows-the-peg-ratio.12043/
#Add a column to a Watchlist that shows the PEG Ratio

declare lower;

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

def isyear = if GetLastYear() == GetYear() then 1 else 0;
def isprevyear = if GetLastYear() == GetYear()+1 then 1 else 0;

def eps_yr = round(EarningsPerShareTTM (fiscalPeriod = FiscalPeriod.YEAR), 2);
def eps_prev_yr = if bn == 1 then 0 else if  isprevyear then eps_yr else eps_prev_yr[1];


# formulas from investopedia , see below

# PE_ratio = share price / EPS
# Earnings growth rate = 100 * (( EPS this year / EPS last year ) - 1)
# PEG ratio = PE ratio / Earnings growth rate

def share = close;
def pe_ratio = (share / eps_yr);
def earnings_growth_rate = 100 * ((eps_yr / eps_prev_yr) - 1);
def peg_ratio = (pe_ratio / earnings_growth_rate);


addlabel(1, "EPS this year " + eps_yr, color.yellow);
addlabel(1, "EPS previous year " + eps_prev_yr, color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "PE ratio " + pe_ratio, color.yellow);
addlabel(1, "Earnings growth rate " + earnings_growth_rate, color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "PEG ratio " + peg_ratio, color.yellow);



#--------------------------------
# test stuff

input test1_lines = no;
plot zeps = eps_yr;
zeps.setdefaultcolor(color.yellow);
zeps.setHiding(!test1_lines);

plot zpeps = eps_prev_yr;
zpeps.setdefaultcolor(color.magenta);
zpeps.setHiding(!test1_lines);


input test2_bubbles = no;
#addchartbubble(test2_bubbles, 0, isyear, (if isyear then color.yellow else color.gray), yes);
addchartbubble(test2_bubbles, 0, isprevyear, (if isprevyear then color.yellow else color.gray), no);



#https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Stock-Fundamentals/EarningsPerShareTTM
#EarningsPerShareTTM

#EarningsPerShareTTM ( Symbol symbol, int fiscalPeriod);   

#Default values:

#symbol: current symbol
#fiscalPeriod: FiscalPeriod.YEAR
#Description
#The EarningsPerShareTTM function returns the value of trailing 12-month earnings per share for the specified symbol. The trailing 12-month earnings per share is calculated as the ratio of company's profit to the number of its outstanding shares of common stock over the last 12 months. By default, the value is returned for the currently selected symbol and based on the annual reporting data. To specify a different symbol for this function, modify the value of the symbol input parameter. To use quarterly data instead of annual, assign the fiscalPeriod.QUARTER constant to the fiscalPeriod input parameter.




#https://www.investopedia.com/terms/p/pegratio.asp
#According to well-known investor Peter Lynch, a company's P/E and expected growth should be equal, which denotes a fairly valued company and supports a PEG ratio of 1.0. When a company's PEG exceeds 1.0, it's considered overvalued while a stock with a PEG of less than 1.0 is considered undervalued.


#Example of How to Use the PEG Ratio
#The PEG ratio provides useful information to compare companies and see which stock might be the better choice for an investor's needs, as follows.

#Assume the following data for two hypothetical companies, Company A and Company B:

#Company A:
#Price per share = $46
#EPS this year = $2.09
#EPS last year = $1.74

#Company B
#Price per share = $80
#EPS this year = $2.67
#EPS last year = $1.78

#Given this information, the following data can be calculated for each company.

#Company A
#P/E ratio = $46 / $2.09 = 22
#Earnings growth rate = ($2.09 / $1.74) - 1 = 20%
#PEG ratio = 22 / 20 = 1.1

#Company B
#P/E ratio = $80 / $2.67 = 30
#Earnings growth rate = ($2.67 / $1.78) - 1 = 50%
#PEG ratio = 30 / 50 = 0.6

#Many investors may look at Company A and find it more attractive since it has a lower P/E ratio between the two companies. But compared to Company B, it doesn't have a high enough growth rate to justify its P/E. Company B is trading at a discount to its growth rate and investors purchasing it are paying less per unit of earnings growth.

#

5 labels
TVpEgB5.jpg



https://www.investopedia.com/terms/p/pegratio.asp

https://tlc.thinkorswim.com/center/...ctions/Stock-Fundamentals/EarningsPerShareTTM


@halcyonguy One more quick question, what would be the code or formula to display the PEG RATIO on a watchlist column? Would you use the Custom Quote Formula?
I can't figure out the correct code to display the PEG ratio in the column
Screenshot-2022-08-04-153932.png


Any help would be greatly appreciated
 
PEG ratio

i think this is right. someone can look it over.
i used the formulas from investopedia (link below)

i don't think fundamental functions work in a column. i tried to copy this to a column study and it gave an error.
i suspect it was this line.
def eps_yr = round(EarningsPerShareTTM (fiscalPeriod = FiscalPeriod.YEAR), 2);
i tried removing the parameter and setting the time to year, but it didn't work.


this is a lower chart study, with labels

Ruby:
# peg_ratio_lower_0

# https://usethinkscript.com/threads/add-a-column-to-a-watchlist-that-shows-the-peg-ratio.12043/
#Add a column to a Watchlist that shows the PEG Ratio

declare lower;

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

def isyear = if GetLastYear() == GetYear() then 1 else 0;
def isprevyear = if GetLastYear() == GetYear()+1 then 1 else 0;

def eps_yr = round(EarningsPerShareTTM (fiscalPeriod = FiscalPeriod.YEAR), 2);
def eps_prev_yr = if bn == 1 then 0 else if  isprevyear then eps_yr else eps_prev_yr[1];


# formulas from investopedia , see below

# PE_ratio = share price / EPS
# Earnings growth rate = 100 * (( EPS this year / EPS last year ) - 1)
# PEG ratio = PE ratio / Earnings growth rate

def share = close;
def pe_ratio = (share / eps_yr);
def earnings_growth_rate = 100 * ((eps_yr / eps_prev_yr) - 1);
def peg_ratio = (pe_ratio / earnings_growth_rate);


addlabel(1, "EPS this year " + eps_yr, color.yellow);
addlabel(1, "EPS previous year " + eps_prev_yr, color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "PE ratio " + pe_ratio, color.yellow);
addlabel(1, "Earnings growth rate " + earnings_growth_rate, color.yellow);
addlabel(1, " ", color.black);
addlabel(1, "PEG ratio " + peg_ratio, color.yellow);



#--------------------------------
# test stuff

input test1_lines = no;
plot zeps = eps_yr;
zeps.setdefaultcolor(color.yellow);
zeps.setHiding(!test1_lines);

plot zpeps = eps_prev_yr;
zpeps.setdefaultcolor(color.magenta);
zpeps.setHiding(!test1_lines);


input test2_bubbles = no;
#addchartbubble(test2_bubbles, 0, isyear, (if isyear then color.yellow else color.gray), yes);
addchartbubble(test2_bubbles, 0, isprevyear, (if isprevyear then color.yellow else color.gray), no);



#https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Stock-Fundamentals/EarningsPerShareTTM
#EarningsPerShareTTM

#EarningsPerShareTTM ( Symbol symbol, int fiscalPeriod);   

#Default values:

#symbol: current symbol
#fiscalPeriod: FiscalPeriod.YEAR
#Description
#The EarningsPerShareTTM function returns the value of trailing 12-month earnings per share for the specified symbol. The trailing 12-month earnings per share is calculated as the ratio of company's profit to the number of its outstanding shares of common stock over the last 12 months. By default, the value is returned for the currently selected symbol and based on the annual reporting data. To specify a different symbol for this function, modify the value of the symbol input parameter. To use quarterly data instead of annual, assign the fiscalPeriod.QUARTER constant to the fiscalPeriod input parameter.




#https://www.investopedia.com/terms/p/pegratio.asp
#According to well-known investor Peter Lynch, a company's P/E and expected growth should be equal, which denotes a fairly valued company and supports a PEG ratio of 1.0. When a company's PEG exceeds 1.0, it's considered overvalued while a stock with a PEG of less than 1.0 is considered undervalued.


#Example of How to Use the PEG Ratio
#The PEG ratio provides useful information to compare companies and see which stock might be the better choice for an investor's needs, as follows.

#Assume the following data for two hypothetical companies, Company A and Company B:

#Company A:
#Price per share = $46
#EPS this year = $2.09
#EPS last year = $1.74

#Company B
#Price per share = $80
#EPS this year = $2.67
#EPS last year = $1.78

#Given this information, the following data can be calculated for each company.

#Company A
#P/E ratio = $46 / $2.09 = 22
#Earnings growth rate = ($2.09 / $1.74) - 1 = 20%
#PEG ratio = 22 / 20 = 1.1

#Company B
#P/E ratio = $80 / $2.67 = 30
#Earnings growth rate = ($2.67 / $1.78) - 1 = 50%
#PEG ratio = 30 / 50 = 0.6

#Many investors may look at Company A and find it more attractive since it has a lower P/E ratio between the two companies. But compared to Company B, it doesn't have a high enough growth rate to justify its P/E. Company B is trading at a discount to its growth rate and investors purchasing it are paying less per unit of earnings growth.

#

5 labels
View attachment 15297


https://www.investopedia.com/terms/p/pegratio.asp

https://tlc.thinkorswim.com/center/...ctions/Stock-Fundamentals/EarningsPerShareTTM
Thank you for this!
I haven't tried it yet, but should the line (
def isprevyear = if GetLastYear() == GetYear()+1 then 1 else 0;) be
(def isprevyear = if GetLastYear() == GetYear()-1 then 1 else 0;)
instead?
Thanks again.
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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