Introduction
A trading plan without backtesting is just a guess. In this lesson you will combine the technical analysis tools (candlestick patterns, support/resistance, RSI, MACD, moving averages) and the risk management rules (position sizing, stop-loss placement, risk-to-reward ratio) covered in earlier lessons into one personal, written plan. Then you will run that plan against historical data to check whether the strategy actually holds up — before risking any real money.
Step 1 — Write Your Trading Rules in Plain Language
Before writing any code, write your entry, exit, and risk rules as a numbered list. Example ruleset for a BTC/USDT swing trade:
Rule 1 — Entry: Open a long position when RSI(14) is below 35, price closes above the 50-period EMA, and MACD histogram turns positive.
Rule 2 — Stop-loss: Place stop 2% below the entry candle's low.
Rule 3 — Take-profit: Close half at 1:2 risk-to-reward, move stop to breakeven, close the rest at 1:4.
Rule 4 — Position size: Risk no more than 1% of total account equity per trade.
Keep the list short. If a rule cannot be written in one sentence, it is too vague to code.
Step 2 — Convert Rules into Testable Code
Encode each rule as a function that returns a boolean (entry signal) or a numeric value (stop level, position size). Using Python and the backtesting library:
The function `next()` is called on every candle and represents one full decision cycle. If you can map every rule from Step 1 to a line in this function, your plan is testable.
Step 3 — Run the Backtest and Read the Output
Load historical OHLCV data and run:
The output includes key metrics: total return, max drawdown, Sharpe ratio, win rate, and number of trades. Do not chase a high return number alone. A 40% return with a 12% max drawdown is more realistic than a 200% return with a 60% drawdown.
Step 4 — Common Mistakes to Avoid
Look-ahead bias: using tomorrow's close to decide today's trade. Always shift indicators by one bar before comparing to current price.
Overfitting: tweaking parameters until the backtest is profitable. If your strategy only works with EMA length 47 on BTC 4h data from 2022, it is curve-fitted.
Ignoring fees and slippage: crypto exchanges charge 0.05–0.10% per side. A strategy with a 0.3% average win cannot survive.
Too few trades: a backtest with 8 trades over one year is statistically meaningless. Aim for at least 50–100 trades before trusting the result.
Summary
A complete trading plan is a numbered ruleset, not a feeling. Encoding those rules in code forces clarity. Backtesting reveals whether the plan is profitable, robust, and worth trading live — or whether it needs to go back to Step 1.
Next lesson will cover paper trading: executing the validated plan in real-time on a testnet account before committing capital.
Lesson Checkpoint
Review what you learned and get feedback on your work.