DNS Research. Trading and Investing Blog. Free articles every day.

How to Build a Profitable Trend Following System From Scratch

advertisement

Understanding the Core Philosophy of Trend Following
Trend following operates on the premise that asset prices tend to move in sustained directions over time. Rather than predicting reversals or identifying tops and bottoms, a trend follower seeks to capture the middle portion of significant price moves. The strategy accepts that not every trade will be profitable, but the mathematical expectation of large winners and small losers creates positive returns over many trades. This asymmetry between gains and losses forms the foundation of every successful trend following system, from the classic Turtle Traders to modern managed futures funds. The core belief is that markets exhibit persistence, and human behavior—fear, greed, herding—drives prices to trend beyond rational levels. A profitable system exploits this persistence without needing to forecast economic data, earnings reports, or geopolitical events.

Defining Your Trading Universe
Before writing any code or placing any trade, you must decide what instruments your system will trade. Trend following works across futures, commodities, currencies, stocks, ETFs, and cryptocurrencies. Each universe has distinct characteristics: liquidity, volatility, transaction costs, and trading hours. Futures markets like crude oil, gold, and treasury bonds offer high liquidity and low relative costs. Stocks provide endless choices but suffer from overnight gaps and earnings events. Cryptocurrencies trade 24/7 with high volatility but variable liquidity. A robust starting universe includes 20–50 liquid, non-correlated instruments. Avoid over-concentration in one sector; otherwise, a single economic shock can devastate your portfolio. Document your universe selection criteria: minimum average daily volume, maximum bid-ask spread, and data availability. For beginners, ETFs tracking broad indices, commodities, and currencies offer an accessible entry point with lower capital requirements.

Selecting Timeframes and Data Frequency
Trend following systems are timeframe-agnostic, but profitability depends on matching your timeframe to your capital, risk tolerance, and lifestyle. Daily bars are the most common choice for retail traders because they require only end-of-day analysis, reduce noise, and have lower transaction costs. Weekly bars produce fewer signals and longer holding periods, suitable for patient investors. Intraday timeframes (1-minute to 1-hour) demand sophisticated infrastructure, low-latency execution, and higher capital to overcome costs. A daily system using 10–20 years of historical data provides enough trades for statistical validation. Avoid optimizing on too little data; trends can take months to unfold. Use adjusted data for splits and dividends if trading stocks. For futures, use continuous contracts with proper roll adjustments—back-adjusted or ratio-adjusted—to avoid artificial price gaps. Data quality is non-negotiable: missing bars, bad ticks, or survivorship bias will invalidate your backtest.

Entry Signal Construction: Moving Averages and Breakouts
The two canonical entry mechanisms are moving average crossovers and channel breakouts. A simple moving average (SMA) crossover uses a fast MA (e.g., 20-period) crossing above a slow MA (e.g., 100-period) to signal a long entry, and the opposite for shorts. Exponential moving averages (EMA) react faster but produce more whipsaws. A more robust variant is the triple moving average: fast, medium, and slow, requiring alignment before entry. Breakout systems, popularized by the Turtles, buy when price exceeds the highest high of the last N days (e.g., 20, 50, or 100) and sell short when price breaks below the lowest low. Donchian channels formalize this. To reduce false breakouts, add a confirmation filter: volume above average, closing price beyond the channel (not just intraday spike), or a volatility-adjusted threshold. Avoid entries based on single indicators alone; combine a trend filter (e.g., price above 200-day SMA for longs) with a trigger (e.g., 20-day breakout). This dual condition increases signal quality and reduces drawdowns.

Exit Strategies: Stop Losses, Trailing Stops, and Profit Targets
Entries are easy; exits determine profitability. Every trend following system needs a stop-loss to cap risk per trade. The most common is the ATR (Average True Range) stop: place a stop 2–3 times ATR below entry for longs. ATR adapts to volatility—wider stops in volatile markets, tighter in calm ones. A fixed percentage stop (e.g., 2%) is simpler but ignores volatility regimes. Trailing stops lock in profits as the trend extends. Popular trailing methods include: (a) a moving average stop—exit when price closes below a 50-day MA; (b) a channel exit—exit when price touches the opposite Donchian channel (e.g., 20-day low for longs); (c) a Chandelier exit—trail stop at highest high minus 3 ATR. Profit targets are generally avoided in trend following because they cap upside, which destroys the positive skew. Instead, let winners run until the trailing stop is hit. Some systems use a time stop: exit if the trade hasn’t moved favorably after X days. This frees capital for better opportunities. Never move a stop against your position; only tighten it in the direction of the trend.

