HeyTraders Documentation

Multi-Timeframe Strategies

Higher TF Trend + Lower TF Entry

Tags: multi_timeframe, trend, entry, confirmation Functions: get_data, align_timeframe, sma, rsi Description: Confirms trend on the daily chart then enters on the hourly chart. Trades only in the direction of the bigger-picture trend. Code:

ticker = context['ticker']

# Current timeframe data (assumed 1h)
rsi_1h = rsi(close, 14)

# Higher timeframe (daily) for trend
btc_daily = get_data(ticker, '1d')
ma20_daily = sma(btc_daily.close, 20)
daily_uptrend_native = btc_daily.close > ma20_daily
daily_uptrend = align_timeframe(
    btc_daily, daily_uptrend_native, timeframe='1d', base_time=time
)

# Entry: daily uptrend + hourly oversold
long_cond = daily_uptrend & (rsi_1h < 30)
exit_cond = rsi_1h > 70

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))

Triple Timeframe Confluence

Tags: multi_timeframe, confluence, trend, filter Functions: get_data, align_timeframe, sma Description: Enters only when the daily, 4-hour, and 1-hour charts are all in an uptrend simultaneously. Code:

ticker = context['ticker']

# Daily trend
daily = get_data(ticker, '1d')
daily_trend_native = daily.close > sma(daily.close, 20)
daily_trend = align_timeframe(
    daily, daily_trend_native, timeframe='1d', base_time=time
)

# 4-hour trend
h4 = get_data(ticker, '4h')
h4_trend_native = h4.close > sma(h4.close, 20)
h4_trend = align_timeframe(
    h4, h4_trend_native, timeframe='4h', base_time=time
)

# Current (1h) - entry signal
ma20 = sma(close, 20)
h1_cross = (close > ma20) & (close.shift(1) <= ma20)

# Combine only after the higher-timeframe results are on the 1H timeline
long_cond = daily_trend & h4_trend & h1_cross
exit_cond = close < ma20

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))

Weekly Support with Daily Entry

Tags: multi_timeframe, support, weekly, daily Functions: get_data, align_timeframe, lowest, rsi Description: Buys when near weekly support and the daily RSI is oversold. Code:

ticker = context['ticker']

# Weekly support level (20-week low)
weekly = get_data(ticker, '1w')
weekly_support_native = lowest(weekly.low, 20)
weekly_support = align_timeframe(
    weekly, weekly_support_native, timeframe='1w', base_time=time
)

# Daily RSI
rsi_val = rsi(close, 14)

# Near weekly support (within 3%)
near_support = (close - weekly_support).abs() / weekly_support < 0.03

long_cond = near_support & (rsi_val < 30)
exit_cond = rsi_val > 60

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))

Intraday with Daily Filter

Tags: multi_timeframe, intraday, daily_filter, trend Functions: get_data, align_timeframe, sma, rsi Description: Takes intraday long positions only when price is above the daily 200-day MA. Code:

ticker = context['ticker']

# Daily trend filter
daily = get_data(ticker, '1d')
ma200_daily = sma(daily.close, 200)
daily_bullish_native = daily.close > ma200_daily
daily_bullish = align_timeframe(
    daily, daily_bullish_native, timeframe='1d', base_time=time
)

# Intraday entry (current timeframe)
rsi_val = rsi(close, 14)

long_cond = daily_bullish & (rsi_val < 25)
exit_cond = rsi_val > 65

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))

Momentum Divergence Across TF

Tags: multi_timeframe, divergence, momentum, rsi Functions: get_data, align_timeframe, rsi Description: Buy opportunity when daily RSI is rising while the 4-hour RSI is oversold. Code:

ticker = context['ticker']

# Daily momentum rising
daily = get_data(ticker, '1d')
rsi_daily = rsi(daily.close, 14)
daily_rising_native = rsi_daily > rsi_daily.shift(3)
daily_rising = align_timeframe(
    daily, daily_rising_native, timeframe='1d', base_time=time
)

