Scan for the mean TOS


Category:
0
0

Let’s say I pull up a daily chart with 1 year of data. The high and low are listed. Let’s say the low of this time frame is $10 and the high is $70. The mean is obviously $40. Is there a way we can scan for stock that are currently trading at or near the mean? Something we can adjust. Say it’s trading with +/- $5 of the mean. Would be nice to have the ability to scan on any time frame with the daily as the default.

Marked as spam
Posted by (Questions: 21, Answers: 47)
Asked on January 19, 2018 6:43 pm
247 views
0
Private answer

Before we get into the solution I need to explain the data limits imposed on the scanner in Thinkorswim. One year of historical data is only available for the Hourly time frame and above. So to scan for the high and low with last year, you must select a time frame of 1 hour or higher.

Details here: http://tlc.thinkorswim.com/center/howToTos/thinkManual/Scan/Stock-Hacker/studyfilters.html

Within those limits, results are exactly the same regardless what time frame you chose so…

If you are looking to find price relative to the mean over a 1 year period, it does not matter what time frame you use. So use the daily for the sake of simplicity. Yes?

Since we have more than one year of historical data available for daily time frame and above, we’ll need to apply a start date to the code. This will be in the form of a user adjustable input that will need to be manually updated to ensure the scan is reading from exactly one entire year.

The surprising thing for me is this code was designed on the daily time frame but works on the hourly time frame as well. When I got started on this I assumed I would have to provide a different section of code for lower time frames.

Here you go. Screenshot below shows the output.

input referenceDate = 20170120;
input range = 5.0;
def startDate = DaysFromDate(referenceDate);
rec highestHigh = if startDate < 0 then high else if high > highestHigh[1] then high else highestHigh[1];
rec lowestLow = if startDate < 0 then low else if low < lowestLow[1] and lowestLow[1] > 0 then low else lowestLow[1];
def mean = (highestHigh + lowestLow) / 2;
plot scan = close < mean + range and close > mean - range;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on January 20, 2018 10:58 am
0
Private answer

If you are looking to find price relative to the mean over a 1 year period, it does not matter what time frame you use. So use the daily for the sake of simplicity. Yes? 

For the most part, yes this will be used on a daily time frame. I do appreciate this and love the ability to customize the price as well as the reference date.

 

I do have a question. I do not get the lines on the chart as you did. The scan works well and within the parameters I set but is there something I’m missing or overlooking or is this just something additional on your chart? Thanks again.

Marked as spam
Posted by (Questions: 21, Answers: 47)
Answered on January 21, 2018 11:39 pm
0

The chart I included was just part of how I develop stuff. I make sure I can visualize all the elements so I know the scan is doing what I want. Your request was for a scan. The chart study version does not work as a scan. So it would have caused confusion. If you want to turn that scan back into the chart study version there are two steps. Change the “plot scan” to “def scan”. Then add the following plot line immediately below that:

plot test1 = highestHigh;
plot test2 = lowestLow;
plot test3 = mean;

( at January 22, 2018 8:32 am)
0

thank you

( at January 23, 2018 10:48 pm)