Futures volume data analysis
TL;DR
In this post I will detail how to download Micro E-mini futures data from MetaTrader 5 and analyze it using Python libraries and volume indicators.
Intro
The trading of index futures contracts attracted my attention due to high liquidity, lower transaction costs and lower capital requirements if compared with other financial instruments. These facts, combined with the large number of online brokers on which an account could be opened in minutes, mean that the entry barrier to start trading is very low.
May be due to that, most of the individuals trading intraday lose money, as pointed out by several studies analyzing trade records from multiple exchanges around the world. As my personal experience of manually trading futures using a discretionary approach matches that pattern, I started to look for alternatives that could tip the scale in my favor.
One of the assumptions of tape reading is that there is a significant correlation between the contract volume and sequence of deals made at each price level and the overall price movement in a given time window. How valid is this assumption, and how could that positively impact my trading? These are the questions I will attempt to answer using a data driven mindset.
Environment configuration
To collect the data I use MetraTrader 5 (MT5) on Windows, a trading platform that is available at no cost and is supported by a wide range of brokers including AMP Global, through which demonstration accounts for paper trading can be easily opened as of the time of writing.
After downloading the application, by accessing the File menu, there should be an option to Open an account, as depicted in Figure 1.
When clicking the option, there should be a window with a search box for selecting the broker on which to open the account, as illustrated in Figure 2.
For opening a demo account, as the one I used for the data collection, some personal data as name, email address and phone number is usually requested by the broker.
If everything goes as planned, it is possible to use the MetaTrader 5 to get data related to an index as the Micro E-mini S&P 500 Index.
Getting data
The first task is to collect data on the price moves at each time window and the amount of contracts traded at those same time windows. By overlapping graphic representations of both time series, aligned by timestamps, a first visual analysis can be made.
Using the built-in features of MT5, it is possible to download data on the open, high, low and close (OHLC) values of the instrument for each time window. By pressing CTRL+U
or the menu item View->Symbols
the window depicted in Figure 3 below should appear.
In the Bars
tab, representing OHLC data, the Micro E-mine ticker (MESM23) can be selected along with the time frame (M1 for 1 minute) and time window from which the data should be collected (1AM to 4PM UTC, April 4th 2023 in the example). After pressing the Request
button on the top right side, the data is collected from the broker databases. By clicking Export Bars
, the data can be saved to a local file.
If the same settings as Figure 3 are used, the resulting file will contain OHLC data in text format with columns separated by a tab. There will be one line for each minute with columns for date, time, number of trades closed (TICKVOL) and amount of contracts (VOL) involved in the deals closed. When opening the file a structure similar to Figure 4 should be visible.
The highlighted row in Figure 4 indicates that during the minute of 2:35PM, 1,038 deals were closed with a volume of 2,156 contracts and MESM23 value increased from $4,152 to $4,154.
Visualizing the data
In order to perform a first analysis of the data and the correlation between volume of deals and the variation of price, it can be useful to visualize OHLC data alongside volumes for each time frame. In order to do that, mplfinance, a Python library on the matplotlib ecosystem, can be used to create graphs with low effort.
I used the following code snippet to generate the graphs used in the analysis.
"""Plotting OHLC data and volume"""
import sys
import mplfinance as mpf
import dateparser
import pandas as pd
= sys.argv[1]
ohlc_filename print(f"Loading candle data from {ohlc_filename}...")
= pd.read_csv(ohlc_filename, sep="\t")
ohlc_data = [
ohlc_data.columns "date",
"time",
"open",
"high",
"low",
"close",
"tick_volume",
"volume",
"spread",
]
"datetime"] = ohlc_data.apply(
ohlc_data[lambda row: dateparser.parse(row["date"] + " " + row["time"]), axis=1
)"datetime", inplace=True)
ohlc_data.set_index(
= mpf.make_marketcolors(
marlet_colors ="green",
up="red",
down="darkblue",
volume
)= mpf.make_mpf_style(marketcolors=marlet_colors)
custom_style print("Saving plot...")
mpf.plot("open", "high", "low", "close", "volume"]],
ohlc_data[[=True,
tight_layout=True,
volumetype="candle",
=(16, 9),
figratio=custom_style,
style="candle_M1.png",
savefig="UTC times",
xlabel )
The first block of code retrieves the first command line argument and uses it as the name of the OHLC file name to be read. The pandas method read_csv
loads the tab-separated values into a data frame that has its columns renamed to standard values expected by mplfinance.
The second block of code concatenates date and time columns, represented as strings, and uses dateparser to create a DatetimeIndex, also expected by mplfinance as the index of its input data.
The third and last block of code creates a custom rendering style for the graph, with red for down candles, green for up candles and dark blue for volumes. The plot created by the plot
method is saved as a PNG image showed in Figure 5.
High level analysis
A quick inspection of Figure 5 indicates that most of the volume traded was done between 1:30PM and 3:30PM, with spikes of more than 10,000 contracts traded in a single minute around 2:40PM. It is also possible to say that in general the periods with less volume traded per minute have a flatter price line, with smaller volatility.
Moreover, periods on which the trade volume suddenly increases, as highlighted in 1, 2 and 3 of Figure 6, seem to correlate with price trends and trend reversals, both upwards and downwards.
Trade volume alone does not explain all the price variance, specially not the direction of the movement. A finer, detailed analysis using different factors is required; that will be the topic of a future post.
Disclaimer
Futures and options trading has large potential rewards, but also large potential risk. You must be aware of the risks and be willing to accept them in order to invest in the futures and options markets. Do not trade with money you can not afford to lose. This post is neither a solicitation nor an offer to buy or sell futures or options. No representation is being made that any account will or is likely to achieve profits or losses similar to those discussed. The past performance of any trading system or methodology is not necessarily indicative of future results.
This post is provided for informational and educational purposes only. This material neither is, nor should be construed as an offer, solicitation, or recommendation to buy or sell any securities. Any investment decisions made by the reader through the use of this content is solely based on the reader independent analysis, taking into consideration their financial circumstances and risk tolerance. The author shall not be liable for any errors or for any actions taken in reliance thereon.
The references made to MT5 and AMP Global in this post do not represent a recommendation. I am not affiliated to neither platform, service nor parent companies.