TradingView backtester has bad reputation. For a good reason - it was producing wrong results, and it was clear at first sight how bad they were.
But this has changed. Along with many other improvements in its PineScript coding capabilities, TradingView fixed important bug, which was the main reason for miscalculations. Sometimes entry condition happened together with closing condition for the already ongoing trade. Example: the condition to close Long entry is the same as a condition to enter Short. And when these two aligned, not only a Long was closed and Short was entered (as intended), but also a second Short was entered, too!!! Whatâs even worse, that second short was not controlled with closing conditions inside strategy.exit() function and it very often lead to losses exceeding whatever was declared in âloss=â parameter. This could not have worked wellâŚ
But HOORAY!!! - it has been fixed and wonât happen anymore. So together with other improvements - TradingViewâs backtester and PineScript is now ok to work with on standard candlesticks
Yep, no need to code strategies and backtest them on other platforms anymore.
Having said the above, there are still some pitfalls remaining, which you need to be aware of and avoid:
- Donât backtest on HeikenAshi, Renko, Kagi candlesticks . They were not invented with backtesting in mind. There are still using wrong price levels for entries and therefore producing always too good backtesting results. Only standard candlesticks are reliable to backtest on.
- Donât use Trailing Stop in your code. TradingView operates only on closed candlesticks , not on tick data and because of that, backtester will always assume price has first reached its favourable extreme (so âhighâ when you are in Long trade and âlowâ when you are in Short trade) before it starts to pull back. Which is rarely the truth in reality. Therefore strategies using Trailing Stop are also producing too good backtesting results. It is especially well visible on higher timeframe strategies - for some reason your strategy manages to make gains on those huge, fat candlesticks But thatâs not reality.
- âwhen=â inside strategy.exit() does not work as you would intuitively expect. If you want to have logical condition to close your trade (for example - crossover( rsi (close,14),20)) you need to place it inside strategy.close() function. And leave StopLoss + TakeProfit conditions inside strategy.exit() function. Just as in attached code.
- If youâre working with pyramiding, add âprocess_orders_on_close=ANYâ to your strategy() script header. Default setting ("=FIFO") will first close the trade, which was opened first, not the one which was hit by Stop-Loss condidtion.