Search

Download Ticks Data using MetaTrader 5 and Python (CFD & Futures)

link between the trading platform MetaTrader 5 and the programming language Python

We have all use fix time bars, but is it really the best way to summarize the ticks? Ticks can give us a better overview of the market? How to use ticks? Many questions, but the first step for all these answers is the same: download tick data using MetaTrader 5 and Python (or from another source, of course).

That’s why in this article, I will show you how to do it in less than 10 lines of code. The goal is to show you how to import the ticks for one day in order to let you customize this code to import for longer historical.

In the 3rd monthly project of the Alpha Quant Program (a program helping new quant traders to break into this amazing field easily with support, applications and e-learning videos), we have imported and stored 10 years of ticks data in 15 minutes for a total cost of 0$ and for only 2GB. The first to do the same begins below, in this post…

1. METATRADER 5 WITH PYTHON - THE PREREQUISITES

To use MetaTrader 5 and Python to download the ticks data, we need to set up our environment. It means several things, you need, of course, Python on your computer and for us a software that allow us to open the notebook containing the code I provided.

The second thing which is mandatory is to use a Windows device. For those of you who have a Mac, you can create a Windows session on your mac directly or use a software that emulates a Windows session like Parrallels Desktop (what I do personally). We need to do that because of the MetaTrader 5 Python library works only on Windows.

And last but not least, you need to have the MetaTrader 5 platform (you can download it here) and at least a demo account from your broker (not the one from Metaquotes because the data are not reliable). I use personally Admiral Markets and AMP Futures but I will detail that later.

2. DOWNLOAD YOUR FIRST TICK DATA USING METATRADER 5 AND PYTHON

Once we have all the prerequisites, it will be really quick. Indeed, we will use the copy ticks range function from the MetaTrader 5 in 1 line of code to extract the data we need. This code extract all the ticks from the 22th January 2024 to the 24th January 2024.

Once we have them, it is important to reshape a bit our output. First, we transform our array into a dataframe and we convert our number date format into a date time format to have a better visualization.

table showing some trading ticks data

As you see above, the from_date and to_date variable our datetime variables. Moreover, we do not have to change the mt5.COPY_TICKS_ALL parameters. The only thing that you need to change is the symbol you put into the function, here “[CAC-40]-Z”. You can put the symbol you want while it is in your MT5 market watch.

Figure: Example of a MetaTrader 5 market watch

table with trading quotations

3. CFD TICKS VS FUTURE TICKS

The CFD vs Future fight has begun a very long time ago. You can trade the one you prefer, it is not the subject of this post. But the question is “how do I know if I’m importing the CFD or Futures data?

The answer is really simple. Indeed, you are importing the data provided by your broker. So, for me, when I want to import CFD data, I use generally Admiral-Markets because they give 10 years of historical data (without the volume like nearly all the CFD providers). And when I want to import Futures data (with volume), I use AMP-Futures because they provide future contracts.

So, to summarize, no needs to have something special into the code. The data will come from the broker you are currently connected to and for the symbol you are selecting into the function.

By the way, you can add new symbols to your market watch and connect you to other brokers with Python? I let you check the documentation here.

Join Our Newsletter

Be the first to receive our latest quant trading content (personal notes, discount, new articles).

4. WHY TICKS ARE BETTER?

As I said it, in one of our previous articles “Algortihmic Trading Strategy building processes – ROAD MAP 2024”. The data is the foundation of all our analysis. The more data you can have, the better it is.

Moreover, the more you are using data difficult to find, difficult to handle, the longer you will keep your edge once you find one. Indeed, your edge disappears when too many people use it. So, if it is too difficult to find it, they will use a simpler dataset and let your edge for you, alone!

Another important reason is that, the ticks are the smallest timeframe: each variation create a new tick. It means, you can create other types of bars (ticks, bars, imbalance bars, volume bars, …), you can find the support and resistance more precisely and much, much more.

So, to conclude, here, I explained to you how to import some ticks data very easily. But it was only for one day. It is impossible to have a year of ticks data on one file. It is too difficult to handle when you have between 10 million and 20 million data. So, you need to store all this data in several files and process them sequentially when you will work with this data. More work, work that other people don’t want to do. So more work, for a better edge..

If you want to take your trading to the next steps using E-learning videos, 7D/7 support, templates, monthly projects, private community, lives and much more, feel free to check our Alpha Quant Program.

👨‍💻Code:
https://github.com/Quantreo/YOUTUBE-VIDEO-CODES/blob/main/IMPORT%20TICKS%20DATA%20USING%20MT5%20AND%20PYTHON/IMPORT%20TICKS%20DATA.ipynb

Join Our Newsletter

Be the first to receive our latest quant trading content (personal notes, discount, new articles).

Lucas Inglese

Lucas is a self-taught Quantitative Analyst, holding degrees in Mathematics and Economics from the University of Strasbourg. Embarking on an independent learning journey, he delved deeply into data science and quantitative finance, eventually mastering the disciplines. Lucas has developed numerous bots, sharing his insights and expertise on LinkedIn, where he regularly posts content. His understanding and empathy for beginners in this complex field led him to author several books and create the comprehensive “Alpha Quant Program.” This program offers e-learning videos, monthly projects, and continuous 7-day-a-week support. Through his online courses and publications, Lucas has successfully guided over 67,000 individuals in their pursuit of knowledge in quantitative finance.

Related Posts

Scroll to Top