How to specify time period in stock scan filter?

Mamba10

New member
I was wondering if it's possible to make a scan limited to a certain time period in the day. Specifically the first 15 mins after open. I want the scan to only output stocks that are exhibiting the filters I've set only at that exact time period in the day.

So I have a MTF MACD indicator that Hahn Tech publicly released. The histogram turns red or green if the Current, Mid, and Long term time frames are in conjunction. It took me some time to make a scan for it, but I got around TOS's "second aggregation not allowed". But I only want the scan to be limited to the first 15 mins of market open.

Could this thinkScript work, if I entered it correctly to the scan code? Or is there something better/easier?:

Code:
input OpenTime = 930;
input DurationMinutes = 15;
def durationSec = DurationMinutes * 60;
def secondsPassed = SecondsFromTime(OpenTime);
def within = if secondsPassed >= 0 and secondsPassed <= durationSec then close else  Double.NaN;
 

tomsk

Well-known member
VIP
Here is a GENERIC scan with a time bracket for the first 15 minutes of the trading day
Describe your scan condition via the variable "condition"
Here's the snippet which evaluates a boolean value

Code:
def condition = <DESCRIBE_YOUR_SCAN_CONDITION_HERE>

def Active = secondsTillTime(0930) > 0 and secondsFromTime(0945) > 0;

plot scan = condition and Active;
 

Mamba10

New member
Here is a GENERIC scan with a time bracket for the first 15 minutes of the trading day
Describe your scan condition via the variable "condition"
Here's the snippet which evaluates a boolean value

def condition = <DESCRIBE_YOUR_SCAN_CONDITION_HERE>
def Active = secondsTillTime(0930) > 0 and secondsFromTime(0945) > 0;
plot scan = condition and Active;

Thanks!!
 

msammons

Member
I tried the above code but there were no executions. I am trying to get trades to execute only from 6:00 am EST to 8:00 pm EST (regular day + normal extended hours). Lots of executions with this code but it does not eliminate the executions outside the extended hours (during backtesting). And when trading SPY thinkorswim extended hours are apparently 24/5.

Can anyone help? where is my code wrong? (or perhaps there is an easier way to restrict trades to only reg hours plus normal extended hours (8 am - 8 pm EST).

Code:
def x = ExpAverage(close, 30);
def y = ExpAverage(close,10);

input DayTimeStart=0600; # 8AM EST
input NightTimeEnd=1959; # 8PM EST

def CountfromStart=SecondsfromTime(DayTimeStart);
def CounttilEnd= Secondstilltime(NightTimeEnd);

def dayperiod=If(CountfromStart >0 && CounttilEnd >0,1,-1); # then 1 else 0;

def long = y crosses above x and dayperiod==1;
def short = y crosses below x and dayperiod == 1;

plot a = long;
plot b = short;

AddOrder(OrderType.BUY_TO_OPEN, long, open[-1], 100);
AddOrder(OrderType.SELL_TO_OPEN, short, open[-1], 100);
 

rovo

Member
Is it possible to scan for a specific time range, ie 3-4pm?

Currently I know how to setup my scanner to scan on the hourly timeframe, and I can designate how many bars back to include, but this isn't reliable as there are sometime varying number of bars depending on the stock.

I'd like to be able to scan the previous 3-4pm block of time whether it's 8pm or 11pm, and not worry about how many bars to include.
 

Benjaminsabe

New member
Is it possible to scan for a specific time range, ie 3-4pm?

Currently I know how to setup my scanner to scan on the hourly timeframe, and I can designate how many bars back to include, but this isn't reliable as there are sometime varying number of bars depending on the stock.

I'd like to be able to scan the previous 3-4pm block of time whether it's 8pm or 11pm, and not worry about how many bars to include.
Hey! Did you figure out how to do it? Been searching for it but havent been able to find anything
 

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Top