Momentum & Trend Following Strategies
RSI Momentum Long Only
Tags: momentum, rsi, oversold, spot, simple
Functions: rsi
Description: Basic RSI strategy that buys when RSI drops below 30 (oversold) and sells when it rises above 70 (overbought).
Code:
ticker = context['ticker']
rsi_val = rsi(close, 14)
long_cond = rsi_val < 30
exit_cond = rsi_val > 70
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
RSI with Trend Filter
Tags: momentum, rsi, trend, sma, filter
Functions: rsi, sma
Description: Enters long only when RSI is oversold and price is above the 200-day MA, preventing counter-trend entries.
Code:
ticker = context['ticker']
rsi_val = rsi(close, 14)
ma200 = sma(close, 200)
# Trend filter: only long above MA200
trend_up = close > ma200
long_cond = (rsi_val < 30) & (trend_up)
exit_cond = rsi_val > 70
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
Dual RSI Strategy
Tags: momentum, rsi, multi_period, confirmation
Functions: rsi
Description: Enters only when both short-period RSI(7) and mid-period RSI(14) are oversold simultaneously, improving signal reliability.
Code:
ticker = context['ticker']
rsi_short = rsi(close, 7)
rsi_mid = rsi(close, 14)
# Both RSIs must be oversold
long_cond = (rsi_short < 30) & (rsi_mid < 35)
exit_cond = (rsi_short > 70) | (rsi_mid > 65)
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
MACD Crossover
Tags: momentum, macd, crossover, trend
Functions: macd_all
Description: Buys when the MACD line crosses above the signal line and sells when it crosses below.
Code:
ticker = context['ticker']
macd_line, signal_line, histogram = macd(close, 12, 26, 9)
# MACD crosses above signal
long_cond = (macd_line > signal_line) & (macd_line.shift(1) <= signal_line.shift(1))
# MACD crosses below signal
exit_cond = (macd_line < signal_line) & (macd_line.shift(1) >= signal_line.shift(1))
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
MACD Histogram Reversal
Tags: momentum, macd, histogram, reversal
Functions: macd_all
Description: Buys when the MACD histogram turns positive from negative, capturing momentum reversals.
Code:
ticker = context['ticker']
_, _, histogram = macd(close, 12, 26, 9)
# Histogram turns positive from negative
long_cond = (histogram > 0) & (histogram.shift(1) <= 0)
# Histogram turns negative
exit_cond = (histogram < 0) & (histogram.shift(1) >= 0)
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
Stochastic Oversold Bounce
Tags: momentum, stochastic, oversold, bounce
Functions: stoch
Description: Buys when Stochastic %K crosses above %D while below the 20 oversold level.
Code:
ticker = context['ticker']
slowk, slowd = stoch(high, low, close, 14, 3, 3)
# Oversold + K crosses above D
oversold = slowk < 20
k_cross_d = (slowk > slowd) & (slowk.shift(1) <= slowd.shift(1))
long_cond = (oversold) & (k_cross_d)
# Overbought
exit_cond = slowk > 80
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
Triple EMA Trend
Tags: trend, ema, alignment, multi_ma
Functions: ema
Description: Enters when 8/21/55 EMAs are in bullish alignment and the short EMA is rising; exits on misalignment.
Code:
ticker = context['ticker']
ema8 = ema(close, 8)
ema21 = ema(close, 21)
ema55 = ema(close, 55)
# EMA alignment: 8 > 21 > 55
aligned = (ema8 > ema21) & (ema21 > ema55)
ema8_rising = ema8 > ema8.shift(1)
long_cond = (aligned) & (ema8_rising)
exit_cond = ema8 < ema21
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
ADX Strong Trend Entry
Tags: trend, adx, strength, filter
Functions: adx, sma
Description: Enters on MA crossover only when ADX is above 25, avoiding choppy sideways markets.
Code:
ticker = context['ticker']
trend_strength = adx(high, low, close, 14)
ma20 = sma(close, 20)
ma50 = sma(close, 50)
# Strong trend + MA crossover
strong_trend = trend_strength > 25
ma_cross_up = (ma20 > ma50) & (ma20.shift(1) <= ma50.shift(1))
long_cond = (strong_trend) & (ma_cross_up)
exit_cond = ma20 < ma50
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
Momentum Breakout with Volume
Tags: momentum, breakout, volume, confirmation
Functions: ts_mean, ts_std_dev
Description: Buys when price breaks above the 20-day high with a volume spike over 2x the average, filtering false breakouts.
Code:
ticker = context['ticker']
# 20-day high breakout
high_20 = ts_mean(high, 20) + ts_std_dev(high, 20)
breakout = close > high_20
# Volume spike (> 2x average)
vol_avg = ts_mean(volume, 20)
vol_spike = volume > vol_avg * 2
long_cond = breakout & vol_spike
exit_cond = close < sma(close, 20)
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(exit_cond, exit_position(ticker))
Perpetual RSI Long/Short
Tags: momentum, rsi, perpetual, long_short, futures
Functions: rsi
Description: Bidirectional RSI trading on futures: goes long on oversold and short on overbought conditions.
Code:
ticker = context['ticker'] # e.g., BINANCEFUTURES:BTC/USDT:USDT
rsi_val = rsi(close, 14)
long_cond = rsi_val < 30
short_cond = rsi_val > 70
exit_long = rsi_val > 50
exit_short = rsi_val < 50
emit(long_cond, entry(ticker, 'LONG', Weight(1.0)))
emit(short_cond, entry(ticker, 'SHORT', Weight(1.0)))
emit((exit_long) & (close > close.shift(1)), exit_position(ticker))
emit((exit_short) & (close < close.shift(1)), exit_position(ticker))