Time based Scan


Category:
0
0

Been struggling with time based code and would really appreciate some guidance.

I was wondering how I can scan for stocks where the high of day is made within the first hour in Thinkscript.

I looked at start time, end time, but that didnt seem to work for this particular application.

Thanks!

 

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on March 16, 2021 6:35 pm
144 views
0
Private answer

The most simple solution is to completely forget about trying to use time at all. For a Study Filter set to 1 hour time frame, the first bar of the day is the first hour high. Done. If you need to use a lower time frame than 1 hour the solution gets a bit more complicated but it is certainly possible. If that's what you are shooting for I suggest you take some time to search the forum for the term "opening range". What you have describe is the exact opposite of an opening range breakout.

If you are using a time frame lower than 1 hour the solution would be more complex than what I am able to provide free of charge in the Q&A Forum.

Edit: Here is the code to run a scan using only the 1 hour time frame (regular session ONLY). The code checks the first hourly bar and captures the high. Using recursion to carry that value forward. Another recursive variable tracks the high of day excluding the first hourly bar. Then it compares the first hour high to the high of day and looks for bars where close is less than open.

def newDay = GetDay() <> GetDay()[1];
rec firstHourHigh = if newDay then high else firstHourHigh[1];
rec highOfDay = if newDay[1] then high else if high > highOfDay[1] then high else highOfDay[1];
def conditionOne = highOfDay < firstHourHigh;
def conditionTwo = close < open;
plot scan = conditionOne and conditionTwo;

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on March 16, 2021 7:40 pm
0
Thanks Pete - Ok so took a stab at this using code I found on your site. What I want to do is say FIRST HOUR HIGH = HIGH OF DAY and OPEN>CLOSE. It runs but doesn't seem to work. Thanks! def stageOne = RegularTradingEnd(GetYYYYMMDD()); def firsthourStart = stageOne[1] stageOne; def stageTwo = SecondsTillTime(730); def premarketSession = stageTwo > 0; def highofday = highest(close); rec firsthourHigh = if firsthourStart and premarketSession then high else if high > firsthourHigh[1] and premarketSession then high else firsthourHigh[1]; plot true = (high is equal to highofday and open>close);
( at March 17, 2021 4:21 pm)
0
No, that will not do at all. And you cannot do this in the most simple matter while also including extended hours session. I have updated my answer to include the simplest solution available. Be sure to check my Edit for a full description of how to apply this and how the code functions.
( at March 17, 2021 6:49 pm)