Backtesting and Optimization Workflow#
Writing a strategy is only the first step. Backtesting verifies whether the strategy has a historical edge, and Optimization identifies robust parameter ranges and assesses the feasibility of going live. This chapter walks through the complete validation workflow in MultiCharts, and highlights the settings most likely to cause large gaps between backtest and live performance.
| Workflow | Purpose | MultiCharts Feature |
|---|---|---|
| Backtesting | Simulate strategy orders on historical data and produce a performance report | Strategy Performance Report |
| Backtest Settings | Configure fill assumptions, commissions, slippage, Look-Inside-Bar | Strategy Properties → Properties / Backtesting tab |
| Optimization | Search for the best parameter combinations | Optimize → Exhaustive / Genetic |
| Walk-Forward | Verify robustness of optimized parameters and avoid overfitting | Walk-Forward Optimization |
Backtesting#
Backtesting means “applying a strategy to historical data and simulating the orders it would have produced.” In MultiCharts, the steps are:
- Open a Chart Window and load the instrument and resolution to test
- Compile the Signal script in Power Editor
- Add the signal to the chart with
Insert → Signal - Open
View → Strategy Performance Reportto inspect the results
Backtesting treats every bar as an established fact and re-runs the strategy’s decisions. All fill behavior is governed by the Backtest Settings.
Key Strategy Performance Report Metrics#
After opening the Strategy Performance Report, the metrics to inspect first:
| Metric | Description | Reading |
|---|---|---|
Net Profit | Total P&L (after commissions and slippage) | Must be positive and meaningfully above Buy & Hold |
Profit Factor | Gross profit / Gross loss | > 1.5 is good; < 1.2 has too thin a margin |
Max Intraday Drawdown | Largest intraday peak-to-trough equity drop (actual field name in the Strategy Performance Report) | Compare to capital — drawdowns above 30% are usually impossible to live-trade |
Total Trades | Number of trades (may also appear as Total # of Trades) | < 30 trades is statistically meaningless; aim for > 100 |
Avg Trade Net Profit | Average P&L per trade | Must be clearly larger than commission + expected slippage |
Percent Profitable (also shown as % Profitable) | Win rate | Meaningful only when paired with the Ratio Avg Win:Avg Loss |
Ratio Avg Win:Avg Loss | Average winning / losing trade | Trend strategies usually > 2; mean-reversion strategies may be < 1 |
Pitfall: Looking only at Net Profit is the most common beginner mistake. A pretty Net Profit number with only 12 trades and an Avg Trade close to the slippage amount will almost never reproduce live.
Backtest Settings (Avoiding Overstated Results)#
The single biggest source of backtest-to-live discrepancy is overly optimistic fill assumptions. In the Chart Window, right-click the signal → Format Signals, then on the Signals tab click Properties to open Strategy Properties (this applies to all signals), and walk through the settings below.
Commissions and Slippage#
In the Strategy Properties window, on the Properties tab, locate the Costs/Capitalization section:
| Field | Recommendation |
|---|---|
Commission Rule | Configured via the rule table — set your broker’s actual round-trip cost (including fees and exchange fees). E.g. ES is roughly $4–5 per contract round-trip |
Slippage | At least 1 tick; 2–3 ticks for thin markets |
The
Commissionfield is defined through a Rule table (allowing tiered calculation by contract count or notional), not a single fixed number.
Even if the strategy looks great with zero costs, adding realistic commissions and slippage often crushes the edge to near zero. Always configure costs before evaluating a strategy.
Bar Magnifier and Look-Inside-Bar#
In the Strategy Properties window, on the Backtesting tab:
| Setting | Description | When to Enable |
|---|---|---|
Use Bar Magnifier | Uses a finer resolution to simulate intra-bar price movement on the main resolution | Any strategy using Stop / Limit orders, or where multiple stops could trigger within a single bar |
Bar Magnifier Resolution | Typically 1 minute or tick | The larger the main resolution, the more important this becomes |
Without Bar Magnifier — assumed fill order
MultiCharts decides the intra-bar movement order based on whether Open is closer to High or to Low (independent of long/short direction):
- If Open is closer to Low → assumed path
Open → High → Low → Close - If Open is closer to High → assumed path
Open → Low → High → Close
Reality may be the exact opposite, causing stops that “didn’t hit” in the backtest to actually trigger live.
assumed path
Open → High → Low → Close (High hit first → target triggers)assumed path
Open → Low → High → Close (Low hit first → stop triggers)Actual live movement may be the exact opposite — within the same bar, an Open near the Low does NOT guarantee the price will rally first then fall. This is exactly why Stop/Limit strategies tend to backtest “too well” without Bar Magnifier enabled.
Stop vs Limit fill: MultiCharts assumes a Stop order fills as soon as the price is touched, but a Limit order must be crossed (penetrated) to be considered filled (just touching the limit price is not a fill). Live queue priority can cause Limit orders to remain unfilled.
Example: a daily strategy with SetStopLoss(10 * BigPointValue) and SetProfitTarget(20 * BigPointValue):
- Without Bar Magnifier: which of stop / target triggers first depends on Open’s position relative to High/Low
- With Bar Magnifier (1-minute): actual 1-minute movement determines which threshold is hit first
A common observation after enabling Bar Magnifier: a previously profitable strategy’s Net Profit gets cut in half — but this is the more honest number.
Intra-Bar Order Generation (IOG)#
In the Strategy Properties window, on the Properties tab (the same tab as Max Bars Back):
| Setting | Description |
|---|---|
Enable Intra-Bar Order Generation | Allows the strategy to place orders before the bar closes; the logic re-runs on every tick |
| Mode | When to Use | Caveat |
|---|---|---|
| IOG Off (default) | Strategy decisions only at bar close | Matches live Bar Close mode — easiest to align |
| IOG On | For tick-by-tick reactions or intraday chasing | Backtests are much slower; live trading needs OnBrokerData handling, otherwise live and backtest diverge |
Common pitfall: IOG is on, but the code doesn’t guard against repeated triggering on the same bar (e.g.
If Close > X Then Buy), so the backtest fires multiple orders on a single bar. Pair entries withMarketPositionorEntriesToday(Date)checks to avoid duplicate entries.
Maximum Bars Back#
In the Strategy Properties window, on the Properties tab:
| Setting | Description |
|---|---|
Maximum number of bars study will reference | The maximum lookback the strategy needs (e.g. Average(Close, 200) requires at least 200) |
Set it too low and the strategy doesn’t execute on early bars; too high and you waste memory. Recommendation: the largest lookback used + a 50-bar buffer.
Optimization#
Optimization tests many parameter combinations and finds the best-performing set. Right-click the signal → Format Signals → select the signal → Optimize.
Two Optimization Algorithms#
| Algorithm | Approach | When to Use |
|---|---|---|
Exhaustive | Tests every combination | First choice when combinations < 10,000; fully reproducible |
Genetic | Evolutionary approximation | Use when the search space is too large for exhaustive; result is approximate |
Example: a 3-parameter strategy with 10 values each = 1,000 combinations → use Exhaustive. A 5-parameter strategy with 20 values each = 3,200,000 combinations → must use Genetic.
Optimization Target Function#
Do not use Net Profit as the optimization target — it overfits aggressively to a few outsized winners. Better choices:
| Target | Description |
|---|---|
Profit Factor | Balances profitability and stability |
Custom Fitness Value | Build your own, e.g. NetProfit / MaxDrawdown or a Sharpe-like measure |
Result Analysis#
When the run completes, don’t simply pick the highest Net Profit row. Open the 3D chart (Optimization Report → 3D Chart) and look for:
- Parameter Plateau: ideally several adjacent parameter sets all perform well, forming a stable plateau. A single sharp peak surrounded by cliff-like drops is almost certainly overfit
- Parameter Stability: prefer a setting in the middle of the plateau, not at the very peak
Example: if MA lengths from 18 to 22 all retain at least 80% of the maximum Net Profit, picking 20 is more robust than picking the absolute peak at 19.
Walk-Forward Optimization#
Walk-Forward Optimization (WFO) is the standard tool for verifying that optimized parameters generalize to unseen data. The workflow:
[IS Training] → find best params → [OOS Validation with those params] → record OOS metrics
↓ window rolls forward
[IS Training] → find best params → [OOS Validation] → record
↓
... repeat for several runs ...- IS (In-Sample): training segment, used for parameter optimization
- OOS (Out-of-Sample): validation segment using the IS-selected parameters; this is the honest performance estimate
To launch in MultiCharts: right-click the signal → Optimize, then in the Optimization dialog locate the dedicated Walk-Forward Optimization section (a full panel with IS/OOS ratio, Anchored/Rolling, Number of Runs, etc., not just a single checkbox) and configure it there.
Key WFO Settings#
| Setting | Recommendation |
|---|---|
IS / OOS Ratio | Common ratios are 4:1 or 3:1 (e.g. 12 months IS + 3 months OOS) |
Number of Runs | At least 5 to be statistically meaningful |
Anchored vs Rolling | Rolling is the common default; Anchored is better when the market regime is stable |
Reading the WFO Report#
The headline metric is WFE (Walk-Forward Efficiency):
WFE = (OOS annualized return) / (IS annualized return)| WFE Range | Interpretation |
|---|---|
| > 0.6 | The strategy may have a real edge (the industry-standard threshold is 0.5–0.6; using 0.6 is recommended) |
| 0.3 – 0.6 | Marginal — proceed with caution |
| < 0.3 | Severe overfitting; do not trade live |
WFE close to 1.0 isn’t automatically better. WFE > 0.7 should make you double-check that the IS performance isn’t itself terrible (if both segments are bad, WFE can still be near 1.0). Always read it together with the absolute returns.
Common Pitfalls#
Look-Ahead Bias#
The strategy uses information that wasn’t available at decision time. Common sources:
| |
[1]references the previous bar’s value. CompareHighest(High, 20)andHighest(High, 20)[1]— the first includes the current bar’s high (future information), the second does not.
Overfitting#
Symptoms of overfitting:
- Optimized equity curve looks unnaturally smooth
- Parameter plateau is very narrow
- Large gap between IS and OOS performance (WFE < 0.3)
- More than 4 tunable parameters
Mitigations:
- Reduce the number of parameters (< 4 is best)
- Validate with Walk-Forward
- Verify the same parameters across multiple instruments
- Hold out a final OOS segment (the most recent 1–2 years) that never participates in optimization
Survivorship Bias#
When backtesting equities, if the data source contains only “currently listed” stocks, delisted stocks are excluded and the strategy performance is overstated. Less of an issue for futures, but stock-selection strategies must handle it explicitly.
Order Fill Assumptions#
MultiCharts assumes by default that a Stop order fills as soon as it is touched, while a Limit order must be crossed (penetrated) to fill. In reality:
- Large Limit orders may only partially fill
- Gap opens may jump entirely past Limit prices
- Stop orders in low-liquidity conditions can slip far beyond the configured amount
Mitigation: increase Slippage and enable Bar Magnifier for tick-level simulation.
Insufficient Sample Size#
Total Trades < 30 produces statistically meaningless results. Mitigations:
- Lengthen the backtest window (cover at least 2 full bull/bear cycles, ideally 5–10 years)
- Run the same strategy on multiple instruments
- Use a finer resolution (e.g. switch from daily to 60-minute)
Complete Workflow Example#
Walking through the full validation flow with a simple MA crossover strategy:
| |
Validation steps:
- Backtest settings: $5 commission, 1-tick slippage, Bar Magnifier on (1-minute), Maximum Bars Back = 100
- Single backtest: run once with default parameters; verify Total Trades > 100 and Avg Trade > slippage
- Optimize:
fastLength5–20,slowLength20–60,stopPoints5–20, target =Profit Factor - Inspect 3D chart: locate a parameter plateau, choose a center-of-plateau combination
- Walk-Forward: 12-month IS + 3-month OOS, 6 runs, require WFE > 0.6
- Multi-instrument validation: apply the same parameters to at least 2 other instruments — performance must not collapse
- Held-out OOS: the most recent 6–12 months of data must never participate in optimization; run a final validation
Only after passing every step should you consider paper trading for a period.
Notes#
Backtest and Live Will Always Differ#
Even after every check, a backtest only approximates live performance — it never equals it. Reasons include: order queue dynamics, market impact, exchange limits, network latency, and feed differences. Always validate with paper trading before going live.
Recompile and Recalculate After Changes#
After modifying a strategy, recompile in Power Editor (Compile) and right-click the signal on the chart → Recalculate, otherwise the performance report still reflects the previous version.
Optimized Parameters Decay Over Time#
Market regimes change. Re-running the optimization and WFO every 6–12 months is reasonable, but re-optimizing weekly is itself a form of overfitting.
Saving Optimization Results#
The Optimization Report can be exported as CSV for further analysis in Excel or Python (e.g. computing Sharpe, Sortino, Calmar ratios).
Reference#
https://www.multicharts.com/trading-software/index.php?title=Strategy_Performance_Report
https://www.multicharts.com/trading-software/index.php?title=Bar_Magnifier
https://www.multicharts.com/trading-software/index.php?title=Intra-Bar_Order_Generation
https://www.multicharts.com/trading-software/index.php?title=Optimization
https://www.multicharts.com/trading-software/index.php?title=Walk-Forward_Optimization