Build and backtest a setup

Turn a chart idea into written rules for the trend, the area, the trigger, the stop and the target, then test those rules on past data honestly: enough trades, no hindsight and no changing the rules halfway. Gold and EUR/USD examples.

TA 4: Pro Lesson 1 of 4 · 4 min read

⚠️ Risk warning: CFDs and leveraged forex are complex instruments with a high risk of losing money rapidly. Most retail accounts lose money. This content is education only, not investment advice or a recommendation.

Gold H4: four trades from one written rule, logged in R3,8963,9333,969XAU/USD · H4EMA 201 · +2R2 · −1R3 · +2R4 · −1ROne written rule, four trades: +2 − 1 + 2 − 1 = +2R. Far too few trades to judge. Illustrative prices.
Gold H4: four trades from one written rule, logged in R Illustrative chart: drawn data, not real prices.

A setup is a trade idea written as rules that another person could follow and get the same trades. "Buy strong pullbacks" is not a setup. "On H4, when price is above a rising EMA 20, buy the first candle that closes back above the previous candle’s high after touching the EMA, with the stop below the pullback low" is. Rules are what make an idea testable.

The five parts of a setup

  • Context: the market, the timeframe and the trend condition (for example price above a rising EMA 20, or higher highs and higher lows on the timeframe above).
  • Area: where the trade may happen (a moving average, a flipped level, a demand zone).
  • Trigger: the exact event that opens the trade, judged on closed candles.
  • Stop: where the idea is wrong, usually just beyond the pullback low or high.
  • Exit: a target in R (multiples of the risk), a trailing rule or a time limit, decided in advance.

Backtesting without fooling yourself

  • Write the rules first, then go through the chart from left to right. Use the bar replay tool in TradingView or the strategy tester in MT5 so you cannot see the future candles.
  • Log every trade the rules give you, including the ugly ones, in R: a loss at the stop is −1R, a win at a 2R target is +2R.
  • Collect enough trades. A handful of trades says almost nothing; luck dominates small samples. Test across different conditions: trends, ranges and volatile news periods.
  • Do not change the rules mid-test. If you want to change a rule, start a new test, and check it on a period you did not use to design it (see overfitting).
  • Include costs: spread, commission and swap. A setup that only works before costs does not work.
Worked example: gold (XAU/USD), H4. The figure uses drawn prices. The rule: price above a rising EMA 20, pullback to the EMA, buy on a close back above the previous candle’s high, stop below the pullback low, target 2R. In this stretch the rule gives four trades: the first reaches 2R, the second is stopped at −1R, the third reaches 2R and the fourth is stopped at −1R. That is +2 − 1 + 2 − 1, a total of +2R. Four trades are far too few to judge anything; they only show how to log the results. A real test needs many more trades across different market conditions, and past results do not guarantee future ones.

Common mistakes

  • Skipping trades in the test that "you would not have taken". In real time you would not have known.
  • Looking ahead: deciding an entry with candles that had not closed yet.
  • Judging the setup on one good month instead of a long, varied sample.

This lesson is educational. A backtest describes how rules behaved on past data; it does not predict future results.

🛠️ Practice task

Use a real chart. This is for practice, not for placing a trade.

  1. Write a setup in five lines: context, area, trigger, stop and exit. Keep it on gold H4 or EUR/USD H1.
  2. Open the chart in TradingView, go back at least six months and start bar replay. You can check the live gold price on the Invvex gold page.
  3. Step forward one candle at a time. Log every trade the rules give you: date, entry, stop, exit and result in R.
  4. Do not change any rule during the test. Write ideas for changes in a separate list.
  5. At the end, write down the number of trades, the total in R and the largest run of losses. Then ask: is this enough trades to mean anything?

🎯 Mark this chart

Study the drawing, pick the letter, then check. This exercise does not count toward your progress; the quiz below does.

EUR/USD H1: find the candle that breaks the rule1.10091.10431.1076EUR/USD · H1EMA 20ABCD
EUR/USD H1: find the candle that breaks the rule Illustrative chart: drawn data, not real prices.
EUR/USD, H1. The rule is: buy only when price is above a rising EMA 20 and pulls back to it. Which marked candle does NOT meet the rule?

Show answer

C. At C, price has fallen below the EMA 20 and the EMA is turning down, so the context rule fails. A, B and D are pullbacks to a rising EMA with price above it. A backtest that includes C is testing a different rule.

EUR/USD H1: find the candle that breaks the rule1.10091.10431.1076EUR/USD · H1EMA 20ABCD✓ Below a falling EMA
Solved: C, below a falling EMA 20 Illustrative chart: drawn data, not real prices.

✍️ Quick quiz

Check what you learned. Your answers stay in this browser.

1. Which of these is a testable setup?

Show answer

Above a rising EMA 20 on H4, buy the close back above the previous high after touching the EMA, stop below the pullback low. Only the second can be followed the same way by anyone, so only it can be tested.

2. A trade hits its stop. A winning trade reaches a 2R target. How do you log them?

Show answer

−1R and +2R. Logging in R makes trades with different stop sizes comparable.

3. Why use bar replay or the strategy tester?

Show answer

So you cannot see the candles that come after the decision. Seeing the future makes every entry look obvious and inflates the results.

4. Halfway through a test you change the stop rule because of a few losses. What should you do?

Show answer

Start a new test with the new rule and check it on fresh data. Mixing rules in one test, or fitting rules to the trades you just saw, makes the result meaningless.