# Trading strategy backtesting with walk-forward analysis

> Test your strategy bar-by-bar on real historical data with commission, spread, and slippage included, optimize parameters via grid search, and validate them out-of-sample.

- **Source (source):** https://aistohire.com/aistrading-ai-trading-signals-119/f/backtesting-trading-strategies-walk-forward
- **Platform (platform):** AIstoHire
- **Language (language):** en

## In summary

- Test your strategy bar-by-bar before risking a euro
- AisTrading reconstructs candle-by-candle what your strategy would have done on Kraken and Alpaca historical data, with commission, spread and slippage already deducted, searches for the best parameters by grid and validates them out-of-sample with walk-forward.
- Zero future information
- Costs built into each trade
- A realism switch

## Test your strategy bar-by-bar before risking a euro

AisTrading backtesting doesn't recalculate formulas over the entire series: it walks through history candle-by-candle, as the live engine would experience it. At each step your strategy only sees closed candles up to that moment (with 60 candles of warmup before starting to trade) and, if it triggers, the entry executes at the open of the next candle, never at the price you just saw. If both the stop and target are hit within the same candle, it assumes the stop: the worst case, not the one you'd hope for. That's what prevents the result from being contaminated by future information.

Costs are built in from the first trade, not estimated at the end. You define three numbers—commission per side, spread and slippage, as percentages—and the test applies half the spread and slippage at each end of the operation, with commission deducted from the result. Default values are real for each market: 0.26% commission, 0.04% spread and 0.05% slippage for crypto; 0.002%, 0.02% and 0.03% for stocks. And there's a realism switch—optimistic, realistic or pessimistic—that multiplies spread and slippage by 0.5, 1 or 2 so you can see how well your strategy holds up when the market gets expensive. When finished you get the breakdown: how much of the result was eaten by costs.

You come out with numbers, not a feeling: closed trades, wins and losses, win rate, profit factor, expectancy per trade (in money and R-multiples), best and worst trade, best and worst consecutive streaks, average duration, total result, total costs and the day-by-day equity curve. And the complete drawdown: how much, from which peak, to which trough, whether it recovered and in how many days. When the sample is small it warns you instead of presenting an 80% win rate over nine trades.

And then come the two tools that separate a test from a decision. Grid optimization sweeps through combinations of your strategy's parameters—up to 200, or 125 if you let the app build the grid itself with three parameters and five values each—and sorts them by the metric you choose: profit factor, expectancy or win rate, marking which ones have enough trades to be reliable. And walk-forward protects you from yourself: it splits history into rolling windows of training and testing (six months and two by default), optimizes on each training period and applies those parameters to the next segment, which the strategy has never seen. The number that matters is efficiency: what percentage of the profit factor you achieved by fitting survives out-of-sample. If it plummets, you've found overfitting, not a strategy.

What makes all this work is that backtesting shares the same evaluate() as the live engine: the ten included strategies and those you build with the formula editor execute with the same code, the same exit rules and the same exposure trimming. What you test is what would later trade. This functionality is part of AisTrading, a mini app by AIsToHire that you can see in full at https://aistohire.com/aistrading-ai-trading-signals-119

## What's included

- **Zero future information** — candle-by-candle walkthrough, 60 candles warmup, entry at next candle's open and stop assumed when stop and target fall within the same candle. Worst case by default.
- **Costs built into each trade** — commission per side, half spread and slippage at each end, with real crypto and stocks values by default and breakdown of how much they took from the result.
- **A realism switch** — optimistic, realistic or pessimistic multiplies spread and slippage by 0.5, 1 or 2. If your strategy only works in the friendly scenario, you'll see it in two clicks.
- **The same code as the live engine** — the backtest calls the evaluate() method of real strategies, not a reimplementation. The historical data you see is what the engine would have traded.
- **Parameter grid optimization with reliability control** — up to 200 combinations sorted by profit factor, expectancy or win rate, and each row marked as reliable only if it accumulates 20 trades or more.
- **Walk-forward with measured efficiency** — rolling training and testing windows, optimization on each segment, and a percentage that tells you how much of the fitted performance survives out-of-sample.
- **Metrics that explain risk, not just profit** — expectancy in R, profit factor, total costs, best and worst streaks, and a drawdown with dates of peak, trough and recovery.
- **Your history, your way** — 5-minute, 15-minute, 1-hour or 1-day candles, from 30 to 365 days from the app (up to 730 via API) and up to 30 symbols per test, with explicit warning when the sample is too short.

## Frequently Asked Questions

### Does the backtest account for commissions and slippage?

Yes, and within each trade, not as a final deduction. You define commission per side, spread, and slippage as percentages; the test applies half the spread and slippage at entry and exit, and subtracts the commission from the result. By default it uses 0.26% commission, 0.04% spread, and 0.05% slippage for cryptocurrencies, and 0.002%, 0.02%, and 0.03% for stocks. The result includes total costs so you can see how much they've taken, and a realism mode that multiplies spread and slippage by 0.5, 1, or 2.

### How do I know if my strategy is overfitted to historical data?

That's what walk-forward is for. It splits the historical data into rolling training and testing windows (six months of training and two months of testing by default), optimizes parameters on each training segment and applies them to the following segment, which the strategy hasn't seen. At the end it gives you an efficiency: the percentage of in-sample profit factor that holds up out-of-sample. High efficiency indicates the parameters hold up; low efficiency is the sign that you've fitted to the past and not to a rule.

### Where does the historical data come from and how far back does it go?

From the same providers the live app uses: candles from Kraken for cryptocurrencies and from Alpaca for U.S. stocks. You choose the timeframe (5 minutes, 15 minutes, 1 hour, or 1 day), the period (30, 90, 180, or 365 days from the app; up to 730 via API), and up to 30 symbols per test. A symbol needs at least 80 candles in the range to appear in the results. If a symbol doesn't have enough real historical data available, the backend fills it with a deterministic synthetic series so the test doesn't break—keep this in mind when interpreting illiquid or newly listed symbols.

### Will the backtest results match what the engine actually does?

Yes, because it's the same code. The backtest invokes the evaluate() method of the same strategies the live engine executes—the ten built-in ones and those you build with the formula mini-language—and replicates their exit rules, limit entries, and position sizing by maximum exposure. There's no parallel reimplementation that could drift, which is the most common reason a backtest promises what then doesn't happen.

### What doesn't AisTrading backtesting do?

It's important to know before using it. It only simulates long positions: no short positions. It maintains at most one open position per symbol and walks through symbols sequentially, so it doesn't simulate a portfolio with multiple concurrent positions. Spread and slippage are fixed percentages, not a function of volume or order size, and there's no market impact, funding costs, dividends, or taxes. The equity curve updates when each trade closes, so drawdown doesn't reflect adverse excursion within an open trade. It also doesn't calculate Sharpe or Sortino in the backtest: those metrics are in the real trade history. Optimization and walk-forward require the advanced app tier.

- [AisTrading — AI Trading Signals Explained](https://aistohire.com/aistrading-ai-trading-signals-119)

## About the platform

**AisTrading — AI Trading Signals Explained** — an app by AIstoHire. Available at: https://aistohire.com/aistrading-ai-trading-signals-119/f/backtesting-trading-strategies-walk-forward

### Other languages

- `es`: https://aistohire.com/es/aistrading-senales-trading-ia-119/f/backtesting-estrategias-trading-walk-forward
- `fr`: https://aistohire.com/fr/aistrading-signaux-trading-ia-119/f/backtesting-strategies-trading-walk-forward
- `it`: https://aistohire.com/it/aistrading-segnali-trading-ia-119/f/backtesting-strategie-trading-walk-forward
- `pt`: https://aistohire.com/pt/aistrading-sinais-trading-ia-119/f/backtesting-estrategias-trading-walk-forward
- `de`: https://aistohire.com/de/aistrading-ki-handelssignale-119/f/backtesting-trading-strategien-walk-forward
- `bg`: https://aistohire.com/bg/aistrading-targovski-signali-s-ii-za-aktsii-i-kripto-119/f/backtesting-na-targovski-strategii-walk-forward
- `ja`: https://aistohire.com/ja/ai-trading-signal-119/f/backtest-walk-forward-trade-senryaku
- `nl`: https://aistohire.com/nl/aistrading-tradingsignalen-met-ai-voor-aandelen-en-crypto-119/f/backtesting-tradingstrategieen-walk-forward
- `ko`: https://aistohire.com/ko/aistrading-ai-trading-signal-119/f/teureiding-jeollyak-baektesteu-wokeupowodeu
- `sv`: https://aistohire.com/sv/aistrading-tradingsignaler-med-ai-for-aktier-och-krypto-119/f/backtesting-tradingstrategier-walk-forward
- `da`: https://aistohire.com/da/aistrading-tradingsignaler-med-ai-til-aktier-og-krypto-119/f/backtesting-tradingstrategier-walk-forward
- `ar`: https://aistohire.com/ar/aistrading-isharat-tdaul-baldhka-alastnaai-llashm-walamlat-almshfra-119/f/trading-strategy-backtesting-walk-forward
- `no`: https://aistohire.com/no/aistrading-tradingsignaler-med-ki-for-aksjer-og-krypto-119/f/backtesting-tradingstrategier-walk-forward
- `fi`: https://aistohire.com/fi/aistrading-tekoalyn-treidaussignaalit-osakkeille-ja-kryptoille-119/f/kaupankaynti-strategian-backtesting-walk-forward
- `zh`: https://aistohire.com/zh/aistrading-ai-trading-signals-119/f/jiaoyi-celue-huice-walk-forward
- `pl`: https://aistohire.com/pl/aistrading-sygnaly-tradingowe-z-ai-dla-akcji-i-krypto-119/f/backtesting-strategii-tradingowych-walk-forward
- `he`: https://aistohire.com/he/aistrading-aitoti-mschr-bbinh-mlakotit-lmniot-vkripto-119/f/backtesting-estrategiot-miskhar-walk-forward
- `cs`: https://aistohire.com/cs/aistrading-obchodni-signaly-s-ai-pro-akcie-a-krypto-119/f/backtesting-obchodnich-strategii-walk-forward
- `id`: https://aistohire.com/id/aistrading-sinyal-trading-ai-untuk-saham-dan-kripto-119/f/backtesting-strategi-trading-walk-forward
