Meta Stock Analysis with LightningChart Python Trader
Tutorial
Written by a Human
Learn how to create Meta stock analysis using LightningChart Python Trader for visualizing stock price data.
Introduction
In this article, I will create Facebook’s Meta stock analysis using LightningChart Python Trader as a data visualization library. The data will be pre-processed using the Python library Pandas. The stock data has been sourced from a Kaggle dataset. The visualisation will go over historical closing prices, as well as OHLC values through Candlestick and Heikin Ashi charts, volume, and trend directions.
Kaggle dataset
The data for this article was acquired from a Kaggle dataset by Arpit Verma. The dataset’s time frame is between 2012 and 2022. Facebook had its IPO on May 18, 2012, so the data contains important historical details. Unfortunately, it is not an updated dataset as it ends on March 24, 2022. However, the purpose of this article is mainly to demonstrate the visualization/charting features of LightningChart Python Trader.
The data is first downloaded as a CSV file and then pre-processed before being imported to the trader. Data import and pre-processing are done mostly with Pandas.
Plotted variables
LightningChart Python Trader requires Open, High, Low, Close (O, H, L, C) values to work as well as a date. These values refer to the stock’s Highest and Lowest prices during the trading day, as well as what the price was at market open and close. Volume value is not required for the trader to work, but is needed for certain indicators.
Libraries used
LightningChart Python trader
LightningChart Python Trader must be installed unless it is already available in your environment. You can install it using the following command
pip install lightningchart_trader
- Pandas: Pandas also needs to be installed before it can be imported into the project.
- OS Library: Python’s built-in OS library will be used briefly. It comes preinstalled with Python, so no additional setup is required
LightningChart Python Trader
LightningChart’s Python Trader (PT) provides extensive charting solutions with a high degree of customizability through its easy-to-use UI and built-in functionalities. Since the library is built for Python, it’s also possible to use other Python libraries if necessary. As with all Lightningchart products, Performance has been a high priority when developing the library, even when working with large amounts of data, thus removing possible bottlenecks in this area.
Overview of the UI
Above is the PT user interface with stock data charted using the default candlestick chart. On the top left are controls used to customize the chart and work with datasets. Here is the explanation for all the UI controls:
Charting features
These are chart types of Python trader provides out of the box.
Chart types can be changed with the the UI or with the set_price_chart_type(chart_type) command. Available ones are ‘CandleStick’, ‘Bar’, ‘Line’, ‘Mountain’, ‘HeikinAshi’, ‘Renko’, ‘Kagi’, and ‘PointAndFigure’. For example, a mountain creating a mountain chart using the following methods:
trader.set_price_chart_type('Mountain')
trader.add_data_array(data)
trader.open()
Chart visuals can be customized using the Python trader UI. Below are available settings for chart and indicator colours, background colour/image etc.
Default chart colours.
Background and indicator colours changed
Chart customization
Customisation can also be done with code, using the built-in methods. The code below changes the background image and the chart colours to the ones seen in the right image. But why use code for customisation, since working with UI is easier?
trader.set_color_theme('cyberSpace')
# Changing the indicator colours for the candlesticks
trader.set_positive_body_color('#0fdf0c')
trader.set_positive_wick_color('#33d7a0')
trader.set_negative_body_color("#f3eb16")
trader.set_negative_wick_color('#b85900')
When the customization is applied on code level there’s no need to change any settings or load a template. Meaning you won’t have to make the changes every time when opening a chart. Python trader supports the use of templates for customization, and these files can be loaded in with code.
However, you still need to manually select the file, and in case you want to share the chart the template file would also need to be shared. When the changes are done in code, only it needs to be shared to get the same results.
Technical indicators
Python trader supports over 100 technical indicators. These include ones such as Relative Strength Index (RSI), Bollinger bands, Moving averages (SMA, EMA etc), Oscillators for money flow and price, Fibonacci retracements, as well as statistical ones like Standard deviation. Technical indicators can be added to a chart easily with the trader UI, their properties (period count, standard dev) can also be changed the same way.
These indicators can also be added and customized via code.
trader.add_simple_moving_average(period_count=14)
trader.add_bollinger_band(period_count=14)
Indicators such as the Fibonacci patterns can be added with the built-in draw tools. Other markers can also be added this way. To see all the indicators, refer to the documentation.
Setting Up Python Environment
This code snippet imports the necessary libraries and creates a new trader instance, which remains unchanged across charts.
from lightningchart_trader import TAChart
import pandas as pd
import os
# license key for python trader and create trader instance
license_key_path = "Python-Trader_License_key.txt"
# license key for python trader and the stock API
license_key = open(license_key_path).read()
chart = TAChart(license_key)
path_to_csv = 'data/project-17/'
# All file names in the filepath
csv_list = os.listdir(path_to_csv)
# Transform the CSV into a dataframe, combine the file path, with the desired files name
stock_dataframe = pd.read_csv(path_to_csv + csv_list[0])
This part of the code imports the necessary libraries and creates a new trader instance. It needs to be run every time, but won’t change between charts. I’ll provide only the code going forward that changes on a per-chart basis, but make sure to include the snippet above.
I recommend providing a full file path to the CSV files, even if the data is saved in the same directory or a subdirectory in relation to your .py files. This since I’ve personally experienced issues with Python when only a partial path is provided. Example:
'C:/Users\name\Desktop\path\to\the\files/'
Note the different types of forward slashes used. Python might give an error if you input the path in the same format as it is in the file directory.
Meta Stock Analysis & Visualizations
Now, we will build the visualizations for Meta stock analysis.
Meta’s historical closing price
Meta’s closing price between 2012 and 2022, Q1.
from lightningchart_trader import TAChart
import pandas as pd
import os
license_key_path = "Python-Trader_License_key.txt"
# license key for python trader and the stock API
license_key = open(license_key_path).read()
chart = TAChart(license_key)
path_to_csv = 'data/project-18/'
# All file names in the filepath
csv_list = os.listdir(path_to_csv)
# Transform the CSV into a dataframe, combine the file path, with the desired files name
stock_dataframe = pd.read_csv(path_to_csv + csv_list[0])
print(stock_dataframe.columns)
# New dataframe for the adjusted close price.
stock_dataframe.rename(columns={
'Close' : 'Old close',
'Adj Close' : 'close'}, inplace=True)
# Set chart title; I'm using the file name as a placeholder,
# type; CandleStick, Bar, Line, Mountain, Renko, HeikinAshi or Point&Figure
# and data source used; in this case the stock dataframe
chart.set_chart_title(csv_list[0])
chart.set_price_chart_type('Line')
chart.set_data(stock_dataframe)
# Optional appearence customization although I recommend changing the time range
chart.set_color_theme('darkGold')
chart.set_line_color("#b2ff24")
chart.change_time_range(0)
chart.set_series_background_color('#258382', fillStyle=1, gradientColor="#1a2765", angle=-173, gradientSpeed=0.80)
chart.open()
OHLC data chart for 1-year period (2021-2022)
Candlestick and Heikin Ashi charts are built to analyze price movements on a day-by-day basis as well as the intraday volatility.
Note: Use ‘HeikinAshi’ as the parameter for the set_price_chart_type() function when creating the second chart. Alternatively, change the type from the Trader UI.
from lightningchart_trader import TAChart
import pandas as pd
import os
license_key_path = "Python-Trader_License_key.txt"
# license key for python trader and the stock API
license_key = open(license_key_path).read()
chart = TAChart(license_key)
path_to_csv = 'data/project-18/'
# All file names in the filepath
csv_list = os.listdir(path_to_csv)
# Transform the CSV into a dataframe, combine the file path, with the desired files name
stock_dataframe = pd.read_csv(path_to_csv + csv_list[0])
print(stock_dataframe.columns)
# New dataframe for the adjusted close price.
stock_dataframe.rename(columns={
'Close' : 'Old close',
'Adj Close' : 'close'}, inplace=True)
# Set chart title; I'm using the file name as a placeholder,
# type; CandleStick, Bar, Line, Mountain, Renko, HeikinAshi or Point&Figure
# and data source used; in this case the stock dataframe
chart.set_chart_title(csv_list[0])
chart.set_price_chart_type('CandleStick')
chart.set_data(stock_dataframe)
# Optional appearence customization although I recommend changing the time range
chart.set_color_theme('darkGold')
chart.set_line_color("#b2ff24")
chart.change_time_range(4)
chart.set_series_background_color('#258382', fillStyle=1, gradientColor="#1a2765", angle=-173, gradientSpeed=0.80)
chart.open()
By analysing not only the trading volume but two indicators that utilize it, it’s possible to detect entry and exit positions. The Money Flow Index (MFI) is somewhat similar to the Relative Strength Index (RSI), with the latter only using price in its calculations, while the former also includes volume. MFI displays potential entry and exit opportunities by showing when the stock is sold or bought in larger quantities than usual. Chaikin Money Flow is based on the idea that the closer the closing price is to either the period’s low or high can be used to determine trend strength.
from lightningchart_trader import TAChart
import pandas as pd
import os
license_key_path = "Python-Trader_License_key.txt"
# license key for python trader and the stock API
license_key = open(license_key_path).read()
chart = TAChart(license_key)
path_to_csv = 'data/project-18/'
# All file names in the filepath
csv_list = os.listdir(path_to_csv)
# Transform the CSV into a dataframe, combine the file path, with the desired files name
stock_dataframe = pd.read_csv(path_to_csv + csv_list[0])
print(stock_dataframe.columns)
# New dataframe for the adjusted close price.
stock_dataframe.rename(columns={
'Close' : 'Old close',
'Adj Close' : 'close'}, inplace=True)
# Set chart title; I'm using the file name as a placeholder,
# type; CandleStick, Bar, Line, Mountain, Renko, HeikinAshi or Point&Figure
# and data source used; in this case the stock dataframe
chart.set_chart_title(csv_list[0])
chart.set_price_chart_type('CandleStick')
chart.set_data(stock_dataframe)
# Optional appearence customization although I recommend changing the time range
chart.set_color_theme('darkGold')
chart.set_line_color("#b2ff24")
chart.set_series_background_color('#258382', fillStyle=1, gradientColor="#1a2765", angle=-173, gradientSpeed=0.80)
chart.add_chaikin_money_flow()
chart.add_money_flow_index()
chart.add_volume()
chart.open()
Price trend direction analysis with Renko chart
Renko charts are used to isolate trend directions and price movements; these charts do not represent time in a linear fashion like line or candlestick charts. A box size of 4 was used for the charts. This means that the stock price has to move 4$ to either direction from the previous brick’s price before a new brick is added (regardless of how long that takes). Base type was close. These values can be changed from the chart settings, top left icon.
Two things can be observed from the first chart. One is the trend direction, the other is volatility. Since the chart’s time range is 2012-2022, but dates before 2019 take only a fraction of the space, it can be concluded that the price has experienced more movement in the 2019-2022 time frame.
By using the RSI indicator, it’s possible to identify possible reversal points and thus good entry/exit times. Although not 100% accurate, many reversal positions could be identified with this indicator. The chart below only has a time range of 2019-2022, and has the Bollinger band added in addition to RSI.
from lightningchart_trader import TAChart
import pandas as pd
import os
license_key_path = "Python-Trader_License_key.txt"
# license key for python trader and the stock API
license_key = open(license_key_path).read()
chart = TAChart(license_key)
path_to_csv = 'data/project-18/'
# All file names in the filepath
csv_list = os.listdir(path_to_csv)
# Transform the CSV into a dataframe, combine the file path, with the desired files name
stock_dataframe = pd.read_csv(path_to_csv + csv_list[0])
print(stock_dataframe.columns)
# New dataframe for the adjusted close price.
stock_dataframe.rename(columns={
'Close' : 'Old close',
'Adj Close' : 'close'}, inplace=True)
# Set chart title; I'm using the file name as a placeholder,
# type; CandleStick, Bar, Line, Mountain, Renko, HeikinAshi or Point&Figure
# and data source used; in this case the stock dataframe
chart.set_chart_title(csv_list[0])
chart.set_price_chart_type('CandleStick')
chart.set_data(stock_dataframe)
# Optional appearence customization although I recommend changing the time range
chart.set_color_theme('darkGold')
chart.set_line_color("#b2ff24")
chart.set_series_background_color('#258382', fillStyle=1, gradientColor="#1a2765", angle=-173, gradientSpeed=0.80)
chart.add_relative_strength_index()
chart.add_bollinger_band()
chart.open()
Analysis
How has Meta’s stock price trended historically?
Meta’s stock has experienced mostly steady growth over the years. Two sharp drops can be observed, most likely related to the Cambridge Analytica controversy that happened around that time, in addition to the 2020 COVID-19 pandemic drop. Finally, in 9/2021, Meta’s stock price began to decline slowly, before sharply dropping in 2/2022. Overall, the latter most examples resulted in over 50% drop in just 6 months from the all-time high.
What insights can be drawn from OHLC patterns about volatility (3/2021-3/2022)?
At a glance, there appears to be an increase in volatility after 9/2021, right after the stock hit its all-time high. This is more noticeable in the high-low prices, especially with the appropriate indicator. There’s a large drop in price, and after this volatility, it remains slightly higher than prior to it.
How does trading volume affect Meta’s price dynamics?
Negative volume index shows that after all time high and before the drop stock price would go during lower volatility days. This might indicate that there was an assumption among smart money (institutions) that Meta’s price would recover. During the large drop, volume went up significantly temporarily and stayed above pre-drop rates (at least for the duration of the dataset).
Conclusion
The stock data has been imported from a CSV file to Python Trader using Pandas. The data frame has been modified to use the adjusted close value of close value. Several different chart types were used to analyse the stock course, over long- and short-term. By combining indicators with different chart types, patterns can be observed. As LightningChart Python Trader makes this very easy due to different tools, easy-to-use UI, and fast performance, it was no issue to try different combinations.
Continue learning with LightningChart
The Complete Guide to JavaScript Charts
Written by a human | Updated on April 9th, 2025JavaScript Charting Libraries Charting libraries are at a high peak and their development and usage are becoming even more popular in languages like JavaScript. As proof, there are a lot of JavaScript charting...
What Can Vibration Analysis Detect?
Written by a human | Updated on April 9th, 2025Vibration Charts When you think about vibration analysis, what comes to mind? It is becoming a very common identification method in structural engineering to identify issues with potential structural integrity, such...
Quasar JS
Written by a human | Updated on April 9th, 2025What is Quasar JS? Hello! In this article, we will create a basic application using the Quasar JS framework. In this application, we will load three charts from the LC JS Library. But before we start, it would be...
