Pine Script

The Main Limitations of Pine Script on TradingView

The Main Limitations of Pine Script on TradingView

Pine Script, the scripting language used on TradingView, is a powerful tool that enables traders to develop custom indicators and strategies. However, like any programming environment, it has certain limitations that users must be aware of to maximize its effectiveness. Below, we discuss the main constraints you may encounter when working with Pine Script.

1. Time Constraints: Script Compilation and Execution

One of the most significant limitations in Pine Script is the time allowed for both script compilation and execution.

  • Compilation Time: When you save a script or add it to a chart, it must first be compiled. This process can take up to two minutes, depending on the script’s complexity and whether a cached version of the script is available. You will receive a warning if your script fails to compile within this timeframe. After three consecutive warnings, you will be temporarily banned from compiling scripts for one hour. This restriction underscores the importance of optimizing your code to avoid repetitive elements and ensure efficient execution.
  • Execution Time: After compilation, the script is executed across all bars of the dataset. The maximum time allowed for execution varies by account type: 20 seconds for basic accounts and 40 seconds for other account types. This limit requires careful consideration, especially for users using complex algorithms.

2. Plot and Drawing Object Limits

Pine Script restricts the number of plots and drawing objects (lines, boxes, polylines, and labels) a script can generate.

  • Plot Limits: Each script is limited to a maximum of 64 plots. Exceeding this number requires optimizing the code to reduce unnecessary plots.
  • Drawing Object Limits: By default, a script can display up to 50 lines, boxes, polylines, and labels on the chart. Although this limit can be increased using the max_lines_count, max_boxes_count, max_polylines_count, and max_labels_count parameters, the overall maximum IDs are capped at 500 for lines, boxes, and labels and 100 for polylines.

3. Request Calls Limits

The number of unique function calls within the request.*() namespace is limited to 40 per script. This includes functions such as request.security(), request.currency_rate(), and others. If a script calls the same function multiple times with identical arguments, only the first call counts toward this limit. However, calls within imported library functions count toward the limit, which can complicate the use of extensive libraries. This is why the maximum number of instruments in a custom screener is capped at 40.

4. Token Limits in Compiled Scripts

Pine Script is translated into a tokenized Intermediate Language (IL) during compilation, and each script’s compiled form is limited to 80,000 tokens. When a script imports libraries, the total token count from all imported libraries cannot exceed 1 million. Users may only discover they’ve exceeded the limit during compilation because there is no way to inspect the token count directly. Reducing redundant code and making efficient use of functions and libraries are crucial strategies for managing this limitation.

5. Historical Data and Bars Limitations

The number of past values you can reference using the [] operator is limited by the historical buffer, which can store a maximum of 5,000 bars. This constraint impacts the depth of historical data analysis and may require adjustments in strategy when dealing with long-term data.

Moreover, the number of historical bars available on a chart is contingent on your TradingView account type:

  • Up to 40,000 bars for the Ultimate plan.
  • Up to 30,000 bars for the Elite plan.
  • Up to 25,000 bars for the Expert plan.
  • Up to 20,000 bars for the Premium plan.
  • Up to 10,000 bars for Essential and Plus plans.
  • Up to 5,000 bars for other plans.

These limits can restrict the scope of backtesting and historical analysis, especially for users with lower-tier accounts.

6. Order Limits in Backtesting

When backtesting strategies, there is a limit of 9,000 trade orders. This limit increases significantly to 200,000 orders when using Deep Backtesting. Traders who employ complex strategies with numerous orders must be mindful of this constraint to avoid hitting the ceiling during extensive backtests.

Conclusion

While Pine Script offers robust capabilities for developing custom indicators and strategies, these limitations can influence how you design and optimize your scripts. Understanding these constraints—such as time limits for compilation and execution, plot and drawing object caps, function call restrictions, token limits, historical data availability, and backtesting order limits—is essential for making the most of Pine Script on TradingView. By optimizing your code and strategically planning your scripts, you can navigate these limitations and develop efficient, practical trading tools.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Pine Script Programming Courses
Pine Script Programming Courses
Learn to build your own TradingView Indicators and Strategies
Sidebar Signup Form
If you want to be the first in this business, subscribe to the latest news