Why your TradingView and MT5 backtests don’t match
You converted a Pine Script strategy to MT5 and the backtest looks different. Usually nothing is broken. Here are the six reasons the platforms disagree, and how to check which ones apply to you.
It is one of the most common messages I get: “My strategy makes 80% on TradingView, the MT5 version makes 20%. Is the conversion wrong?” (The numbers vary; the question does not.) Sometimes it is. More often, both platforms are doing exactly what they were told, and they were told different things. Six differences explain almost every mismatch.
1. The data is not the same
TradingView’s feed for a symbol is not your broker’s feed. Prices differ slightly, sessions start at different times, and daily candles close at different hours depending on the server’s timezone. A strategy whose signals sit close to a threshold, such as a crossover by a fraction of a pip, will trigger on different bars.
How to check: export a few hundred bars from both platforms for the same symbol and timeframe, line them up by time and compare the closes.
2. Orders fill differently
By default, a Pine strategy fills at the next bar’s open, with no spread, commission or slippage unless you set them. An EA trades at the live bid or ask, pays the spread on every entry and exit, and slips on fast moves.
1//@version=62strategy("Fill assumptions", overlay = true,3 process_orders_on_close = false, // default: fill at NEXT bar's open4 commission_type = strategy.commission.percent,5 commission_value = 0, // default: no commission at all6 slippage = 0) // default: no slippageFor a strategy with many short trades, costs alone can turn a profitable TradingView result into a losing MT5 one. In that case MT5 is closer to the truth.
3. What happens inside a bar
When a bar touches both your stop and your target, TradingView has to guess which came first from the bar’s open, high, low and close, unless you enable the bar magnifier. MT5’s “every tick based on real ticks” mode replays the actual price path, so it knows. Strategies with tight stops and targets are most affected.
4. Repainting and look-ahead
request.security() with look-ahead switched on, used without reading the previous bar, lets a script see higher-timeframe values before they were final. The TradingView backtest then looks better than anything that could be traded live. A correct MQL5 conversion cannot see the future, so the edge “disappears”. It was never there.
5. Indicators start differently
Moving averages, RSI and other indicators need a warm-up period, and each platform seeds the first values in its own way. The first stretch of bars can disagree even with identical data. This usually only matters for short tests or long indicator periods.
6. Position models differ
Pine’s pyramiding, strategy.close() and order cancellation rules do not map one-to-one onto MT5’s hedging and netting accounts. Multiple entries, partial exits and reversals need explicit decisions in the EA, and different decisions produce different trade lists.
How to reconcile the two properly
- Align the data. Same symbol, timeframe and period, with prices compared and the timezone offset known.
- Compare indicator values, bar by bar, before comparing any trades.
- Compare trade lists, entry by entry, with costs switched off on both sides.
- Explain every difference: data, fill rule, intrabar order, look-ahead, warm-up or position model.
- Then add costs back and run MT5 on real ticks. That is the number to plan with.
If the trade lists match with costs off and diverge only when costs are added, the conversion is right and the strategy is more sensitive to costs than TradingView suggested. That is worth knowing before you trade it.