DonDelMuerte
New member
@RobertPayne I appreciate your help with thinkscript on this thread! I have a question regarding building a robust pre-market scanner. Here is the premise of what I'm trying to achieve:
1. Determining Current Time
Right now I have several ways of doing this.
These methods are great, but they only work on aggregation periods less than or equal to 1 day - as per link. I have to use a recursive variable to store the previous day's close because ToS will not let me reference
2. Storing Previous day Close
Again, not sure if there is a cleaner way to do this.
3. Determining the Gap
This is where the real problem arises for me - and it comes down to the difference between scripts for "custom quotes" and scripts for the scanner. The difference being that for the custom quotes I can specify an alternate aggregation period for the gap calculation as such:
*** This only works in the custom quotes script where I'm allowed a secondary aggregation period. If I use the same code in the scanner, the error is thrown:
Tl;DR
For the study scanner I must use the daily timeframe (or so I believe) for which I do not know how to determine current time vs open/pre market hours or even current premarket prices. Using a lower timeframe (1M for instance) allows me to determine the current time/market hours but forces me to use a secondary aggregation period - which is not allowed in the study scanner (or so I believe).
** Another Issue: I have no way of verifying my results unless I'm in the premarket. So I can only code and do trial and error for a limited time every day. Weird to me that we can't use these types of scanners in the OnDemand mode - makes the trial and error process a bit tougher. Is there a way to circumvent this? I'm relatively new to ToS!
- Returning premarket gap ups during the premarket hours
- Returning
close[1]
toopen
gaps during all other hours - Write a script for the "quotes" column that displays this gap as well
1. Determining Current Time
Right now I have several ways of doing this.
Code:
def isopen=if secondsFromTime(0930)>=0 and econdstillTime(1600)>=0 then 1 else 0;
def ispre=if secondsFromTime(0400)>=0 and secondstillTime(0930)>0 then 1 else 0;
Code:
def trading_duration = 6.5*60*60;
def seconds_market = secondsFromTime(0930);
def pre_duration = 5.5*60*60;
def seconds_pre = secondsFromTime(0400);
def isopen=seconds_market>=0 and seconds_market <= trading_duration;
def ispre=seconds_pre>=0 and seconds_pre <= pre_duration;
These methods are great, but they only work on aggregation periods less than or equal to 1 day - as per link. I have to use a recursive variable to store the previous day's close because ToS will not let me reference
close(period=AggregationPeriod.DAY)[1]
while using an overall period of less than 1 D in the stock hacker study scan setup. I'd really like to find a way to check current time vs open/pre market hours while using the daily timeframe because it would make the rest of the code much cleaner.2. Storing Previous day Close
Code:
input marketClose = 1600;
def closeCounter = SecondsTillTime(marketClose);
def regSessEnd = closeCounter[-1] == 0;
rec priorDayClose = if regSessEnd then close else priorDayClose[1];
3. Determining the Gap
This is where the real problem arises for me - and it comes down to the difference between scripts for "custom quotes" and scripts for the scanner. The difference being that for the custom quotes I can specify an alternate aggregation period for the gap calculation as such:
Code:
def o = if isopen then open(period=AggregationPeriod.DAY) else if ispre then close else open(period=AggregationPeriod.Day);
def c = if isopen then close(period=AggregationPeriod.DAY)[1] else if ispre then priorDayClose else close(period=AggregationPeriod.DAY)[1];
plot x = 100*(l-c)/c;
Secondary period not allowed: Day.
Tl;DR
For the study scanner I must use the daily timeframe (or so I believe) for which I do not know how to determine current time vs open/pre market hours or even current premarket prices. Using a lower timeframe (1M for instance) allows me to determine the current time/market hours but forces me to use a secondary aggregation period - which is not allowed in the study scanner (or so I believe).
** Another Issue: I have no way of verifying my results unless I'm in the premarket. So I can only code and do trial and error for a limited time every day. Weird to me that we can't use these types of scanners in the OnDemand mode - makes the trial and error process a bit tougher. Is there a way to circumvent this? I'm relatively new to ToS!