This content originally appeared on Level Up Coding - Medium and was authored by Besarion Turmanauli
How to export historical price data from MetaTrader 5 to CSV
This is the fourth article in a series of tutorials: Build AI for generating quant trading strategies automatically, you can access the previous article from here:
Build AI for Generating Quant Trading Strategies in C# (Part 3)
Tester class is ready, it will be used by reinforcement learning algorithm later, however, we need to generate data points for the tester.
First, let’s export OHLC price data from MetaTrader 5 trading terminal:
- Launch your MT5 terminal, if the Market Watch window is not visible, go to the main menu > View > Market Watch or CTRL+M. It looks like this:

2. Right-click on the instrument of your choice and choose Symbols, a new window will appear:

3. Switch to the Bars tab highlighted on a screenshot above, choose the timeframe, start date, end date, and click Request:

4. Click on the Export Bars button and save the CSV file wherever you want:

As you can see we have candle open date, open price, high price, low price, close price, tick volume, volume (actually we don’t have real volume for Forex pairs, this is why it’s always 0), and spread values to work with, we’ll import and process them in a PriceEngine class in C#, calculating daily OHLC (open, high, low, close) values, some indicator values like RSI, ATR and more.
CSV data’s ready for import, we’ll process this data in the next tutorial.
Thank you and have a great day!
Build AI for Generating Quant Trading Strategies in C# (Part 4) was originally published in Level Up Coding on Medium, where people are continuing the conversation by highlighting and responding to this story.
This content originally appeared on Level Up Coding - Medium and was authored by Besarion Turmanauli

Besarion Turmanauli | Sciencx (2021-04-14T17:30:20+00:00) Build AI for Generating Quant Trading Strategies in C# (Part 4). Retrieved from https://www.scien.cx/2021/04/14/build-ai-for-generating-quant-trading-strategies-in-c-part-4/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.