“Impossible” problem: Coding a hourly condition in a daily timeframe study???

joetimismith

New member
I’m really stumped on this one.

I have this study that scans for a set of 2 candles that meet certain criteria in the daily time frame, like a bullish engulfing for example. Is there a way I can add a condition in the same study where the second candle's first hourly candle needs to have a greater move from its close minus open than the rest of the candles in that day combined (last hour's close minus second hour's open). Note that this second candle on the daily timeframe has to be green, meaning its close needs to be higher than the open.

If anyone can help me out with this, I really would appreciate it!
 
Welcome to the Forum @joetimismith You are right, what you want to do is impossible on the TOS platform

The Peculiarities Of Secondary Aggregations
The secondary aggregation period cannot be less than the chart that it is being displayed on. Higher timeframes can be used on lower timeframe charts but not the other way around.

FYI: The secondary aggregation period can not be referenced in scans on the TOS platform.
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation
 

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

Note: While what you're asking for isn't possible, I've finagled a way to get a scan for stocks that meet your criteria, in the StockHacker.
Note: This only works end-of-day, as it's not time-of-day aware, and just uses offsets.
Note: You have to use two thinkscripts: one at HOURLY aggregation, and another at DAILY aggregation.
(I use this technique often, comparing the YEARLY/QUARTERLY/MONTHLY/WEEKLY to what's going on at lower time frames (DAILY, 4-HR, etc.), to help me spot good reversal candidates that have a chance of re-gaining their long-term trend.)

In StockHacker,
All of The Following:
Add Filter > Study > Custom > thinkScript Editor
Aggregation: DAILY
Code:
input length = 20;
input trendSetup = 3;

def BodyMax = Max(open(period = AggregationPeriod.DAY), close(period = AggregationPeriod.DAY));
def BodyMin = Min(open(period = AggregationPeriod.DAY), close(period = AggregationPeriod.DAY));
def IsEngulfing = BodyMax > BodyMax[1] and
    BodyMin < BodyMin[1];
def IsBlack = open(period = AggregationPeriod.DAY) > close(period = AggregationPeriod.DAY);
def IsWhite = open(period = AggregationPeriod.DAY) < close(period = AggregationPeriod.DAY);
def IsPrevDoji = IsDoji(length)[1];

def BullishEngulfing = IsDescending(close(period = AggregationPeriod.DAY), trendSetup)[1] and
    (IsBlack[1] or IsPrevDoji) and
    IsWhite and
    IsEngulfing;

plot scan = BullishEngulfing;

Then, also under "All of the Following"
Add Filter > Study > Custom > thinkScript Editor
Aggregation: 1h
Include Extended-hours trading session [UNCHECKED]
Code:
# SCAN END-OF-DAY
# ONE HOUR
#EXTENDED-HOURS = OFF
# This script assumes you're using an hourly chart, and it's END-OF-DAY, and looks for the last 7 bars on that chart. You might have UNEXPECTED results on different timeframes or different times of day.


## Get the close and open of first hourly candle
rec Bar1Open = open[6];
rec Bar1Close = close[6];

## Get the open of second hourly candle
rec Bar2Open = open[5];

## Get the close of LAST hourly candle
rec Bar7Close = close[0];

## FIRST HOURLY CANDLE has a bigger close to open move than the rest of the candles that day.
def Bar1BigMove = AbsValue(Bar1Close - Bar1Open) > AbsValue(Bar7Close - Bar2Open);

plot scan = Bar1BigMove;

Example of the scan (I sorted the results by Volume):

8WSaP5Q.png



Hourly criteria met on $BTG:

JyEv9ed.png


Daily criteria met on $BTG:

En5TPnl.png
 
Last edited by a moderator:

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
117 Online
Create Post

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