# 4H oversold
h4 = get_data(ticker, '4h')
rsi_4h = rsi(h4.close, 14)
h4_oversold_native = rsi_4h < 30
h4_exit_native = rsi_4h > 60
h4_oversold = align_timeframe(
    h4, h4_oversold_native, timeframe='4h', base_time=time
)
h4_exit = align_timeframe(
    h4, h4_exit_native, timeframe='4h', base_time=time
)

# Divergence: daily rising but 4H oversold
long_cond = daily_rising & h4_oversold
exit_cond = h4_exit

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))

Swing Trade with Intraday Timing

Tags: multi_timeframe, swing, timing, entry Functions: get_data, align_timeframe, sma, bollinger_bands Description: Enters when the 4-hour Bollinger Band lower band is touched during a daily uptrend. Code:

ticker = context['ticker']

# Daily uptrend
daily = get_data(ticker, '1d')
ma50_daily = sma(daily.close, 50)
daily_uptrend_native = daily.close > ma50_daily
daily_uptrend = align_timeframe(
    daily, daily_uptrend_native, timeframe='1d', base_time=time
)

# 4H Bollinger Band touch
h4 = get_data(ticker, '4h')
upper_native, middle_native, lower_native = bollinger_bands(h4.close, 20, 2)
touch_lower_native = h4.close <= lower_native
exit_native = h4.close > middle_native
touch_lower = align_timeframe(
    h4, touch_lower_native, timeframe='4h', base_time=time
)
h4_exit = align_timeframe(
    h4, exit_native, timeframe='4h', base_time=time
)

long_cond = daily_uptrend & touch_lower
exit_cond = h4_exit

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))

Trend Confirmation Across Timeframes

Tags: multi_timeframe, trend, ema, confirmation Functions: get_data, align_timeframe, ema Description: Strong long entry when weekly, daily, and 4-hour EMAs are all in bullish alignment. Code:

ticker = context['ticker']

# Weekly EMA alignment
weekly = get_data(ticker, '1w')
ema8_w = ema(weekly.close, 8)
ema21_w = ema(weekly.close, 21)
weekly_aligned_native = ema8_w > ema21_w
weekly_aligned = align_timeframe(
    weekly, weekly_aligned_native, timeframe='1w', base_time=time
)

# Daily EMA alignment
daily = get_data(ticker, '1d')
ema8_d = ema(daily.close, 8)
ema21_d = ema(daily.close, 21)
daily_aligned_native = ema8_d > ema21_d
daily_aligned = align_timeframe(
    daily, daily_aligned_native, timeframe='1d', base_time=time
)

# 4H EMA crossover (entry trigger)
h4 = get_data(ticker, '4h')
ema8_4h = ema(h4.close, 8)
ema21_4h = ema(h4.close, 21)
h4_cross_native = (ema8_4h > ema21_4h) & (ema8_4h.shift(1) <= ema21_4h.shift(1))
h4_exit_native = ema8_4h < ema21_4h
h4_cross = align_timeframe(
    h4, h4_cross_native, timeframe='4h', base_time=time
)
h4_exit = align_timeframe(
    h4, h4_exit_native, timeframe='4h', base_time=time
)

long_cond = weekly_aligned & daily_aligned & h4_cross
exit_cond = h4_exit

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))

Scalping with HTF Context

Tags: multi_timeframe, scalping, context, short_term Functions: get_data, align_timeframe, sma, rsi Description: Scalps on the 15-minute chart in the direction of the 1-hour trend. Code:

ticker = context['ticker']

# 1H trend context
h1 = get_data(ticker, '1h')
ma20_h1 = sma(h1.close, 20)
h1_bullish_native = h1.close > ma20_h1
h1_bullish = align_timeframe(
    h1, h1_bullish_native, timeframe='1h', base_time=time
)

# 15min entry (current TF)
rsi_15m = rsi(close, 7)

# Scalp long in hourly uptrend
long_cond = h1_bullish & (rsi_15m < 20)
# Quick exit
exit_cond = rsi_15m > 60

emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))