Position Sizing and Risk Management
Position sizing is the single most important determinant of long-term survival. The goal is to risk a fixed fraction of equity per trade—typically 0.5% to 2%. The formula: Position Size = (Account Equity × Risk %) / (Entry Price − Stop Price). For example, with a $100,000 account, 1% risk, entry at $50, and stop at $48, the risk per share is $2. Position size = $1,000 / $2 = 500 shares. For futures, calculate the dollar value of the ATR-based stop and divide into your risk budget. Never risk more than 2% per trade; even 1% can produce 10–20 consecutive losers in a choppy market. Portfolio-level risk management includes: (a) maximum total exposure (e.g., 200% of equity across all positions); (b) maximum correlated exposure (e.g., no more than 30% in energy futures); (c) maximum number of open positions (e.g., 10–20); (d) daily loss limit (e.g., stop trading if down 5% in a day). Use volatility parity: size positions so each contributes equal risk (ATR × position value) to the portfolio. This prevents a single volatile instrument from dominating returns.

Backtesting Without Overfitting
Backtesting is not optional; it is the laboratory where you validate or discard your system. Use high-quality historical data spanning at least two full market cycles—ideally 15–20 years. Split data into in-sample (70%) for development and out-of-sample (30%) for validation. Never optimize on out-of-sample data. Avoid curve-fitting: if your system has more than 5–7 parameters, you are likely fitting noise. Prefer robust parameters that work across a range—e.g., a 50-day breakout works nearly as well as 45 or 55. Walk-forward analysis is superior: optimize on a rolling window, test on the next window, and repeat. This mimics real trading. Metrics to evaluate: Compound Annual Growth Rate (CAGR), maximum drawdown, Sharpe ratio (target > 0.7), Sortino ratio, Calmar ratio (CAGR / max drawdown), win rate (trend followers often win 35–45%), profit factor (gross profit / gross loss, target > 1.5), and average win / average loss (target > 2.5). Also examine trade duration, consecutive losers, and monthly return distribution. A system with a 30% max drawdown and 15% CAGR is realistic; anything promising 50% CAGR with 5% drawdown is fraudulent or overfitted.

Transaction Costs, Slippage, and Liquidity
Ignoring costs is the fastest way to turn a profitable backtest into a losing live system. Every trade incurs commission, exchange fees, and slippage (difference between expected and actual fill price). For daily systems, assume slippage of 0.05–0.2% per trade depending on instrument liquidity. For futures, use realistic round-turn commissions ($2–$5 per contract). For stocks, add SEC fees and borrow costs for shorts. Model slippage as a fixed number of ticks or a percentage of ATR. If your backtest assumes fills at the exact breakout price, you are overestimating returns. A more conservative approach: enter at the next bar’s open after the signal, or at the close of the signal bar plus one tick. Test your system with doubled costs to see if it survives. If profitability disappears, the edge is too thin. Liquidity matters: avoid instruments with average daily volume below 500,000 shares or 10,000 futures contracts. Thin markets have wide spreads and erratic fills.

Psychological Discipline and Automation
Even a mathematically sound system fails if you cannot execute it consistently. Trend following is psychologically brutal: you will endure long losing streaks, give back open profits, and watch friends make money in mean-reversion strategies. The only defense is rules-based automation. Write your entry, exit, and sizing rules in exact, unambiguous terms. Then either code them into a trading platform (e.g., Python with Backtrader, TradingView Pine Script, or a broker API) or hire a developer. Automation removes fear and greed. If you must trade manually, create a checklist and follow it without exception. Keep a trading journal: log every signal, fill, and emotion. Review monthly. Do not change your system after three losses; that is normal variance. Give a new system at least 100 trades before judging it. Paper trade for 3–6 months before risking real capital. Start with small size (10% of intended risk) and scale up only after proving consistency.

