Code for Price-to-Sales Ratio Scan


Category:
0
0

Do you have code that would allow me to scan for Price-to-Sales Ratio (P/S) where I could enter a min and a max and have the results filtered to display that range?

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on September 27, 2022 8:51 am
520 views
1
Private answer

I contacted Thinkscript support about this issue and have received some additional details which I will share:

Response from Aaron Morgan with Thinkscript support:

The SalesPerShare in TOS is generated once per year, and you have to recursively find it starting from today's date. The sample code I gave you has an example of how that would need to function to obtain a value. It also has to be on a security where that data is published, as it will not be available for all securities. It also needs to be on a time frame where the data will populate. At the minimum, you would need a 1D 1Y chart.

The following code was provided by Thinkscript support:

declare lower;
def sps = if isnan(salesPerShare()) then sps[1] else salesPerShare();
plot ptsr = if (close / sps) > 0 then close / sps else 0;

So this will only work as a chart study. It will NOT work as a custom quote field (custom watchlist column) which was the original request. When I asked for confirmation about this limitation I received the following response from Aaron Morgan with Thinkscript support:

Bad news, I'm sorry to say the fundamental functions do not work in custom quote fields. There isn't a work around for it, either as it is all of the fundamental functions.

So there we have it from the official source. I am including a screenshot below which shows how this solution appears on a chart.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 4, 2022 2:36 pm
0
Private answer

I contacted the author of this post to get further clarification. The following additional details were provided by Aaron B:

Price-to-sales and sales per share are related but they are two separate things.

The price-to-sales ratio is calculated by taking a company's market capitalization (the number of outstanding shares multiplied by the stock price) and dividing it by the company's total sales or revenue over the past 12 months.

The sales per share is calculated by dividing the company's total sales or revenue over the past 12 months by the outstanding shares.

So to determine the price-to-sales, you can divide the current stock price by the sales per share.

Thinkorswim provides a limited number of functions for what they refer to as "Stock Fundamentals". Details here:

https://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Stock-Fundamentals

From that list we have a function named "SalesPerShare()". Based on the details provided by Aaron B, we can compute the "Price to Sales Ratios" but dividing the current stock price by the "SalesPerShare()". However this is where we run into a block wall.

The "SalesPerShare()" function does not work for scans, or custom watchlist columns. In fact it does not appear to work anywhere on the platform at all. Not even in a chart study. It requires the input of a ticker symbol. And for those two tools it would not be possible to input a ticker symbol because the function needs to be able to compute the data for several ticker symbols. And even when this function is applied in a chart study and a ticker symbol is manually entered into the function, it still fails.

I have tried every trick I can think of to get this to work and it appears to be broken, completely.

I think this is one of those issue which needs to be sent to TD Ameritrade support as a bug report. I have come across this same problem with other functions in the "Stock Fundamentals" group. Perhaps the developers forgot to wire things up. Or they may need to simply remove these from the language reference altogether.

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 27, 2022 4:16 pm