How to Fix Backtest Not Showing Any Results for a SMA Crossover Script in TradingView
Автор: vlogize
Загружено: 2025-05-21
Просмотров: 10
Описание:
Learn how to fix issues with your SMA crossover script in TradingView that prevent backtesting results from showing. Follow our step-by-step guide for troubleshooting and correcting your Pine Script code.
---
This video is based on the question https://stackoverflow.com/q/69891234/ asked by the user 'Sunil Doddapaneni' ( https://stackoverflow.com/u/7037953/ ) and on the answer https://stackoverflow.com/a/69900890/ provided by the user 'TJalam' ( https://stackoverflow.com/u/14828615/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions.
Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: Backtest not showing any results for a SMA crossover script in tradingview
Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l...
The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license.
If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com.
---
Troubleshooting: Backtest Not Showing Results in TradingView
If you're a trader using TradingView, you may encounter issues with your backtests not yielding any results, especially when it comes to implementing a Simple Moving Average (SMA) crossover strategy. This can be frustrating, particularly if you are confident in the code you’ve written. In this guide, we'll delve into a common pitfall associated with a SMA crossover script and provide a clear solution to fix the issue.
The Problem
You may have a Pine Script for a SMA crossover strategy like the one provided below. Despite having no errors during compilation, your backtest results return empty. Here’s a code snippet that represents the situation:
[[See Video to Reveal this Text or Code Snippet]]
The key issue arises with the strategy.close() line where an unknown trade ID "sell" is used incorrectly.
Analyzing the Solution
To resolve the problem and ensure that backtest results are properly displayed, follow these steps:
1. Understand the strategy.entry() and strategy.close() Functions
The strategy.entry() function requires a unique identifier for trade entries, allowing you to manage positions later. The strategy.close() function must reference an existing trade ID that was used in strategy.entry().
2. Correct the Trade ID
In the original script, the line:
[[See Video to Reveal this Text or Code Snippet]]
uses "sell" as the trade ID. However, this ID never matches any strategy.entry() call, producing no results in your backtest.
3. Update Your Code
Correct the trade ID in the strategy.close() function to ensure consistency with your strategy.entry():
[[See Video to Reveal this Text or Code Snippet]]
Complete Corrected Script
Here’s the full corrected code to ensure proper backtesting:
[[See Video to Reveal this Text or Code Snippet]]
Conclusion
By correcting the trade ID in your strategy.close() function to match the ID from your strategy.entry(), you can finally see your backtest results. Fixing this small but crucial detail can transform your Pine Script experience in TradingView from one of frustration to success.
If you are still having trouble or need further customization in your trading strategies, consider reaching out to the TradingView community forums or check out additional resources on Pine Script coding.
Happy trading!
Повторяем попытку...
Доступные форматы для скачивания:
Скачать видео
-
Информация по загрузке: