Testing and analysis
Backtest Sensitivity Analysis: Compare Nearby Settings
Published ForeXpert team日本語で読む

Backtest sensitivity analysis measures how much your decisions and results change when you adjust a setting in a trading rule. You can check it by replaying the same historical window with an 18-bar, 20-bar, and 22-bar moving average while keeping the rest of the test fixed.
In a manual backtest, a small change in the final profit or loss can hide quite large differences in the decisions you made along the way. We compare the totals and then match the bars by timestamp to see where the decisions diverged. This guide walks through the process using an invented example you can adapt to your own notes.
What does backtest sensitivity analysis tell you?
A parameter is a value you specify in a rule, such as the number of bars used to calculate a moving average or the number of bars you wait before placing an order. A sensitivity check asks what happens to a rule when that value moves within a range you define. For manual practice, the first question can be very concrete. Which bars would have passed the filter at one setting and failed it at another?
Suppose one condition for considering a long trade is that a completed candle closes above a simple moving average. Here, the average adds up the most recent completed closes and divides by their count. Changing that count changes which closes go into the average. When price is close to the line, the new average can put the very same close on the other side of the filter.
Testing values at regular intervals is one idea behind grid search in the QuantConnect documentation. In a manual replay, a short list of nearby values gives you time to investigate individual decisions. Write down why you chose those values before running the comparison. Our guide to backtest overfitting explains what happens when you keep adding trials in response to past results.
To keep the settings fixed and examine how a shift in the test window affects your results, see how to compare backtest start dates.
Three steps for comparing settings by hand

1. Keep the test conditions and recording method fixed
Use the same currency pair, price data, timeframe, start and end times, and starting state. Keep your entry and exit rules, sizing method, and treatment of costs consistent. Load enough earlier history for the longest moving average to be defined when scoring starts. Use that earlier history to initialize the indicators and begin counting decisions at the same bar in each replay.
Write down when you check the filter and when an order first becomes eligible to fill. For example, you might check the completed candle and only consider fills from the next candle. Create columns for the bar time, close, moving average value, filter result, whether a position was already open, and what action you took. Our manual forex backtesting guide covers the basic replay workflow.
2. Change one setting at a time
Write down your baseline and nearby values before you begin. Here we use 20 bars as the baseline and 18 and 22 as the alternatives. This spacing illustrates the method. For your own review, choose a range that has a meaning for the rule you are studying and note your reason in plain language. Also decide how to handle a tie. With a strict above-the-line rule, a close exactly on the average fails the filter in all three runs.
You can practice on an iPhone with ForeXpert, which lets you display a moving average and step through historical candles one at a time. Use a separate replay for each value and keep comparison notes in a spreadsheet or notebook. Replaying the same stretch can bring later moves to mind. Write down criteria for discretionary judgments ahead of time and flag any decision where you remember what happened next.

3. Review the bars where decisions differ
Line up the observations by timestamp. For each bar where the filter differs, check whether that difference also changed an order or a fill. An eligible bar may produce no new trade if another entry condition fails or a position is already open. Keep the filter result separate from the action so you can tell where that happened.
Start with the earliest difference. Suppose the 18-bar setting alone led to an entry. If another opportunity appeared while that trade was still open, the second decision might differ even when the two moving averages agree about the second bar. The earlier trade changed the position state. Recording that sequence gives you a clearer explanation than treating every later change as a fresh signal.
Worked example with invented numbers
Suppose you mark the same 50 candidate bars in advance and record whether each close is above its moving average, regardless of whether you already hold a position. All runs share the same order and exit rules. The P&L below is in the same account currency, with a fixed trade size and costs deducted the same way in each run. Only closed trades enter the total, and the illustration assumes no positions remain open at the end. The figures are invented to demonstrate the comparison.
| Average length | Bars passing the filter | Closed trades | Net P&L after costs |
|---|---|---|---|
| 18 bars | 21 | 8 | +$24 |
| 20 bars (baseline) | 20 | 8 | +$25 |
| 22 bars | 19 | 7 | +$13 |
The first two rows differ by $1 and have eight closed trades each. Now suppose 17 bars passed the filter in both runs. That leaves four bars that passed only with 18 and three that passed only with 20. The net count differs by one, while seven individual bars changed classification. Check which of those bars produced orders and whether matched trades shared the same exit times.
The 22-bar row finishes $12 below the baseline and has one fewer closed trade. To find how much of the difference comes from that trade, compare the P&L of trades you can match and the trades that appear in only one run. Similar order times can lead to different fills or exits. If you cannot confidently pair two trades, leave their times and reasons in the notes so you can see where the sequences diverge.
Use the differences to plan the next check
Look for the circumstances in which the results diverge. If most changes come from closes hovering near the average, record a few of those bars and check how the written filter behaves at that boundary. If one large trade accounts for much of the difference in P&L, report its contribution alongside the full total. With few trades, one result can carry a lot of weight.
Keep the full set of values you tried, the common test conditions, and a few examples of decisions that changed. Then write a question for a fresh historical window, such as whether the differences still cluster around closes near the average. Set the comparison rules before opening the new window. If you add settings after seeing that window, log those runs as new exploration.
Similar results across nearby settings describe the period and range you tested. The small sample in the example gives too little evidence to rank the settings. Backtesting does not guarantee future results, and live trading carries the risk of loss.
FAQ
How many values should I try?
A baseline and one value on either side make a manageable first exercise. Three values give you a local comparison. If you expand the range, write down what you want to learn and retain each run so the record reflects the full comparison.
Are two settings equivalent if they produce the same P&L?
The same total can come from different trades, holding times, and costs. Match the decisions by timestamp first, then follow the orders and fills to see how each replay reached its result.
What if two settings interact?
Hold one fixed for the first check so you can describe what happens when the other moves. If the combination matters, plan a separate table of pairs and test every pair under the same conditions. A one-at-a-time test only tells you what happened at the fixed value.
Summary
Pick a baseline and nearby settings, fix the comparison conditions, and decide how you will record each bar. After the replay, find the earliest bar where the decisions differ and trace what happened to any order that followed. Write down one explanation you can check in a fresh period.


