This course is optional. It's for people who want to write their own backtests in Python, a free programming language. You can skip it and still follow every other course in the Advanced level. By the end of this lesson, you'll know what Python can do that a chart's own tester can't. You'll also know what it costs to learn, and who it's worth the effort for.
1 of 9
What you'll learn
- Compare three ways to test. Hand testing, a chart tester, or your own Python code.
- Repeat the slow checks. Code reruns the Level 4 checks as often as you like.
- Count the costs. Python takes time to learn, and its bugs can look like results.
- Make your rules exact first. Code hides vague words, so sharpen them by hand.
- Bring your own strategy. Code checks rules you already have. It won't find new ones.
Exercise
- Pick one check from Level 4 that you'd like to run more times than you could by hand.
- Then read your rules and mark any word that still needs judgement.
- If you find some, sharpen them by hand before coding.
Quick check
1. What does Python let you do that's slow by hand?
2. Your rules still say 'enter when the move looks strong'. What's the better next step?
3. Why does this course end by checking code against a chart?
0 of 3 answered.
Finished this lesson?
Tick it off and keep your place
Read the full notes
A free programming language. Traders use it to write their own tests of trading rules on files of past prices.More in the glossary lets you write your own Running a strategy’s exact rules over past prices to see which trades they would have taken.More in the glossary and run the Level 4 checks thousands of times, but it costs time to learn, needs your own data, and its bugs look like results. It's worth it once your rules are exact.
- This course is optional. It's for people who want to write their own Running a strategy’s exact rules over past prices to see which trades they would have taken.More in the glossary in Python, a free programming language. Every other Advanced course works without it.
- Three ways to run the same rules over past prices: by hand with A chart feature that hides the candles after a point you choose, then shows them again one at a time, so you can practise on past prices without seeing ahead.More in the glossary and a log (Hand testing versus computer testing); a chart platform's own tester, such as TradingView's Strategy Tester running TradingView’s own programming language, used to write the indicators and strategies that run on its charts.More in the glossary; or your own Python code reading a file of prices.
- What Python adds: the Level 4 checks run as often as you like (Walk-forward testing, Shuffling trade order); tests from files for any market you have data for; every assumption visible; every trade in a table you can question.
- What it costs: time to learn; finding and checking your own data; bugs that look like results; no chart unless you check one yourself. Testing many versions still brings the many-tests problem.
- Worth it when your rules are already exact (The two-person test) and you want checks your tester can't run easily. Not yet if rules still need judgement: code hides vagueness. Code tests rules; it doesn't find a strategy. More: Systematic vs discretionary trading.
Worked example
Made-up numbersShuffling by hand versus in code
Made-up numbers · 10,000 shuffles · 5 minutes each by hand
- 10,000 × 5 = 50,000 minutes
- 50,000 ÷ 60 = about 833 hours
- At an hour an evening, that's over two years of evenings.
- In Python, the same shuffles take a few seconds.
The code takes time to learn once; after that, the slow checks become quick.
Your turn
DrillMade-up numbers · 2,000 shuffles · 6 minutes each by hand
Trading is risky. You can lose money. Test results are hypothetical, and a test can't tell you what will happen next. This lesson explains how testing works. It isn't advice.