DCA & Accumulation Strategies
Simple Time-Based DCA
Tags: dca, time_based, accumulation, simple, notional
Functions: Notional
Description: Fixed-amount DCA buy on every candle. The simplest DCA strategy.
Code:
ticker = context['ticker']
# Buy every candle with fixed notional amount
always_true = close > 0
emit(always_true, entry(ticker, 'LONG', Notional(100), accumulate=True))
Monday Weekly DCA
Tags: dca, weekly, monday, time_based, periodic
Functions: Notional, weekday, hour, minute
Description: Buys a fixed amount on each Monday candle. Uses calendar variables instead of bar-count modulo.
Code:
ticker = context['ticker']
# ISO weekday: Monday=1 ... Sunday=7
monday_open = (weekday == 1) & (hour == 0) & (minute == 0)
emit(monday_open, entry(ticker, 'LONG', Notional(500), accumulate=True))
RSI-Based DCA
Tags: dca, rsi, smart_dca, condition_based
Functions: rsi, Notional
Description: DCA buy only when RSI is below 40. Accumulates only in oversold conditions.
Code:
ticker = context['ticker']
rsi_val = rsi(close, 14)
# Only DCA when RSI is below 40 (favorable conditions)
favorable = rsi_val < 40
emit(favorable, entry(ticker, 'LONG', Notional(100), accumulate=True))
RSI Zone Fixed DCA
Tags: dca, rsi, fixed_amount, smart_dca
Functions: rsi, Notional
Description: Buys the same fixed amount across RSI oversold zones. Production DCA accounting uses one fixed notional amount per run.
Code:
ticker = context['ticker']
rsi_val = rsi(close, 14)
# Buy a fixed amount whenever RSI is in an oversold zone
oversold_zone = rsi_val < 40
emit(oversold_zone, entry(ticker, 'LONG', Notional(100), accumulate=True))
Price Drop DCA
Tags: dca, price_drop, discount, accumulation
Functions: ts_mean, Notional
Description: Adds to position whenever the price drops 5% or more below the 20-day moving average.
Code:
ticker = context['ticker']
ma20 = ts_mean(close, 20)
# Price is 5% or more below MA
discount = (ma20 - close) / ma20
buy_dip = discount > 0.05
emit(buy_dip, entry(ticker, 'LONG', Notional(200), accumulate=True))
Volatility-Filtered Fixed DCA
Tags: dca, volatility, atr, fixed_amount
Functions: atr, ts_mean, Notional
Description: Buys a fixed amount only when volatility is not elevated. Do not vary DCA notional inside one run.
Code:
ticker = context['ticker']
atr_val = atr(high, low, close, 14)
atr_avg = ts_mean(atr_val, 50)
# Skip unusually high-volatility bars
volatility_ok = atr_val <= atr_avg * 1.2
emit(volatility_ok, entry(ticker, 'LONG', Notional(100), accumulate=True))
Bollinger Band DCA
Tags: dca, bbands, discount, fixed_amount
Functions: bollinger_bands, Notional
Description: Buys a fixed amount when price is below the Bollinger middle band and near the lower zone.
Code:
ticker = context['ticker']
upper, middle, lower = bollinger_bands(close, 20, 2)
# Buy the same fixed amount in the lower half of the band
near_lower = close < lower * 1.02
between = (close >= lower * 1.02) & (close < middle)
buy_zone = near_lower | between
emit(buy_zone, entry(ticker, 'LONG', Notional(100), accumulate=True))
Fear & Greed DCA
Tags: dca, rsi, momentum, contrarian
Functions: rsi, Notional
Description: RSI-based fear/greed index. Buys during fear (low RSI) and stops buying during greed (high RSI).
Code:
ticker = context['ticker']
rsi_val = rsi(close, 14)
# Fear zones use the same fixed amount
extreme_fear = rsi_val < 25
fear = (rsi_val >= 25) & (rsi_val < 40)
neutral = (rsi_val >= 40) & (rsi_val < 60)
# No buying when RSI > 60 (greed)
fear_zone = extreme_fear | fear | neutral
emit(fear_zone, entry(ticker, 'LONG', Notional(100), accumulate=True))
MA Cross DCA Trigger
Tags: dca, ma, crossover, trigger
Functions: sma, Notional
Description: Starts DCA only after a golden cross. Accumulates after trend reversal is confirmed.
Code:
ticker = context['ticker']
ma20 = sma(close, 20)
ma50 = sma(close, 50)
# Only DCA when short MA is above long MA (uptrend)
uptrend = ma20 > ma50
emit(uptrend, entry(ticker, 'LONG', Notional(100), accumulate=True))
Grid-Style Accumulation
Tags: dca, grid, levels, fixed_amount
Functions: ts_mean, Notional
Description: Buys the same fixed amount at several price levels. For different amounts, run separate fixed-amount backtest variants.
Code:
ticker = context['ticker']
reference_price = ts_mean(close, 100) # Use 100-day average as reference
# Calculate price level relative to reference
price_ratio = close / reference_price
# Grid levels: buy the same fixed notional at lower levels
level_1 = (price_ratio >= 0.95) & (price_ratio < 1.0)
level_2 = (price_ratio >= 0.90) & (price_ratio < 0.95)
level_3 = (price_ratio >= 0.85) & (price_ratio < 0.90)
level_4 = price_ratio < 0.85
buy_level = level_1 | level_2 | level_3 | level_4
emit(buy_level, entry(ticker, 'LONG', Notional(100), accumulate=True))
DCA with Take Profit
Tags: dca, take_profit, exit, profit_taking
Functions: rsi, Notional, PercentFromEntry
Description: DCA buy combined with full exit when RSI is overbought to realize profits.
Code:
ticker = context['ticker']
rsi_val = rsi(close, 14)
# DCA when RSI < 50
buy_cond = rsi_val < 50
# Take profit when overbought
exit_cond = rsi_val > 75
emit(buy_cond, entry(ticker, 'LONG', Notional(100), accumulate=True))
emit(exit_cond, exit_position(ticker))