This open-source Python Flask application plots Yahoo Finance data on TradingView Lightweight Charts, with EMA and RSI indicators, a watchlist, multiple timeframes and a light/dark theme. Flask and yfinance fetch the data, pandas_ta calculates the indicators, and the Lightweight Charts JavaScript library renders interactive candlestick charts in the browser. The full code is on GitHub so you can run it locally and customise it.
Hey traders! If you’re looking for a way to visualize your stock data dynamically and interactively, you’re in for a treat. Today, we’ll explore how to create a web application using TradingView’s Lightweight Charts and Yahoo Finance. This tool fetches real-time stock data, applies technical indicators like EMA and RSI, and offers a smooth, interactive experience. Plus, it’s open-source, so you can tweak it to your heart’s content!
- Backend: Flask with yfinance for data and pandas_ta for EMA and RSI; watchlist symbols are stored in SQLite.
- Frontend: TradingView Lightweight Charts for candlestick, EMA and a synchronised RSI pane.
- Install with git clone, pip install -r requirements.txt and python app.py, then open http://127.0.0.1:5000.
- The repository now uses the Lightweight Charts v5 addSeries API; v4 tutorials using addCandlestickSeries will not work with v5.
- Use the .NS suffix for NSE stocks (for example RELIANCE.NS) and ^NSEI for Nifty 50.
Why TradingView Lightweight Charts?
TradingView’s Lightweight Charts are perfect for traders who want clean, responsive and highly customizable charting. Whether you’re analyzing market trends, tracking stock performance, or just keeping an eye on your favorite stocks, these charts offer the precision and clarity you need without any unnecessary bloat.

Why open source?
I believe in the power of community and collaboration. By keeping this project open-source, I’m inviting you to customize, enhance, and build upon this tool. Whether you want to add new features, integrate additional data sources, or just tweak the visuals to your liking, the code is all yours to play with. Let’s make trading tools better together!

