⬡ ADVANCED STRATEGY · WITH CODE · 12 MIN READ

Multi-timeframe strategy: timeframe confluence.

The technique that turns an average strategy into a good one: read the trend on the higher chart and enter on the lower one. Here is the concept, the single-timeframe mistake and the code to automate it.

By the RoboTraderIA Team· updated May 2026· intermediate to advanced level

Picture two traders running the same moving average crossover strategy. One trades looking only at the M5 and takes trades in every direction. The other only accepts M5 signals that are aligned with the H1 trend. The second one will trade less — and better. That is the essence of multi-timeframe: use the higher chart as the compass and the lower one as the trigger. It is one of the most effective ways to filter out bad trades.

01The single-timeframe mistake

Anyone trading off a single chart falls into a trap: a buy signal on the M5 can be perfectly aligned in the short term and still be nothing more than a bounce inside a downtrend on the H1. You buy, the bounce ends, and the higher trend swallows you. A single timeframe leaves you blind to context.

The tide metaphor: think of the higher timeframe as the tide and the lower one as the waves. You can see a wave rising (a buy signal on the M5), but if the tide is going out (a downtrend on the H1), betting on the wave is risky. Multi-timeframe makes you swim with the tide.

02The concept: higher trend, lower entry

The structure is always the same — two (sometimes three) timeframes with distinct roles:

Higher timeframe → DIRECTION

Defines whether you look only for buys or only for sells. E.g.: H1.

"Is price above the 200 moving average on the H1? Then I only look for buys."

Lower timeframe → TRIGGER

Gives the exact moment to enter, in the direction already defined. E.g.: M15.

"Was there a pullback and a bullish crossover on the M15? I go long."

H1: uptrend (look for buys only) tide: rising pullback = entry ✓ pullback = entry ✓ SELL signals on M15 are ignored — against the tide
With the H1 trending up, the bot only accepts buys. Pullbacks on the lower timeframe become entries; sell signals are ignored.

03Which timeframes to combine

The rule of thumb is a ratio of roughly 4 to 6 times between them — wide enough to give a different context, close enough to still make sense. Common combinations:

  • Day trading: M15 (trend) + M3 or M5 (entry)
  • Wider intraday: H1 (trend) + M15 (entry)
  • Swing: Daily (trend) + H4 (entry)

Some traders use three: a top one (macro direction), a middle one (operating trend) and a low one (trigger). More than three turns into paralysis — too much information, too few decisions.

04Coding the confluence

The bot has to pull two timeframes and cross-check the information. Here is how on both platforms:

Pine Script (TradingView)
//@version=5
strategy("Multi-Timeframe", overlay=true)

// trend on the HIGHER timeframe (e.g. 60 min)
tf_maior = input.timeframe("60", "Timeframe da tendência")
ma200_maior = request.security(syminfo.tickerid, tf_maior, ta.sma(close, 200))
fechamento_maior = request.security(syminfo.tickerid, tf_maior, close)
tendencia_alta = fechamento_maior > ma200_maior

// trigger on the CURRENT timeframe (the chart's, lower)
ma_rapida = ta.ema(close, 9)
ma_lenta  = ta.ema(close, 21)
gatilho_compra = ta.crossover(ma_rapida, ma_lenta)

// CONFLUENCE: only buys if the trigger AND the higher trend agree
if gatilho_compra and tendencia_alta
    strategy.entry("Compra", strategy.long)
Python (pulling 2 timeframes)
# multi_timeframe.py
def direcao_tendencia(df_maior):
    # trend on the higher chart: price vs the 200 moving average
    ma200 = df_maior["close"].rolling(200).mean().iloc[-1]
    return "ALTA" if df_maior["close"].iloc[-1] > ma200 else "BAIXA"

def gatilho_entrada(df_menor):
    # trigger on the lower chart: EMA crossover
    r = df_menor["close"].ewm(span=9).mean()
    l = df_menor["close"].ewm(span=21).mean()
    cruzou_cima = r.iloc[-2] < l.iloc[-2] and r.iloc[-1] > l.iloc[-1]
    return "COMPRA" if cruzou_cima else "AGUARDA"

# confluence
df_h1  = puxar_candles("WIN$N", timeframe_H1)
df_m15 = puxar_candles("WIN$N", timeframe_M15)

if direcao_tendencia(df_h1) == "ALTA" and gatilho_entrada(df_m15) == "COMPRA":
    print("Confluência confirmada — comprar")

In Pine, the key function is request.security — it fetches data from another timeframe inside the same script. In Python, you simply pull two DataFrames from different periods (via the MT5 API or Binance) and cross-check the information.

Combine it with the right indicators

The 200 moving average defines the higher trend; the EMA crossover gives the trigger. See the moving averages guide.

See moving averages →

05Watch out when automating

  • Repaint: in Pine, be careful with request.security using the still-forming candle of the higher timeframe — it can "repaint" and mislead you in the backtest. Use the value of the already closed candle ([1]) for reliable data.
  • Fewer trades is the point: multi-timeframe will cut your number of trades considerably. That is a feature, not a bug — you are filtering out the bad ones. Do not "loosen" the filter just to trade more.
  • Synchronization: make sure both timeframes belong to the same asset and are updated at the same moment. Data that is out of sync between them produces false signals.

06Why it works

Multi-timeframe works because it attacks the biggest enemy of most strategies: trading against the dominant trend. Statistically, trades aligned with the higher trend have a better expectancy. By filtering out everything that goes against the "tide", you cut a large slice of the losing trades — even keeping the same entry strategy. It is one of the few adjustments that improves results without adding fragile complexity.

The bigger principle: this ties into everything we preach — risk management and context are worth more than the strategy itself. Multi-timeframe is, at heart, a context filter. And a context filter is what separates a bot that survives from a bot that bleeds.

07Frequently asked questions

What is multi-timeframe analysis?

It means analyzing the same asset across several periods: a higher one to define the trend direction and a lower one for entry timing. Trading with the higher trend filters out a lot of bad trades.

Which timeframes should you combine?

Common rule: a ratio of 4 to 6 times. E.g.: H1 (trend) + M15 (entry), or Daily + H4 for swing trading. The higher one gives context, the lower one gives the trigger. Up to three timeframes works; beyond that it turns into paralysis.

How do you automate multi-timeframe?

The bot pulls two periods: it calculates the trend on the higher one (e.g. price above the 200 moving average) and only looks for entries on the lower one in that direction. In Pine, use request.security; in Python, pull two DataFrames and cross-check them.

Multi-timeframe cuts my number of trades, is that bad?

No, that is the point. You are filtering out trades against the trend (usually the worst ones). Fewer trades, better quality. Do not loosen the filter just to trade more — that cancels out the benefit.

What is repaint and how do you avoid it?

Repaint is when a higher timeframe value changes while the candle is still forming, misleading the backtest. Avoid it by using the value of the already closed candle (index [1] in Pine) when pulling higher timeframe data.

Related reading

🎁 Get the free trading bot (with the Quotex, Deriv and IQ Option APIs)

Open source bot + ready-made API code. You edit it by chatting with ChatGPT/Claude — no programming. Free, no spam.

👉 Want the ready-made bot instead? Go to botbinaryoptions.com →