Feature
Multi-timeframe conditions
Price, indicator and pattern conditions can read bigger candles than the run itself uses. An hourly bot can buy 4-hour RSI dips only while the daily trend is up, and the engine makes sure each condition only sees bigger candles that have already closed.
How it works
Add on and a timeframe to the end of a condition, as in rsi(14) < 30 on 4h; in the Lab the same setting is on the block. The choices are 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d and 1w.
The timeframe must be at least the run's candle size and a whole multiple of it: a 1-hour run can read 2h, 4h, 1d or 1w, for example, but not 15m. A condition with a smaller timeframe stops the run with an error, and a run that fails is not charged. A timeframe equal to the run's candle size changes nothing.
Lengths and lookbacks count the bigger candles: rsi(14) < 30 on 1d uses a 14-day RSI, whatever the run's candle size.
bot "4h Dips In A Daily Uptrend"
when price crosses below ema(50) on 1d
then sell 100%
when rsi(14) < 35 on 4h and macd(12,26,9) above zero on 1d
then buy 100%
Which blocks can use it
- Price: price move, price level, breakout, big candle and candle streak.
- Indicators: SMA and EMA crosses, golden cross, RSI, MACD, Bollinger Bands, Stochastic, ATR, volatility, Supertrend, ADX/DMI, Keltner Channel, CCI, Williams %R and the Chandelier exit.
- Patterns: candlestick patterns, fair value gaps and liquidity sweeps.
- Timing and portfolio blocks (hours, weekdays, cooldown, trade P&L, drawdown and the rest) and imported Pine Script conditions always use the run's own candles. A Pine script can read a higher timeframe itself with
request.security.
How the bigger candles are built
The engine builds the bigger candles from the run's own candles, in UTC: daily candles start at 00:00 UTC, weekly candles on Monday at 00:00 UTC, and smaller sizes divide the day evenly. Each takes the open of its first candle, the highest high, the lowest low and the close of its last candle.
A bigger candle's value becomes visible on the run candle that closes it, never earlier. On a 1-hour run, the 4-hour candle from 08:00 to 12:00 UTC is first seen by the hourly candle from 11:00 to 12:00. Before that, conditions read the 4-hour candle from 04:00 to 08:00. Nothing reads a bigger candle that is still forming, so there is no look-ahead and no repainting.
States and events
One bigger candle spans several run candles, so each condition is either a state or an event on a higher timeframe.
- States keep the result of the last completed bigger candle on every run candle until the next one closes. They include comparisons such as
rsi(14) < 30, price above or below a level or band,macd(…) above zero,supertrend(…) is bullish, ADX levels, breakouts, price moves and streaks. On a 1-hour run, each 4-hour result holds for four run candles. - Events fire once, on the run candle where the completed bigger candle becomes visible, and are false on the other run candles. They are the crosses (price and SMA or EMA, price level, golden cross, MACD and its signal), Supertrend flips, DMI crosses, candlestick patterns, fair value gaps, liquidity sweeps and big candles.
Warm-up
Indicators need history before the first candle of a run, and on bigger candles that history is longer. The engine loads the extra run candles automatically: an RSI(14) on 1d in a 1-hour run needs about 14 × 5 × 24 = 1,680 hourly candles of warm-up. Warm-up is capped at 20,000 run candles, so a very long indicator on weekly candles may not be fully settled when the run starts.
Worked example
Take the bot above on a 1-hour run:
rsi(14) < 35 on 4his a state. If the 4-hour candle from 08:00 to 12:00 UTC closes with an RSI of 33, the condition becomes true on the hourly candle from 11:00 to 12:00 and stays true through the candle from 14:00 to 15:00. The next 4-hour candle's RSI takes over on the candle from 15:00 to 16:00.macd(12,26,9) above zero on 1dis a state too. On every hourly candle of 5 March except the last, it reads the MACD of 4 March; the candle from 23:00 to 24:00, which completes 5 March, reads the MACD of 5 March.price crosses below ema(50) on 1dis an event. If the daily candle of 5 March closes below its 50-day EMA after closing above it on 4 March, the sell rule fires once, on the hourly candle from 23:00 to 24:00 on 5 March, and not on the other hourly candles.
Multi-timeframe conditions: frequently asked questions
Does a higher-timeframe condition repaint?
No. It only reads bigger candles that have closed, and each value appears on the run candle that closes its bigger candle.
Can I use a lower timeframe than the run?
No. The timeframe must be at least the run's candle size and a whole multiple of it; otherwise the run stops with an error and is not charged.
When does a weekly candle start?
On Monday at 00:00 UTC, like the weekly candles on the charts.
Why does a daily cross fire only once on an hourly run?
A cross is an event: it fires on the hourly candle that completes the day where the cross happened, and is false on every other hourly candle.
Can imported Pine Script conditions use another timeframe?
Not with this setting. A Pine script can request a higher timeframe of the same market itself with request.security.
What if the timeframe equals the run's candle size?
Nothing changes: the condition reads the run's own candles.
Related
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.