Skip to content
Wildflower
Join free
Backtesting in Python (optional)

Free Trading School · Level 7 · Course 7.5

Checking your code against a chart

Lesson 15 of 15 in Backtesting in Python (optional)Module 3: Results and checks

Advanced · Backtesting in Python

Checking your code against a chart

Wildflower Trading School · Lesson 7.5.3.5

Wildflower

You've seen how a bug can look just like a result. The last check in this course is a simple one: take a few of the code's trades and find them on a chart. By the end of this lesson, you'll know which trades to pick, what to check on each one, and the mismatches worth looking for first.

1 of 8

What you'll learn

  • Pick a few trades. Take the first, the last, a win, a loss and anything odd.
  • Match the time zone. Find each trade on a chart of the same market and time zone.
  • Check four things. Compare the signal, entry, stop and target, and exit with the chart.
  • Spot common mismatches. Rule out time zones, adjusted files, averages and entry bars.
  • Find which side is wrong. Any difference means the code or your chart reading is off.

Exercise

  1. Pick five trades from your own test: the first, the last, a win, a loss and the biggest.
  2. Find each on a chart and check the signal, the entry, the levels and the exit.
  3. Write down any difference and which side was wrong.
  4. Then try the course quiz.

Quick check

  1. 1. Which trades are worth checking by hand?

  2. 2. Every trade on the chart is a few hours off from the code. What's the likely cause?

  3. 3. The code's entry equals the signal bar's close. What does that point to?

0 of 3 answered.

Finished this lesson?

Tick it off and keep your place

Make a free account and we'll remember where you are, so “What a portfolio of strategies is” is waiting next time.

Read the full notes

To catch code mistakes, pick a few trades, find each on a chart in the same time zone, and check the signal, the entry, the stop and target, and the exit. Any difference means one side is wrong.

  • Pick a few trades: the first, the last, a win, a loss and anything odd. Find each on a chart of the same market, in the same time zone (Hand testing versus computer testing).
  • Check four things: the rule was met on the signal bar; the entry is the next bar's open; the and sit where the rule says; the exit is the first bar that touched one.
  • Made-up trade: signal 1 March (close 4,059.25 above the 4,057.51); entry 2 March at 4,051.75; risk 1.5 × 62.30 = 93.45; stop 3,958.25, target 4,238.75; 11 March low 3,962.50, 4.25 clear; exit 15 March at the stop, no gap.
  • Likely mismatches: time zone; a file against an unadjusted chart; a different indicator average or length; an entry at the signal bar's close instead of the next open ().
  • Close calls flip first when anything differs. Any difference means either the code or your reading of the chart is wrong: find out which.

Worked example

Made-up numbers

Checking the levels by hand

Made-up numbers · entry 4,051.75 · on the signal day 62.30 · stop 1.5 ATR · target 2 × risk

  1. Risk: 1.5 × 62.30 = 93.45 points
  2. Stop: 4,051.75 − 93.45 = 3,958.30, down to a : 3,958.25
  3. Target: 4,051.75 + 186.90 = 4,238.65, up to a tick: 4,238.75
  4. Both match the code.

This trade checks out. A stop 4.25 points higher would have been hit four days sooner.

Your turn

Drill

Made-up numbers · code entry 4,059.25 · chart: next bar opened 4,051.75

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.