Scan for stocks hitting 52 week high with a certain time frame


Category:
0
0

Hi Pete,

 

Wondering if possible in TOS to scan fro stocks that made 52 week high within this time frame

7/10 to 7/30

Marked as spam
Posted by (Questions: 13, Answers: 13)
Asked on September 27, 2017 6:38 am
3095 views
0

You may be able to use the function named GetYYYYMMDD() to get today’s date. You can read more here: http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Date—Time/GetYYYYMMDD.html

If you can’t get it working then I suggest you post this as a new topic to avoid confusing future visitors to this post. Seems to me that my response to the original request covers what you are asking. So if you post this in a new question be sure to explain things in more detail.

( at September 27, 2017 9:02 pm)
0
Private answer

We can do this in just a few lines of code. We are making use of two built in functions:

DaysTillDate() http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Date—Time/DaysTillDate.html

and

DayFromDate() http://toslc.thinkorswim.com/center/reference/thinkScript/Functions/Date—Time/DaysFromDate.html

Here is the code. The screenshot that follows shows scan results and sample chart.

input dateBegin = 20170710;
input dateEnd = 20170730;
def daysFromBegin = DaysFromDate(dateBegin);
def daysUntilEnd = DaysTillDate(dateEnd);
def highestInYear = Highest(high, 252);
def yearlyHighWithinRange = daysFromBegin >= 0 and daysUntilEnd >= 0 and high > highestInYear[1];
rec holdState = CompoundValue(1, if yearlyHighWithinRange then 1 else holdState[1], 0);
plot scan = holdState;

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on September 27, 2017 2:29 pm