Python Tradingview Ta Readthedocs Io en Latest
Python Tradingview Ta Readthedocs Io en Latest
deathlyface (Brian)
1 Getting Started 3
1.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3 Quick Start . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Usage 5
2.1 Importing TradingView_TA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2 Checking the version . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Instantiating TA_Handler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.4 Retrieving the analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.5 Retrieving multiple analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.6 Symbol search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.7 Proxy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Changelog 11
3.1 3.3.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.2 3.2.10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 3.2.9 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.4 3.2.8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.5 3.2.7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.6 3.2.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.7 3.2.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.8 3.2.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.9 3.2.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.10 3.2.2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.11 3.2.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.12 3.2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.13 3.1.6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.14 3.1.5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.15 3.1.4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.16 3.1.3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
3.17 3.1.1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.18 3.1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.19 3.0.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.20 2.5.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.21 2.2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.22 2.1.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
i
3.23 2.0.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
4 FAQ 15
4.1 Is the data delayed? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 How do I get past data? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.3 How do I create a trading bot? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.4 How can I get involved? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
4.5 How does TradingView_TA works? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.6 Why do I get 4XX error? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
ii
python-tradingview-ta Documentation
TradingView_TA is an unofficial Python API wrapper to retrieve technical analysis from TradingView.
This documentation will help you to understand and use TradingView-TA.
Contents 1
python-tradingview-ta Documentation
2 Contents
CHAPTER 1
Getting Started
This guide will help you understand the basics of TradingView_TA package.
1.1 Requirements
1.2 Installation
tesla = TA_Handler(
symbol="TSLA",
screener="america",
exchange="NASDAQ",
interval=Interval.INTERVAL_1_DAY
)
print(tesla.get_analysis().summary)
# Example output: {"RECOMMENDATION": "BUY", "BUY": 8, "NEUTRAL": 6, "SELL": 3}
3
python-tradingview-ta Documentation
Usage
Note: Please install or update TradingView_TA to the latest version. Please read the getting started guide before
continuing.
Warning: TradingView_TA older than v3.2.0 is no longer supported. Please update using pip install
tradingview_ta --upgrade.
Starting from version 3.1.3, you can retrieve the version of TradingView_TA through the __version__ attribute.
print(tradingview_ta.__version__)
# Example output: 3.1.3
handler = TA_Handler(
symbol="",
(continues on next page)
5
python-tradingview-ta Documentation
Parameters:
Tip: You can search on https://tvdb.brianthe.dev to see which symbol, exchange, and screener to use.
Note:
– If you’re looking for stocks, enter the exchange’s country as the screener.
– If you’re looking for cryptocurrency, enter "crypto" as the screener.
6 Chapter 2. Usage
python-tradingview-ta Documentation
class Interval:
INTERVAL_1_MINUTE = "1m"
INTERVAL_5_MINUTES = "5m"
INTERVAL_15_MINUTES = "15m"
INTERVAL_30_MINUTES = "30m"
INTERVAL_1_HOUR = "1h"
INTERVAL_2_HOURS = "2h"
INTERVAL_4_HOURS = "4h"
INTERVAL_1_DAY = "1d"
INTERVAL_1_WEEK = "1W"
INTERVAL_1_MONTH = "1M"
• timeout (float, optional) – How long to wait (in seconds) for the server to return a response.
analysis = handler.get_analysis()
Note: analysis is an instance of Analysis class. It contains information such as the exchange, symbol, screener,
interval, local time (datetime.datetime), etc.
Attributes:
• symbol (str) – The symbol set earlier.
• exchange (str) – The exchange set earlier.
• screener (str) – The screener set earlier.
• interval (str) – The interval set earlier.
• time (datetime.datetime) – The time when the data is retrieved.
• summary (dict) – Technical analysis (based on both oscillators and moving averages).
# Example
{'RECOMMENDATION': 'BUY', 'BUY': 12, 'SELL': 7, 'NEUTRAL': 9}
# Example
{'RECOMMENDATION': 'BUY', 'BUY': 2, 'SELL': 1, 'NEUTRAL': 8, 'COMPUTE': {
˓→'RSI': 'NEUTRAL', 'STOCH.K': 'NEUTRAL', 'CCI': 'NEUTRAL', 'ADX':
# Example
{'RECOMMENDATION': 'BUY', 'BUY': 9, 'SELL': 5, 'NEUTRAL': 1, 'COMPUTE': {
˓→'EMA10': 'SELL', 'SMA10': 'SELL', 'EMA20': 'SELL', 'SMA20': 'SELL',
# Example
{'Recommend.Other': 0, 'Recommend.All': 0.26666667, 'Recommend.MA': 0.
˓→53333333, 'RSI': 60.28037412, 'RSI[1]': 58.58364778, 'Stoch.K': 73.
8 Chapter 2. Usage
python-tradingview-ta Documentation
Parameters:
• symbols (list) – List of exchange and ticker symbol separated by a colon. Example: [“NASDAQ:TSLA”,
“NYSE:DOCN”] or [“BINANCE:BTCUSDT”, “BITSTAMP:ETHUSD”].
• screener (str) – Screener (e.g., "america", "indonesia", "forex", "crypto").
• timeout (float, optional) – How long to wait (in seconds) for the server to return a response.
• additional_indicators (list, optional) – List of additional indicators to retrieve. Example: ["RSI",
"Mom"].
• interval (str) – Time frame
class Interval:
INTERVAL_1_MINUTE = "1m"
INTERVAL_5_MINUTES = "5m"
INTERVAL_15_MINUTES = "15m"
INTERVAL_30_MINUTES = "30m"
INTERVAL_1_HOUR = "1h"
INTERVAL_2_HOURS = "2h"
INTERVAL_4_HOURS = "4h"
INTERVAL_1_DAY = "1d"
INTERVAL_1_WEEK = "1W"
INTERVAL_1_MONTH = "1M"
# Example
{'NYSE:DOCN': <tradingview_ta.main.Analysis object at 0x7f3a5ba49be0>, 'NASDAQ:TSLA':
˓→<tradingview_ta.main.Analysis object at 0x7f3a5ba65040>, 'NASDAQ:AAPL':
# Example
{'BINANCE:DEXEUSDT': None, 'BINANCE:BTCUSDT': <tradingview_ta.main.Analysis object at
˓→0x7f3561cdeb20>}
Note: While symbols listed on https://tvdb.brianthe.dev are guaranteed to work with the “get analysis()” function,
symbols returned by this function may not.
Parameters:
• text (str) – Query string.
• type (str, optional) – Type of asset (stock, crypto, futures, index). Defaults to None (all).
2.7 Proxy
Simply add the proxies parameter if you wish to utilize a proxy. Works with both TA_Handler() and
get_multiple_analysis(). It’s worth noting that a bad proxy could result in TradingView rejecting your
request.
10 Chapter 2. Usage
CHAPTER 3
Changelog
3.1 3.3.0
New:
• Symbol search
3.2 3.2.10
New:
• Support for proxy
• Additional indicators support for get_multiple_analysis()
3.3 3.2.9
New:
• Interval: 30 minutes and 2 hours
3.4 3.2.8
New:
• Indicators: change, low, high
11
python-tradingview-ta Documentation
3.5 3.2.7
Bug fix:
• get_multiple_analysis() will now return None if there is no analysis for a certain symbol. See #55
for more details.
3.6 3.2.6
Bug fix:
• Add indicators
• Get multiple analysis
3.7 3.2.5
New:
• Retrieve indicators TA_Handler.get_indicators()
• Add custom indicators TA_Handler.add_indicators()
• Indicators: volume
Bug fix:
• Update RSI algorithms
3.8 3.2.4
New:
• Retrieve multiple analysis
Bug fix:
• Update compute algorithms
3.9 3.2.3
New:
• Timeout
• Indicators: BBUpper and BBLower
• Test script (test.py)
12 Chapter 3. Changelog
python-tradingview-ta Documentation
3.10 3.2.2
New:
• Indicators: open and P.SAR
3.11 3.2.1
New:
• Removed EMA5 and SMA5 from analysis
Bug fix:
• Switched buy/sell on momentum
3.12 3.2.0
New:
• Instantiate TA_Handler using parameters
3.13 3.1.6
New:
• Set interval to "1d" if invalid
3.14 3.1.5
New:
• Move indicators to Analysis class
3.15 3.1.4
Bug fix:
• Pull request #19
3.16 3.1.3
New:
• Added user agent
• Added __version__ attribute
3.10. 3.2.2 13
python-tradingview-ta Documentation
3.17 3.1.1
Bug fix:
• Pull request #7
3.18 3.1.0
New:
• Set symbol/exchange/screener/interval using functions
3.19 3.0.0
New:
• Use scanner (https://scanner.tradingview.com/america/scan) instead of selenium
• Indicators
3.20 2.5.0
New:
• Support for Heroku
3.21 2.2.0
New:
• Rename pair to symbol
• Support for Python 3.4
• Added warnings
3.22 2.1.0
Bug fix:
• Requirements
3.23 2.0.0
New:
• Use class
• Use headless selenium webdriver
14 Chapter 3. Changelog
CHAPTER 4
FAQ
Note: TradingView_TA does not support paid real-time data at the moment.
Note: Please refer to TradingView’s website to see whether the data is delayed or not.
Warning: Trading (especially using bots) is very risky. I won’t be responsible for any financial loss. You have
been warned.
The pseudocode below should help you get started in creating your own trading bot.
15
python-tradingview-ta Documentation
# Import packages.
from tradingview_ta import TA_Handler, Interval, Exchange
import time
# Instantiate TA_Handler.
handler = TA_Handler(
symbol="SYMBOL",
exchange="EXCHANGE",
screener="SCREENER",
interval="INTERVAL",
)
# Repeat forever.
while True:
# Retrieve recommendation.
rec = handler.get_analysis()["RECOMMENDATION"]
# Create a buy order if the recommendation is "BUY" or "STRONG_BUY" and the last
˓→order is "sell".
# Create a sell order if the recommendation is "SELL" or "STRONG_SELL" and the
˓→last order is "buy".
last_order = "buy"
elif "SELL" in rec and last_order == "buy":
# REPLACE COMMENT: Create a sell order using your exchange's API.
last_order = "sell"
Warning: last_order won’t be saved when the program exit. When the bot restarts, it will always create a
new buy order.
16 Chapter 4. FAQ
python-tradingview-ta Documentation
A simple network inspection on TradingView’s website revealed that the data is retrieved through an undocumented
API.
TradingView_TA works by calculating similar data using algorithms reverse-engineered from their JavaScript code.
400 error indicates that the request is invalid. Usually, this is caused when the indicators does not exist. See https:
//pastebin.com/1DjWv2Hd for valid indicators.
404 error indicates that the webpage does not exist. Usually, this is caused when the screener does not exist. Check if
the screener, symbol, and exchange are correct using this tool: https://tvdb.brianthe.dev.