Calculate top and bottom half of the hour

gavin

New member
Hi all, I'm trying to scan for inside hourly bars on equities with the following settings:

1. Show Extended-Hours Trading session is disabled
2. Start aggregations at market open is enabled

The problem I'm running into is that I'm unaware of a way to account for #2 above in my basic test condition: high[1] < high[2] and low[1] > low[2]

The problem is, that's only valid at the top half of any hour, from XX:00 - XX:29. At XX:30 - XX:59 I need to switch over to another scan, but it would be great if there's a way to account for the current time and include all conditions in one scan. Obviously this is because I'm hacking this together by aggregating two 30m bars, and the lookback period depends on how many 30m bars exist.

If anyone has an idea of how to do this or a workaround then I'd really appreciate it!
 
Last edited:
Solution
You can calculate the half hour of the day using code like this:
Code:
declare lower;

def Y = 31556926;
def M = 2629743;
def D = 86400;
def H = 3600;
def HalfHour = 1800;
def epoch = (getTime() / 1000);
def YMD = (epoch % Y) - (epoch / Y);
def month = (Floor(YMD / M) + 1);
def Half_Hour_Index = Floor((epoch % D) / HalfHour);

def lower_half = Half_Hour_Index % 2;

lower_half will return 1 when true (when you are in the second half of the hour) and 0 when false (first half of the hour). You can then use this as a driver for which equation to use in the calculation of your study.

Hope that helps

Happy Trading,
Mashume
You can calculate the half hour of the day using code like this:
Code:
declare lower;

def Y = 31556926;
def M = 2629743;
def D = 86400;
def H = 3600;
def HalfHour = 1800;
def epoch = (getTime() / 1000);
def YMD = (epoch % Y) - (epoch / Y);
def month = (Floor(YMD / M) + 1);
def Half_Hour_Index = Floor((epoch % D) / HalfHour);

def lower_half = Half_Hour_Index % 2;

lower_half will return 1 when true (when you are in the second half of the hour) and 0 when false (first half of the hour). You can then use this as a driver for which equation to use in the calculation of your study.

Hope that helps

Happy Trading,
Mashume
 
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
208 Online
Create Post

Similar threads

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.
Back
Top