Features of the application
- Real-Time Stock Data: Fetch and display real-time stock data from Yahoo Finance.
- Technical Indicators: Apply and visualize technical indicators such as EMA (Exponential Moving Average) and RSI (Relative Strength Index).
- Interactive Charts: Use TradingView’s Lightweight Charts for a smooth and interactive data visualization experience.
- Theme Toggle: Switch between light and dark themes for a better user experience.
- Watchlist: Maintain a watchlist to quickly switch between different stock symbols.
- Crosshair Synchronization: Synchronize crosshair positions across multiple charts for better data comparison.
- Multiple timeframes: 1 minute, 5 minutes, 15 minutes, hourly, daily, weekly and monthly, with an auto-update option.
Working mechanism
- Data Fetching: The backend of the application, built with Flask, fetches stock data from Yahoo Finance using the yfinance library. It calculates EMA and RSI using the pandas_ta library.
- Data Processing: The fetched data is processed and formatted to be used by the frontend. EMA and RSI values are included in the data and NaN values are handled appropriately.
- Data Serving: Flask serves the processed data to the frontend through various API endpoints.
- Interactive Visualization: The frontend uses TradingView’s Lightweight Charts to display the stock data and technical indicators interactively. Users can add stocks to a watchlist and toggle between light and dark themes.
How to install and run the Flask app
These are the steps from the project README on GitHub:
git clone https://github.com/marketcalls/tradingview-yahoo-finance.git
cd tradingview-yahoo-finance
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
python app.py # then open http://127.0.0.1:5000
The app opens with a default watchlist of US stocks. To chart Indian markets, add Yahoo Finance symbols with the exchange suffix, such as RELIANCE.NS or TCS.NS for NSE, .BO for BSE, and ^NSEI for the Nifty 50 index. For more on Yahoo symbols and data, see my yfinance guide for analysing stock market data.
Intraday history on Yahoo Finance is limited, so the app requests 7 days of data for 1 and 5 minute charts and 60 days for 15 minute and hourly charts, and five years for daily, weekly and monthly charts.
Technologies used in the application
1. Flask (Backend)
Description: Flask is a lightweight web framework for Python. It’s used to create web applications and APIs.
Usage in the Application:
- Serving HTML templates and static files.
- Defining API endpoints to fetch stock data.
- Handling HTTP requests and responses.
2. Yahoo Finance API (yfinance)
Description: yfinance is a Python library that enables easy access to historical market data from Yahoo Finance.
Usage in the Application:
- Fetching historical stock data.
- Providing real-time data for various stock symbols.
- Supporting different intervals like daily, weekly, and monthly data.
3. Pandas (Data Processing)
Description: Pandas is a powerful data manipulation and analysis library for Python.
Usage in the Application:
- Storing and processing fetched stock data in DataFrames.
- Cleaning and preparing data for visualization.
- Handling date and time operations.
4. Pandas_TA (Technical Analysis)
Description: pandas_ta is a Python library that provides technical analysis indicators using Pandas.
Usage in the Application:
- Calculating technical indicators like EMA (Exponential Moving Average) and RSI (Relative Strength Index).
- Adding these indicators to the stock data for visualization.
5. TradingView Lightweight Charts (Frontend)
Description: TradingView Lightweight Charts is a library that provides high-performance, interactive financial charts.
Usage in the Application:
- Rendering interactive candlestick charts.
- Displaying technical indicators like EMA and RSI.
- Synchronizing multiple charts for comparative analysis.
- Providing a smooth user experience with features like crosshair synchronization.
2026 update: Lightweight Charts v5 and pandas_ta
Lightweight Charts v5 API change
TradingView Lightweight Charts moved to version 5 after this post was written (the current npm release is 5.2.1). Version 5 replaced the per-type methods with a single addSeries() call, as described in the official v4 to v5 migration guide. The repository’s static/main.js already uses the new style:
// Lightweight Charts v4 (older tutorials)
const candles = chart.addCandlestickSeries({ upColor: '#26a69a', downColor: '#ef5350' });
// Lightweight Charts v5 (used in the current repository)
const candles = chart.addSeries(LightweightCharts.CandlestickSeries, {
upColor: '#26a69a',
downColor: '#ef5350',
});
The template loads the library from unpkg without a version number, so it always pulls the latest release. If you fork the project, pin a version (for example [email protected]) so a future major release cannot break your charts.
If pandas_ta will not install
The repository pins pandas_ta==0.3.14b0 together with numpy==1.26.4. Newer pandas-ta releases on PyPI require Python 3.12 or later, so mixing versions can fail. If you hit install errors, you can drop pandas_ta and compute both indicators with plain pandas:
import pandas as pd
def ema(close: pd.Series, length: int = 20) -> pd.Series:
return close.ewm(span=length, adjust=False).mean()
def rsi(close: pd.Series, length: int = 14) -> pd.Series:
delta = close.diff()
gain = delta.clip(lower=0)
loss = -delta.clip(upper=0)
avg_gain = gain.ewm(alpha=1 / length, adjust=False, min_periods=length).mean()
avg_loss = loss.ewm(alpha=1 / length, adjust=False, min_periods=length).mean()
rs = avg_gain / avg_loss
return 100 - (100 / (1 + rs))
# data['EMA'] = ema(data['Close'], 20)
# data['RSI'] = rsi(data['Close'], 14)
The EMA can differ slightly from pandas_ta in the first few bars because of how the series is seeded, but the values converge after the warm-up period.
Ideas to extend the project
- Replace Yahoo Finance with broker data for NSE intraday charts. See TradingView Lightweight historical charts using OpenAlgo.
- Add more indicators such as Supertrend, VWAP or Bollinger Bands as extra line series.
- Share the app from your laptop with pyngrok and an ngrok free domain.
- Add price alerts on the watchlist and push them to Telegram.
This open-source project is just a starting point. Feel free to modify, extend, and enhance it as you see fit. Together, we can create even more useful tools for the trading community. Happy trading!
Frequently Asked Questions
Is TradingView Lightweight Charts free?
Yes. Lightweight Charts is open source under the Apache 2.0 licence. TradingView asks that you keep its attribution notice visible on the chart.
Can I use TradingView Lightweight Charts with Python?
The library itself is JavaScript, so Python is used on the server side. A Flask or FastAPI backend fetches and processes the data and returns JSON, and the browser renders it with Lightweight Charts, as in this project.
Is Yahoo Finance data real time for NSE stocks?
Yahoo Finance data for Indian stocks is suitable for analysis and learning, but it can be delayed and is not an exchange-authorised feed for trading. Use your broker’s API for live trading decisions.
How do I add Nifty to the chart?
Add the Yahoo symbol ^NSEI for the Nifty 50 index, or ^NSEBANK for Nifty Bank, to the watchlist.
Related: Yahoo Finance API
Learn by watching: free videos every week
Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

