- the stock rules earned 1.8% without the bond income in the discovery window, no more than just holding the bond ETF (3.9%): the result is the bond sleeve, not the strategy
- significantly underperforms Equal-weight buy & hold basket (10 symbols) in the discovery window: CAGR 1.5% vs 8.5% (lags by 7.1 pp, limit 5.0 pp) and Sharpe 0.43 vs 0.59
“The strategy achieved a shallower drawdown (5.5% vs 20.9%) but failed to keep pace with its Equal-weight buy & hold basket (10 symbols) benchmark, trailing by 10.2 percentage points in CAGR over the backtest window.”
Research Integrity Gate
PASS — 8/8 Validated
Executive Summary
The strategy underperformed both benchmarks over the five-year period from October 7, 2021, to October 7, 2026. With a total return of 15%, it lagged behind the equal-weight buy-and-hold basket’s return of 85% and the buy-and-hold SPY’s return of 90% by 69.73 and 74.77 percentage points, respectively. The strategy’s max drawdown of 5% was lower than the drawdowns of both benchmarks, which stood at 21% and 24%.What We Are Testing
This strategy employs a long-only ADX trend-emergence approach trading SPY, QQQ, IWM, EFA, EEM, TLT, GLD, XLK, XLF, and XLE. It uses a 14-period ADX to gauge trend strength, with a 50-period and 200-period SMA to assess price trends. Positions are entered when the ADX crosses above 20, the close is above the 50-period SMA, and the 50-period is above the 200-period. Exits occur when the close drops below the 50-period SMA or the ADX falls below 20.
Cash not held in a position is invested in the SHY bond ETF and earns its daily total return, so the strategy is never uninvested.
Strategy Design
Base Backtest Result
The strategy recorded 37 positive months versus 24 negative months, with average gains of 1% during winning months and average losses of about 1%. The average closed-trade result was $89, yielding a win rate of 48% and a profit factor of 1.69.Symbol-Level Results
GLD contributed a net P&L of $4,949, the highest among symbols, followed by XLK at $3,626. The bottom performers included XLF at -$2,191 and IWM at -$1,983. Excluding the largest winner decreased net profit to $13,118, while removing the top five reduced it to $6,839.
Risk-Adjusted Quality
The worst drawdown lasted for 261 trading days, occurring between October 8, 2021, and October 20, 2022, with recovery achieved by June 15, 2023. The average drawdown length was 27 trading days, with an average recovery time of about 12 days.
Limits of This Backtest
- There was no available overfitting-guard statistic to verify the robustness of the strategy against data mining.
Monthly Returns
Monthly returns reflected a distribution of 37 positive months versus 24 negative months, highlighting an inclination toward gains. Notably, the longest unbroken stretch below a prior peak spanned 423 trading days, indicating a prolonged period without recovery to prior equity peaks.
Held-Out Validation
The rules were written down before any results existed. The data was split at 2025-02-04: the first part (the discovery window) decided whether the strategy was worth writing about at all, and the second part (the held-out window) was scored exactly once, only after the strategy had cleared the first. Nothing was adjusted after looking at the held-out numbers.
Held-out window: the stock rules alone returned 6.0% against 5.1% for simply holding the bond ETF over the same days.
Buy-And-Hold Comparison
What The Result Teaches
This walkthrough serves an educational purpose, highlighting that past results do not guarantee future performance.Next Tests
The strategy recorded a win rate of 48%, which indicates a relatively even split between winning and losing trades. Given that the average closed-trade result was only $89, introducing a tighter exit condition, such as exiting every time the close falls below the SMA(50), might help capture gains more effectively and potentially improve overall profitability.
Trade SPY, QQQ, IWM, EFA, EEM, TLT, GLD, XLK, XLF, and XLE from 2021-10-07 to 2026-10-07 using a long-only ADX trend-emergence strategy with daily bars, signals evaluated on the close, next-open execution, no leverage, no shorting, and one equal-dollar slot per symbol based on starting equity of $100,000 divided by 10, using whole shares and no adding to an existing position. For each symbol, compute ADX(14), SMA(50), and SMA(200). Enter long when the symbol is not already held, ADX(14) crosses above 20 from at or below 20, the close is above the SMA(50), and the SMA(50) is above the SMA(200). Exit when the symbol is held and the close falls below the SMA(50).
What Should We Test Next?
Help prioritize the next quantitative experiment for this strategy family in our lab:
Run This Strategy with Different Parameters
Modify lookback periods, test alternative universes, or adjust risk parameters in the web application backtesting engine.
Open in Web Studio →Reproduce This Test
# %% Environment
#' Load the backtesting packages and set a stable timezone.
suppressPackageStartupMessages({
library(quantmod)
library(TTR)
library(xts)
library(FinancialInstrument)
library(blotter)
library(quantstrat)
})
Sys.setenv(TZ = 'UTC')
options(width = 120)
%% Universe & Parameters
#' Strategy specification implemented here: ADX(14), SMA(50), and SMA(200);
#' enter long when not held, ADX crosses above 20, close > SMA50, and SMA50 > SMA200;
#' exit when held and close < SMA50 or ADX crosses below 20.
symbols <- c('SPY', 'QQQ', 'IWM', 'EFA', 'EEM', 'TLT', 'GLD', 'XLK', 'XLF', 'XLE')
start_date <- as.Date('2021-10-07')
end_date <- as.Date('2026-10-07')
init_equity <- 100000
n_symbols <- length(symbols)
slot_size <- init_equity / n_symbols
adx_n <- 14
sma_fast_n <- 50
sma_slow_n <- 200
transaction_cost_bps <- 0.0005
parameter_table <- data.frame(
parameter = c('symbols', 'start_date', 'end_date', 'init_equity', 'n_symbols', 'slot_size', 'adx_n', 'sma_fast_n', 'sma_slow_n', 'transaction_cost_bps'),
value = c(paste(symbols, collapse = ', '), as.character(start_date), as.character(end_date), init_equity, n_symbols, slot_size, adx_n, sma_fast_n, sma_slow_n, transaction_cost_bps)
)
print(parameter_table)
%% Data
#' Download unadjusted Yahoo data, convert every symbol to adjusted OHLC, and stop if a split-like daily return remains.
getSymbols(symbols, from = start_date, to = end_date, src = "yahoo", adjust = FALSE)
for (sym in symbols) assign(sym, adjustOHLC(get(sym), use.Adjusted = TRUE))
for (sym in symbols) {
worst <- max(abs(dailyReturn(Cl(get(sym)))), na.rm = TRUE)
if (worst > 0.40) stop(sprintf("%s has a %.0f%% one-day move: likely an unadjusted split.", sym, worst * 100))
}
%% Portfolio Account & Strategy Setup
#' Create a long-only quantstrat portfolio, account, orders object, and strategy container.
portfolio.st <- 'adx_trend_emergence'
account.st <- 'adx_trend_emergence_account'
strategy.st <- 'adx_trend_emergence'
suppressWarnings(try(rm.strat(portfolio.st), silent = TRUE))
suppressWarnings(try(rm.strat(account.st), silent = TRUE))
suppressWarnings(try(rm.strat(strategy.st), silent = TRUE))
try(currency('USD'), silent = TRUE)
for (sym in symbols) suppressWarnings(stock(sym, currency = 'USD', multiplier = 1))
init_date <- as.character(start_date - 1)
initPortf(portfolio.st, symbols = symbols, initDate = init_date, currency = 'USD')
initAcct(account.st, portfolios = portfolio.st, initDate = init_date, currency = 'USD', initEq = init_equity)
initOrders(portfolio.st, symbols = symbols, initDate = init_date)
strategy(strategy.st, store = TRUE)
%% Indicators
#' Compute ADX(14), SMA(50), and SMA(200) for each symbol.
add.indicator(strategy.st, name = 'ADX', arguments = list(HLC = quote(HLC(mktdata)), n = adx_n), label = 'ADX')
add.indicator(strategy.st, name = 'SMA', arguments = list(x = quote(Cl(mktdata)), n = sma_fast_n), label = 'SMA50')
add.indicator(strategy.st, name = 'SMA', arguments = list(x = quote(Cl(mktdata)), n = sma_slow_n), label = 'SMA200')
%% Signals
#' Build entry and exit signals from ADX crosses and moving average trend conditions.
add.signal(strategy.st, name = 'sigThreshold', arguments = list(column = 'ADX.ADX', threshold = 20, relationship = 'gt', cross = TRUE), label = 'ADXCrossUp')
add.signal(strategy.st, name = 'sigThreshold', arguments = list(column = 'ADX.ADX', threshold = 20, relationship = 'lt', cross = TRUE), label = 'ADXCrossDown')
add.signal(strategy.st, name = 'sigComparison', arguments = list(columns = c('Close', 'SMA.SMA50'), relationship = 'gt'), label = 'CloseAboveSMA50')
add.signal(strategy.st, name = 'sigComparison', arguments = list(columns = c('SMA.SMA50', 'SMA.SMA200'), relationship = 'gt'), label = 'SMA50AboveSMA200')
add.signal(strategy.st, name = 'sigComparison', arguments = list(columns = c('Close', 'SMA.SMA50'), relationship = 'lt'), label = 'CloseBelowSMA50')
add.signal(strategy.st, name = 'sigFormula', arguments = list(formula = 'ADXCrossUp & CloseAboveSMA50 & SMA50AboveSMA200', cross = FALSE), label = 'EnterLong')
add.signal(strategy.st, name = 'sigFormula', arguments = list(formula = 'ADXCrossDown | CloseBelowSMA50', cross = FALSE), label = 'ExitLong')
%% Rules
#' Enter with one whole-share equal-dollar slot at the next open, do not pyramid, and apply transaction costs.
trade_value_fee <- function(TxnQty, TxnPrice, ...) {
-abs(as.numeric(TxnQty) * as.numeric(TxnPrice)) * transaction_cost_bps
}
osEqualDollar <- function(data, timestamp, orderqty, ordertype, orderside, portfolio, symbol, ruletype, ...) {
pos_qty <- getPosQty(portfolio, symbol, timestamp)
if (!is.na(pos_qty) && pos_qty != 0) return(0)
row_num <- which(index(data) == timestamp)
if (length(row_num) != 1 || row_num >= NROW(data)) return(0)
next_open <- as.numeric(Op(data)[row_num + 1])
if (is.na(next_open) || next_open <= 0) return(0)
qty <- floor(slot_size / (next_open * (1 + transaction_cost_bps)))
if (is.na(qty) || qty < 1) return(0)
qty
}
apply_trade_value_fees <- function(portfolio, symbols) {
for (sym in symbols) {
txn <- getTxns(portfolio, sym)
if (is.null(txn) || NROW(txn) == 0) next
fees <- trade_value_fee(txn$Txn.Qty, txn$Txn.Price)
fees[is.na(fees)] <- 0
.blotter[[portfolio]]$symbols[[sym]]$txn$Txn.Fees <- fees
}
}
add.rule(strategy.st, name = 'ruleSignal', arguments = list(sigcol = 'EnterLong', sigval = TRUE, orderqty = 1, ordertype = 'market', orderside = 'long', prefer = 'Open', replace = FALSE, osFUN = 'osEqualDollar'), type = 'enter', label = 'EnterLong')
add.rule(strategy.st, name = 'ruleSignal', arguments = list(sigcol = 'ExitLong', sigval = TRUE, orderqty = 'all', ordertype = 'market', orderside = 'long', prefer = 'Open', replace = FALSE), type = 'exit', label = 'ExitLong')
%% Run the Backtest
#' Apply the strategy, charge percentage transaction costs to every filled trade, then update portfolio, account, and ending equity.
applyStrategy(strategy.st, portfolios = portfolio.st)
apply_trade_value_fees(portfolio.st, symbols)
updatePortf(portfolio.st)
updateAcct(account.st)
updateEndEq(account.st)
%% Idle Cash in Bonds
#' Cash that is not held in a position is never left idle. It is treated as invested in a short-term
#' Treasury bond ETF (bond_symbol) and earns that ETF's daily total return (dividends included). The
#' stock positions and their trades are unchanged; the bond income is credited to the account as interest, so
#' every equity, return and drawdown figure below includes it. Idle cash on a day is the equity of the stock
#' account minus the market value of the stock positions, plus the bond income already earned.
bond_symbol <- "SHY"
getSymbols(bond_symbol, from = start_date, to = end_date, src = "yahoo", adjust = FALSE)
bond_ret <- dailyReturn(Ad(get(bond_symbol)))
acct_summary <- getAccount(account.st)$summary
acct_dates <- index(acct_summary)
stock_equity <- as.numeric(acct_summary$End.Eq)
stock_value <- as.numeric(getPortfolio(portfolio.st)$summary$Long.Value[acct_dates])
idle_cash <- stock_equity - stock_value
bond_daily <- numeric(length(acct_dates)) # one value per account date; 0 on a date with no bond price
pos <- match(as.Date(acct_dates), as.Date(index(bond_ret)))
bond_daily[!is.na(pos)] <- as.numeric(bond_ret)[pos[!is.na(pos)]]
bond_value <- max(idle_cash[1], 0) # cash held in the bond ETF at the close of the previous day
bond_earned <- 0 # bond income accumulated so far
bond_income <- numeric(length(acct_dates))
for (i in seq_along(acct_dates)[-1]) {
bond_income[i] <- bond_value * bond_daily[i]
bond_earned <- bond_earned + bond_income[i]
bond_value <- max(idle_cash[i] + bond_earned, 0)
}
for (i in which(bond_income != 0)) {
addAcctTxn(account.st, TxnDate = acct_dates[i], TxnType = "Interest", Amount = bond_income[i], verbose = FALSE)
}
updateAcct(account.st)
updateEndEq(account.st)
cat(sprintf("Idle cash earned $%s in %s over the window.\n", format(round(sum(bond_income)), big.mark = ","), bond_symbol))
Full Per-Symbol Trade Statistics
Strategy Code & Replication
The strategy code behind every number in this article is published as standalone, pre-executed research reports. Each one re-runs the backtest end to end against freshly downloaded market data when rendered.
More Backtests
- Can Keltner Channel Breakouts Beat Buy-and-Hold? A 3-Year Test on Tech Equities & QQQ
- MACD SMI Trend Following Across Sector & Global ETFs
- Can OBV Accumulation Signals Improve Trend Entries on Diversified ETFs?
Get the Next Strategy Post-Mortem
One hypothesis. One serious test. Failures included. We stress-test quantitative strategies until they break and publish the unvarnished results.