Why your TradingView and MetaTrader 5 backtests do not match
Bar-based versus tick-based simulation, spreads, data feeds and fill rules: what causes differences and which ones you can reduce.
Different data
TradingView and your MetaTrader broker use different price feeds. Highs, lows and even session start times can differ, especially on forex and CFDs, so an indicator cross can happen one bar earlier or later. Before comparing strategy results, compare a plain moving average on both charts for the same dates.
Different simulation
The TradingView broker emulator works from bar OHLC data (unless you enable bar magnifier on supported plans) and assumes an intrabar path. The MT5 Strategy Tester offers several modes: "Every tick based on real ticks", "Every tick" (generated), "1 minute OHLC" and "Open prices only". Stops and targets hit inside a bar can resolve differently in each mode.
For a strategy that decides only on closed bars, "Open prices only" is fast and close to the Pine default. For anything using intrabar stops, use real ticks where your broker provides them.
Costs and fills
Pine strategies ignore spread and commission unless you set them. MT5 uses the broker spread (fixed or recorded) and the commission from the symbol settings. Set commission and slippage in the Pine strategy() call so both tests include similar costs.
Pine Script
//@version=5
strategy("Costed", overlay=true, commission_type=strategy.commission.cash_per_contract, commission_value=3.5, slippage=2)What a fair comparison looks like
Same symbol, same timeframe, same date range, similar costs, and a trade-by-trade list rather than only net profit. Expect entry dates to match closely and prices to differ by a few points. Large differences in the number of trades point to logic or indexing errors, not to data. Remember that neither backtest predicts future results.