thinkorswim Stock Hacker
Fix the Secondary Aggregation Error in thinkorswim Stock Hacker
A daily candle that closed up and a five-minute candle that closed above its predecessor are two separate checks. Comparing a five-minute close with the previous session’s daily high requires both prices in the same calculation. Start by writing your condition in plain English so you can tell which case you have.
Quick Answer
Stock Hacker gives each Study filter one timeframe. For independent daily and intraday conditions, create two Custom Study filters in All of the following and set each filter’s aggregation separately. If the condition compares a five-minute close directly with the previous day’s high, verify the comparison on a five-minute chart with the daily level plotted.
Set up one daily Study filter and one five-minute Study filter
In thinkorswim Desktop, go to Scan → Stock Hacker and choose a small stock watchlist in Scan in. In All of the following, add a Study filter, select Custom, then open thinkScript Editor. Set this filter’s aggregation to Day. Paste the daily script below and save the filter.
Add a second Custom Study filter in the same group. Set this one to five minutes and paste the five-minute script. For this regular-session example, leave EXT off and match the extended-hours setting on your chart. Each filter should contain exactly one plot. Run the scan after the first few five-minute bars have completed in the regular session.
Daily filter
plot scan = close[1] > open[1];
Five-minute filter
plot scan = close[1] > close[2];
The daily filter asks whether the last completed daily candle closed above its open. The five-minute filter asks whether the last completed five-minute candle closed above the preceding five-minute close. With both filters in All of the following, a symbol has to pass both checks. If your scan is empty, run each filter by itself against the same watchlist to see which one removes the symbol you expected.
Why the scan can pass a stock that is still below yesterday’s high
At 10:12 a.m. ET, both example stocks have a last completed five-minute close of 105.00. Each stock’s prior daily close was above its daily open. Both also rose from the previous five-minute close of 104.00. Their results diverge only when you bring the previous daily high into the comparison.
Two fictional stocks in the same scan| Check | Stock A | Stock B |
|---|
| Prior daily open → close | 100 → 102 | 100 → 102 |
|---|
| Last two completed five-minute closes | 104 → 105 | 104 → 105 |
|---|
| Passes both scan filters? | Yes | Yes |
|---|
| Prior daily high | 104 | 106 |
|---|
| Five-minute close above prior daily high? | Yes | No |
|---|
Check the completed five-minute candle against the prior daily high
Open a five-minute time chart. Go to Studies → Edit Studies and create a chart study. Paste the code below, save it and add it to the chart. It plots the previous daily candle’s high. The day offset belongs to the daily price series. On Monday, the previous daily candle normally belongs to Friday, assuming there was no holiday.
plot PriorDayHigh = high(period = AggregationPeriod.DAY)[1];
At 10:12 a.m., use the candle that ended at 10:10, while the 10:10–10:15 candle is forming. Read its close and the study level on that candle. In the example, Stock A closed one point above the line and Stock B closed one point below it. If the line differs from the daily high you expected, open the same symbol on a daily chart and check the previous candle and session before relying on the comparison.
If you paste the daily-level line into a five-minute Stock Hacker filter, the secondary aggregation error returns. Keep the line on the chart. Use the scan to narrow your list if the independent criteria are part of your setup, then check the daily level on each chart.
Sources
Official References
Platform details on this page were checked against these official resources.
Related Guides
Keep Building the Rule System
FAQ
Common Questions
Can I use two timeframes in one thinkorswim Stock Hacker scan?
Yes, with separate Study filters that each use their own aggregation. For two independent criteria that must both pass, put the filters in All of the following.
Why does thinkScript with AggregationPeriod.DAY work on my chart and fail in Stock Hacker?
A chart study can reference daily data when its chart timeframe is five minutes. Stock Hacker prohibits secondary aggregation inside a Study filter. Choose Day on the filter itself for conditions that only need daily bars.
Can separate filters tell me whether the five-minute close is above yesterday’s high?
Separate filters test independent conditions. To check one price directly against the other, plot the previous daily high on a five-minute chart and compare it with the close of the completed candle.
Risk Disclosure
Futures trading contains substantial risk and is not suitable for every investor. TradeReign is a trading-discipline and rule-enforcement application. It does not provide trading advice, trade signals, investment recommendations, or performance guarantees.
TradeReign is not a broker-dealer, futures commission merchant, or investment advisor.
Futures trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Only risk capital - money that can be lost without jeopardizing financial security or lifestyle - should be used for trading. Past performance is not necessarily indicative of future results.