Build a better understanding and set correct expectations of what you can and can’t do with TradingView’s Pine Script.
In this article I present to the reader a common concern from one of my students about the flexibility and usability of Pine Script. This is a concern for many and thus, I have decided to dedicate a precious portion of my time compiling; to the best of my knowledge, a comprehensive compendium of the limitations and abilities of Pine Script.
“Not sure I like the low LIMIT numbers for charts, alerts, script size or memory, and that may be the real “gorilla in the room” problem. Maybe a larger more robust general language would not have these problems. Also, Pine Script appears very limiting when it comes to Algo Trading for “Stocks” (not FOREX). A Python-Interactive Brokers or MATLAB-IB is more general and non-chart based. Another question could be: Is Pine Script just a charting tool with some “bells-and-whistles” which you have to pay $20-30 / month to use”Concerned Student
Disclaimer: My statements herein are of my own opinion. I am partially biased because I offer services with Pine Script. But I am completely independent of TV and PS and have not been paid for my comments here. If someone wants to pay me that would be nice 🙂
First off, every language and platform that you work with will inherently have some trade-offs. Pine Script has limitations, but these are not as crippling as you might expect, unless you fit into some specific categories that I will outline below. Secondly, Pine Script is free. You would only pay $10-$50 a month if you have specific use cases. Also, outlined below.
Now, there’s two things we need to look at in order to gain a realistic expectation of Pine Scripts capabilities.
TradingView itself. And Pine Script.
The biggest downside to Pine Script (PS) is that you must use TradingView (TV). The upside to that statement, is that TV is an excellent charting platform… in my humble opinion.
Over the course of this article I will not cover TV in its entirety, but TV in a limited scope with a focus on Pine Script.
If TV is new to you, I would highly recommend just checking out their platform and using it for a while before you decide if you want to learn how to program in the dedicated ecosystem. *Note: Even though, PS only works on TV it can still be externally applied through the use of webhooks, SMS, and email messages, which can then be parsed and interpreted by any other language/platform.
If you haven’t signed up for a TV account yet, let me plug this ref link. (We both get $30.)
General Pros and Cons Of TradingView and Pine Script
Before we dive into the intricacies of TV and PS, I want to give a brief overview of TV and PS so you can make a quick judgement if this is right for you or not. That way you don’t have to waste anymore time reading this ostentatiously worded article. I like words, I won’t apologize, I also like when people get straight to the point. Life is a struggle, surprise?
Pros & Cons of TradingView
|Freemium Model, with lots of features in the free version.||Lacking Statistical Charting Capabilities (bar charts, pie charts)|
|Beautiful Charts.||Order book/ L2 data is basic.|
|Massive community/ Widely Used||No Buy/Sell Volume Data* (Included as a paid indicator, but unavailable for PS)|
|Access to a Large variety of data feeds||No Automated order execution.|
|Cloud Based||Cloud Based|
|Desktop/Mobile Friendly||Not Ideal for options/futures analysis.|
|Built in paper trading|
|Built in backtesting/forward testing|
|Built in Live Trading|
Pros & Cons of TradingView Summary
TV is the best charting platform out there, with excellent tools for advanced technical and fundamental analysis. However, it’s a little lacking when it comes to displaying anything other than a standard price chart. Pricing options/futures can be done thanks to PS, but it is not intuitively integrated into the system design. Order book data is available, but only if you connect to a broker. This platform is built for charting and ease of use. It is a very good place to start. I continue to use it to this day.
Pros and Cons of Pine Script
|Advanced technical and fundamental analysis.||Cloud based Domain Specific Language.|
|Easy to use.||Tick data not available for backtesting.|
|Very quick to implement.||L2 NOT accessible through Pine Script.|
|Widely used, growing in popularity and constantly being updated with new features every month.||Built-in Automated Trading Unavailable, but may be possible in the future. Automated trading is still possible through third party workarounds.|
|Free||Cannot import alternative datasets|
Pros and Cons of Pine Script Summary
Pine Script is a beginner friendly time series scripting language with advanced capabilities, built into the TradingView ecosystem. It will run on any available chart found on TradingView.
Every indicator on TradingView is built with PS *with the exception of volume based indicators. However, there have been implementations of volume based indicators built with PS.
This language is good for:
- Traders who already use indicators on TradingView and would like to improve or build one for themselves.
- Anyone looking to get a quick start in programming for finance.
- Traders that want to backtest and forwardtest different ideas and strategies without wasting time.
- Automating Mean reversion strategies, trend following strategies, advanced technical analysis, quantifying fundamental analysis and similar high level quantitative analysis not involving extensive CPU usage.
This language may not be for you if:
- You are looking to build a Market Making Bot.
- You understand ML/AI and want to apply that to Finance.
- You want to program a HFT strategy.
- You specifically need to work with order book data, buy/sell volume or tick data.
A Closer look…
If you still think the TV/PS ecosystem will fit your needs then continue reading for a closer look at the limitations you will be confined to.
Technical Limitations of TradingView
TradingView is a subscription cloud service with a freemium membership model.
There are 4 tiers which fit the needs of most; Basic, Pro, Pro+ and Premium. However, I won’t go over them in detail because you can view them here.
Most of the time you can get away using the Basic tier, which is absolutely FREE. I use this tier 90% of the time. The only major limiting factor is that you cannot use webhooks in this tier, also backtesting historical data is somewhat limited.
Some people might grope at the fact that you only can have 3 indicators or that you can only set up 1 alert with the Basic subscription, but if you know Pine Script well or just watch a few free videos of mine, you can build ONE indicator that runs your entire strategy across 40 different assets with full alerts on each asset; so this isn’t really an issue. And honestly, if I really wanted to bootstrap an automated strategy that didn’t need to be low latency, I could just as easily build an email parser and utilize email alert based signals.
That being said, if you’re lazy like me you’ll probably want to upgrade to the pro version for $90 a year to make your life easier if you decide you want to fully automate order execution.
Overall though, I’m very content with the free version and might just build an open source email parser that people can use for automated trading if enough people continue to support my work.
Technical Limitations of Pine Script.
This information has been cited from the PineCoders website. I have not verified all of these limitations, some may be outdated as the website is not an official source.
- The limit for plots is 64. Note that one plot statement can use up more than one allowed plot, depending on how it is structured. If you use a color of any form that is not of “const” form on the plot or text, each one will add a plot count. Starting with Pine v4, alertcondition() calls also count for one plot. All plotting functions count for at least one plot, except hline() calls which do not count as a plot. Some plotting functions such as plotcandle() count as 4 plots, 5 if you use series color on the body.
- The limit for lines and labels created with label.new() and line.new() is 500 each.
- The limit for security() calls is 40, but by using functions returning tuples with security(), you can fetch many more values than 40.
- The limit for variables is 1000.
- The limit for the number of lines in a script is unknown. However there is a limit of 50K compiled tokens, but they don’t correspond to code lines.
- Runtime Limitations occur if your script takes longer than 40 seconds to compile on a premium account and 20 seconds on a basic account.
- Backtest Data limitations allow for up to 20k historical bars on a premium account with up to 5k on a basic account
Anecdotally, I have rarely been thwarted by these limitations in my years working with pine script. It does happen though and often can be resolved by improving the way you write the code. So in a way it makes you a better programmer :). On a final note, I am a bit disappointed with the Backtest data limitations for free accounts. Sometimes 5k historical bars is not enough if you have a slow strategy. That being said, I am in the process of building a Pine Script study that will overcome this limitation, making freedom even more free! 🙂
Comparisons against other languages
There are sooooo many other options out there when it comes to programming/scripting languages. I would love to make a complete comparison of each and every one, but that’s too much work for me. So I’m just going to give you my general breakdown based on what I have worked with or touched upon. Unfortunately, I’ve never worked with Interactive Brokers so I can’t comment on that.
|Name of Language||Platform||Type of Language||HFT||Stocks||Crypto||Forex||ML/AI||Market Making||Ease of Use||Support||Notes|
|Think Script||ThinkorSwim||Domain Specific.||Unknown||Unknown||Unknown||Unknown||Unknown||Unknown||4||Unknown|
|MQL||Metatrader||Domain Specific. Similar to C++||4||1||3||5||2||1||2||5||Good for Forex.|
|ACSIL||Sierra Charts||Domain Specific. Similar to C++||4||Unknown||Unknown||Unknown||Unknown||Unknown||2||1||No Support.|
|Python||MacOs, Linux, Windows, and more.||General Programming Language||3||3||4||2||5||4||3||5||Must build and maintain entire infrastructure|
|C++||MacOs, Linux, Windows, and more.||General Programming Language||5||3||4||2||4||5||2||5||Must build and maintain entire infrastructure|
The future of Pine Script
Pine Script is still a new language (roughly 8 years old at the time of this writing 2021), but it has come a long way and is growing in popularity. I started out using MQL and bounced between Pine Script and Python mostly. But over the years, as Pine Script has evolved I have chosen PS more and more for building financial applications. As of October 2020 Pine Script boasts:
- Over 100,000+ carefully curated public and paid scripts.
- 5 million script instances running on charts at any given time.
- 1.5 million server-side alerts running 24×7.
- 120 million updates per minute on 600 thousand tickers.
A Final Note
As a final note. Try not to do what I did and waste a bunch of time bouncing between programming languages looking for the perfect one. A lot of people, like myself, got hung up on tick data or speed constraints, but those things don’t really matter unless you specifically know you need them. And if you’re not sure, you probably don’t need them. Cheers!