Portfolio Construction and Diversification
A single trend following system on one instrument is fragile. The real power comes from trading a diversified portfolio of 20–50 uncorrelated markets. When one market trends, others may not; this smooths equity curves and reduces drawdowns. Diversification across asset classes: equity indices, interest rates, currencies, energy, metals, grains, softs, and meats. Historically, trends often appear in different sectors at different times. Rebalance your portfolio monthly or quarterly. Allocate risk equally across instruments (e.g., 0.5% risk per trade × 20 instruments = 10% total portfolio risk). Avoid doubling risk on “high conviction” trades; that is discretionary override and breaks the system. Use a correlation matrix to ensure no two instruments are >0.8 correlated. If they are, treat them as one for risk purposes. Consider adding a volatility filter: only take signals when market volatility (e.g., VIX or ATR percentile) is above a threshold. Some systems also use a trend strength filter (e.g., ADX > 25) to avoid choppy markets. But filters add parameters; test carefully.

Volatility Regimes and Adaptive Parameters
Markets alternate between trending and ranging regimes. A fixed-parameter system will suffer in ranges. Adaptive trend following adjusts parameters based on volatility or trend strength. For example, use a shorter breakout period (e.g., 20 days) when ATR is low, and a longer period (e.g., 100 days) when ATR is high. Or use a moving average that changes speed based on Kaufman’s Adaptive Moving Average (KAMA). Another approach: trade multiple systems simultaneously—one fast, one slow—and allocate capital equally. This ensemble method reduces parameter sensitivity. Volatility targeting: scale position size inversely to recent ATR so that each position contributes constant volatility. For example, if ATR doubles, halve position size. This stabilizes returns and avoids blowups during volatility spikes. Avoid over-adapting; every adaptive rule needs out-of-sample validation. A simple regime filter: only trade when the 200-day SMA slope is positive (for longs) or negative (for shorts). This avoids counter-trend disasters.

Common Pitfalls and How to Avoid Them
Pitfall 1: Over-optimization. Solution: use walk-forward analysis and limit parameters. Pitfall 2: Ignoring survivorship bias. Solution: use a database that includes delisted stocks and expired futures contracts. Pitfall 3: Assuming perfect fills. Solution: add slippage and delay entries by one bar. Pitfall 4: No stop loss. Solution: always use ATR-based or channel-based stops. Pitfall 5: Revenge trading after losses. Solution: automate and set daily loss limits. Pitfall 6: Risking too much per trade. Solution: cap at 1% and reduce after drawdowns. Pitfall 7: Trading too many correlated instruments. Solution: group by sector and limit sector risk. Pitfall 8: Abandoning the system during drawdown. Solution: pre-commit to a minimum of 100 trades or 12 months. Pitfall 9: Using too little data. Solution: require at least 200 trades in backtest. Pitfall 10: Confusing luck with skill. Solution: run Monte Carlo simulations to see the range of possible outcomes. If your backtest’s 95th percentile drawdown is 50%, you must be willing to endure that.

Execution Infrastructure and Broker Selection
For daily systems, a reliable broker with API access is sufficient. Interactive Brokers, Tradier, and Alpaca offer APIs for automated trading. For futures, use a broker that supports automated futures trading (e.g., AMP, Optimus). Ensure your broker allows the order types you need: market, limit, stop, stop-limit, and trailing stops. Avoid brokers that charge for API access or have poor uptime. Your execution code should: (a) fetch daily data after close; (b) calculate signals; (c) generate orders; (d) place orders at next open; (e) monitor stops and trailing exits; (f) log everything. Use a VPS (virtual private server) for 24/7 operation. Redundancy: have a backup internet connection and a manual override plan. For crypto, use exchange APIs with rate limits in mind. Test your execution with paper trading for at least one month. Slippage in live trading often exceeds backtest assumptions; monitor actual fills vs. expected and adjust your cost model.

Monitoring, Reporting, and Iteration
Once live, track daily: equity, open positions, risk per position, total exposure, and margin usage. Weekly: rolling 20-day Sharpe, current drawdown, and win/loss ratio. Monthly: full performance report—CAGR, max drawdown, profit factor, and comparison to benchmark (e.g., S&P 500). Use a dashboard (e.g., Grafana, Google Sheets, or Python with Plotly). Set alerts for: drawdown exceeding 15%, margin call risk, or a position stop not triggering. Do not change your system based on one month’s results. Review quarterly. If after 200 trades the system underperforms its backtest by more than 30%, investigate: data errors, execution slippage, or regime change. Only then consider a minor parameter adjustment—and re-validate out-of-sample. Keep a written log of every change and its rationale. The best trend following systems evolve slowly, not reactively.

