Basic Stock Fundamental Script

ZKL

New member
Complete newbie to thinkscript. Can anyone tell me how I can get the following script to work. Struggling with the SalesPerShare stock fundamental function (no such variable error). I want to add this script to a new marketwatch column. Basically all I want to do is divide the SalesPerShare value by the last share price. Thanks!

declare lower;
def rev_per_share = SalesPerShare / close;
AddLabel (yes, "" + Round(rev_per_share,3), if rev_per_share > 0 then Color.Green else Color.Red);
 

halcyonguy

Active member
VIP
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();
 

ZKL

New member
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();

Hi @halcyonguy , thanks for your reply and help, much appreciated.

I am trying to add scripts to personalize the marketwatch tab. I've left the "" in the addlabel instruction so that I only see the value in the marketwatch column and not the label as well which takes up too much space.

Also, by adding the script, I can reduce the decimals and color code to make it easier to visualise.

Unfortunately, adding the () at the end of SalesPerShare still gives me an error message (invalid symbol in Stock Fundamentals function):

declare lower;
def rev_per_share = SalesPerShare() / close;
AddLabel (yes, "" + Round(rev_per_share,3), if rev_per_share > 0 then Color.Green else Color.Red);


I can see the SalesPerShare values for each ticker symbol so I know the function is pulling information.

Here is a screenshot of what I am trying to achieve (hope this works):
nqEM91y.png
 

Jeff1228

New member
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();
Thanks. So we should set the fiscal period to quarter, correct?
 

ZKL

New member
hello. there are a couple things to change in your code.
...not sure what you want to see by using this , in addlabel
, "" +
but it won't display anything. maybe this is what you want?
, "rev/share " +

...SalesPerShare() needs the () at the end.

...SalesPerShare() data does not exist on every candle. it shows up on 1 candle, once a year. so you need a way to keep the value after finding it.

take a look at this study. it displays several fundamental parameters of a stock.
https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/

this formula reads SalesPerShare() data.
if it finds data that isn't an error, it puts the value into x. if SalesPerShare() is an error, then x is equal the previous candle value of x. this is how to pass a value from one candle to the next, by using an offset of [1], to look at the previous candle.

def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare();

Hi again @halcyonguy. I keep trying but I can't seem to make the code work. I have added your formula and checked over the study from @MerryDay (https://usethinkscript.com/threads/fundamentals-labels-for-thinkorswim.5308/).

I get the error message "Invalid symbol in Stock Fundamentals function". I am adding the script in the MarketWatch custom formula.

declare lower;
declare hide_on_intraday;
input show_labels = yes ;
input show_summaries = no ;
def x = if IsNaN(SalesPerShare()) then x[1] else SalesPerShare() ;
def rev_per_share = x / close;
AddLabel(show_labels and rev_per_share, "Revenue Per Share = " + Round(rev_per_share, 2));


Hoping you can help me make this work. Thanks again!
 

ZKL

New member
Managed to make the code work without the "Invalid symbol in Stock Fundamentals function" error:

def sales_per_share = compoundValue (1, if IsNaN(SalesPerShare()) then sales_per_share [1] else SalesPerShare(), 1);
def rev_per_share = sales_per_share / close;
AddLabel (yes, "" + Round(rev_per_share, 2));
 

Similar threads

Top