Sometimes when adding a script to the chart in TradingView you might see the following error: “Add to Chart operation failed, reason: The script must have one study() or strategy() function call”.
This is happening because PineScript expects to see 1 study or strategy call in your script. Most likely you missed it when copied your script or accidentally delete it. Based on this function call TradingView can distinguish an indicator from a strategy for backtesting.
It’s very easy to solve that error, just add the following line at the very top of your script buy below “//@version=4”.
If you have an indicator:
study("My Script")
If you have a strategy for backtesting insert the following line:
strategy("My Script")
Follow me on TradingView and YouTube.