Backtest
The Backtest module (SharpTrader Optimizer) lets you test a strategy on stored historical ticks and search for the best parameter values before running it live. It works with the built-in arbitrage strategies and with your own C# bots written in the Coding module: the same strategy code runs live, in a backtest and in an optimization.
Product page and license: SharpTrader Optimizer.
Video: SharpTrader Optimizer Explained (Real Tick Backtesting & Strategy Optimization Guide 2026)
Two modes
| Mode | What it does | Use it to |
|---|---|---|
| Backtest | Runs one set of parameters over a selected date range. Shows the equity curve, every closed order (ticket, time, type, lots, price, P/L), results by direction and by hour of day. | Check a single configuration, debug strategy logic, prepare a report. |
| Optimization | Runs every combination of the parameter ranges you set (grid search) and ranks the results by PnL or drawdown. | Find stable parameter regions, compare execution-time scenarios, do walk-forward checks. |
A typical workflow: run an optimization to find candidate ranges, then backtest the best few combinations one by one and look at the shape of the equity curve and the drawdown.
Before your first backtest
- Enable tick collection for the symbols you want to test, and for their conversion pair (for example GBPUSD when you test EURGBP).
- Download candle history for the timeframes your bot uses. Without it, bars are built from ticks and indicators need time to warm up.
- In custom bots use
ticker.getTime()instead ofDateTime.Now, so the bot sees the replayed time. - Rebuild your bots in Bot management after updating SharpTrader to use the new functions.
How the simulation works
- Tick replay. The test replays stored ticks (time, bid, ask), not bar approximations. The spread is taken from each tick, so it widens and narrows the same way it did in the market.
- Execution time. You set the order execution time in milliseconds. The engine moves forward in the tick stream by half of that time (the request leg) from the moment the strategy decided to trade and fills the order at the bid/ask of that tick. The difference from the price the strategy saw is the slippage. It can be positive, negative or zero, depending on how the market moved. Open and close can have different execution times.
- Simulated broker. Market, limit and stop orders; time in force IOC, FOK, GTC and DAY (DAY orders expire at 17:00 New York time).
- Simulated account. Each session starts with a balance of 10,000. Balance and equity follow the strategy's results.
- No look-ahead. Closed bars come from the downloaded candle history; the current bar is built from the replayed ticks.
- Replayed time. The bot's clock and its log show the replayed time, not the current time.
- Currency conversion. Profits on crosses and non-USD indices are converted with historical prices: the conversion pair is replayed automatically. Results do not depend on live prices or on whether the session is connected.
- Logs. Each run shows only its own log. Log lines can be copied with the right-click menu or Ctrl+C.
Choosing the execution time
Use the round-trip time you actually see on your setup. As a rough guide: 5–20 ms for co-located institutional setups, 30–60 ms for a fast bridge VPS, 80–180 ms for a typical retail VPS, 200 ms and more for a poor connection.
Run the same parameters at 0 ms (upper limit only, not realistic), about 50 ms and about 150 ms. If the result collapses between 50 and 150 ms, the strategy is very sensitive to latency and will likely suffer from a slower broker or VPS. Never pick final parameters from a run at 0 ms.
Backtesting a custom bot
- Add your custom strategy to the Backtesting window.
- Open the strategy settings and select the symbols to test on the Backtesting tab.
- Set the date range and the execution time, then start the test.
All indicators of the bot API (IIndicators) work in backtests: trend, bands and channels, oscillators, volume and moving averages, for example Ichimoku, SuperTrend, Bollinger and Keltner bands, Parabolic SAR, Stochastic RSI, Aroon, VWAP, Hull MA and KAMA. They are fast enough to call on every tick; index 0 is the newest bar. If there are not enough bars, an indicator returns null and getLastError() explains why.
See also: Bot Code Example, AI Assistant.
Optimization
- In the settings grid, tick the parameters you want to optimize and enter Min, Step and Max for each. Parameters that are not ticked keep a single fixed value.
- Enum and true/false parameters are tested with every possible value.
- The number of combinations is shown while you edit the ranges.
- Combinations run in parallel on all CPU cores and write no logs, to save memory.
- Smart mode stops a combination early when it reaches your limits: max losing positions, max consecutive losing positions, max loss. Non-profitable combinations can be left out of the results.
- In the results, open any run to see its parameters (optimized ones are shown in bold) and apply them to your strategy in one click.
- Save parameters and Load parameters store parameter sets in files, so you can move them between live trading, backtests and optimizations.
Example: Latency Arbitrage parameters
For Latency Arbitrage the most useful parameters to optimize are Diff to open, Min profit, Pips for Min profit, Trail distance, S/L, T/P, Max Spread Slow and Max Spread Fast. The newer columns Min move, Trend interval, Cooldown and Reverse factor % can also be included. Start with coarse steps and narrow the ranges around the best region.
How long does it take
Run time grows with the number of combinations, the length of the tick history and falls with the number of CPU cores. As a reference, about 30,000 combinations on one week of XAUUSD ticks take roughly 12 hours on a 4-core CPU and about 3 hours on a 16-core CPU. For grids of 100,000+ combinations over several months of ticks use an 8–16 core machine with 32 GB RAM and an SSD.
Analysing the results
- Hour of day. Every backtest shows PnL by hour. It often turns out that most of the profit comes from a few hours (for example the London or New York open) and that some hours only lose money.
- Filters. After the run you can filter results by day of week and hour of day, by order lifetime, by number of orders and by realized slippage, without running the test again.
- Walk-forward check. Optimize on one period (for example January–March) and test the best parameters on the next one (April–June). If the best parameters change a lot between periods, the strategy is over-fitted.
Related pages
- AI Optimization – optimization of parameters on live (forward) trading.
- Latency Arbitrage, Latency Arbitrage Settings
- Coding Module description