Capital Requirements and Realistic Return Expectations
You cannot trade a diversified futures portfolio with $1,000. Minimum capital for a 20-instrument futures system is $50,000–$100,000 to properly size positions and avoid over-leverage. For ETFs, $10,000–$25,000 is workable if you trade 5–10 liquid ETFs. Realistic long-term returns: 8–15% CAGR with 20–40% maximum drawdowns. Some years will be negative (e.g., 2015, 2018 for many trend followers). The Sharpe ratio is typically 0.5–0.8. Do not expect smooth monthly returns; trend following produces lumpy equity curves—flat for months, then sharp gains. The worst drawdowns occur in choppy, mean-reverting markets (e.g., 2011–2014 for many systems). Your goal is not to beat the market every year but to provide crisis alpha: trend following often shines during prolonged bear markets (2008, 2022) when stocks fall. Combine with a stock/bond portfolio for diversification. Never use leverage beyond 2:1 notional exposure. Never risk money you cannot afford to lose. Start small, prove the system, then scale.

Advanced Techniques: Multi-Timeframe and Machine Learning
Once you have a baseline system, consider multi-timeframe confirmation: a daily trend signal confirmed by a weekly trend filter (e.g., weekly MACD > 0). This reduces false signals. Or use intraday breakouts for entry but daily trailing stops for exit. Machine learning can assist with regime classification (e.g., random forest to predict trending vs. ranging), but avoid using ML for price prediction—it overfits. Use ML only for meta-labeling: given a signal, predict whether it will be a winner or loser, and size accordingly. Or use clustering to identify market states. Keep ML models simple (logistic regression, decision trees) and validate heavily. Another advanced method: pairs trading with a trend filter—trade the spread between two correlated instruments when both are trending. Or volatility-adjusted momentum: rank instruments by risk-adjusted returns (e.g., Sharpe over 3 months) and go long the top decile, short the bottom. But remember: the more complex the system, the more likely it is to fail live. Simplicity is robust.

Legal, Tax, and Operational Considerations
If trading futures, you need a futures account and must understand margin calls, contract rolls, and 1099 tax reporting (60/40 treatment for futures). For stocks, wash sale rules apply to losses. For crypto, tax treatment varies by jurisdiction. Consult a tax professional. If managing others’ money, you may need registration as a CTA (Commodity Trading Advisor) or investment advisor. For personal trading, keep meticulous records: trade date, instrument, entry/exit, P&L, and fees. Use accounting software or a dedicated trading journal. Operational risks: broker bankruptcy (use SIPC or segregated funds), data feed failure, power outage, and software bugs. Mitigate with backups and manual kill switches. Never share your API keys. Use two-factor authentication. Test your system’s behavior during market holidays, half-days, and extreme events (e.g., flash crashes). Have a plan for when your internet dies mid-trade: call your broker. Document everything.

Final System Blueprint: A Concrete Example
Universe: 30 liquid futures (ES, NQ, CL, GC, ZB, ZN, 6E, 6J, ZC, ZS, etc.). Timeframe: daily. Entry: 50-day Donchian breakout with 200-day SMA trend filter (long only if price > 200 SMA; short only if price < 200 SMA). Stop: 3 ATR(20) below entry for longs. Trailing exit: 20-day opposite Donchian channel or 2 ATR trailing stop, whichever is tighter. Position sizing: 1% risk per trade, ATR-based. Max 10 positions, max 30% sector risk. Rebalance monthly. Backtest 2005–2025. Expected: CAGR 10–12%, max drawdown 25–35%, Sharpe 0.6, win rate 40%, profit factor 1.6. Trade 100+ times before judging. Automate with Python. Monitor weekly. Adjust nothing for 12 months. This is a profitable, robust trend following system from scratch.

advertisement

latest posts

Something went wrong. Please refresh the page and/or try again.

Discover more from DNS Research

Subscribe now to keep reading and get access to the full archive.

Continue reading