{"id":29565510,"url":"https://github.com/tim55667757/mt4forexparser","last_synced_at":"2025-07-18T21:32:00.618Z","repository":{"id":53965248,"uuid":"280826934","full_name":"Tim55667757/MT4ForexParser","owner":"Tim55667757","description":"Read forex data in MetaTrader 4 .hst-format and convert into .csv file and pandas dataframe. See article (ru): https://forworktests.blogspot.com/2022/01/mt4forexparser-python-metatrader-4.html","archived":false,"fork":false,"pushed_at":"2023-10-18T02:21:50.000Z","size":4563,"stargazers_count":26,"open_issues_count":2,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-04T12:06:10.330Z","etag":null,"topics":["candlesticks","chart","forex","history","metatrader-4","parser"],"latest_commit_sha":null,"homepage":"https://tim55667757.github.io/MT4ForexParser/","language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tim55667757.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2020-07-19T08:49:07.000Z","updated_at":"2025-05-16T20:17:17.000Z","dependencies_parsed_at":"2022-08-13T05:20:47.272Z","dependency_job_id":"ef68f882-3737-4c74-8b92-5b5e314d24d3","html_url":"https://github.com/Tim55667757/MT4ForexParser","commit_stats":{"total_commits":34,"total_committers":1,"mean_commits":34.0,"dds":0.0,"last_synced_commit":"4aceab05f150cfccc0ad4622c612476e279b68f0"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/Tim55667757/MT4ForexParser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FMT4ForexParser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FMT4ForexParser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FMT4ForexParser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FMT4ForexParser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tim55667757","download_url":"https://codeload.github.com/Tim55667757/MT4ForexParser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tim55667757%2FMT4ForexParser/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265837538,"owners_count":23836557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["candlesticks","chart","forex","history","metatrader-4","parser"],"created_at":"2025-07-18T21:30:35.475Z","updated_at":"2025-07-18T21:32:00.585Z","avatar_url":"https://github.com/Tim55667757.png","language":"HTML","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MT4ForexParser\n\n[![Build Status](https://travis-ci.com/Tim55667757/MT4ForexParser.svg?branch=master)](https://travis-ci.com/Tim55667757/MT4ForexParser)\n[![pypi](https://img.shields.io/pypi/v/MT4ForexParser.svg)](https://pypi.python.org/pypi/MT4ForexParser)\n[![license](https://img.shields.io/pypi/l/MT4ForexParser.svg)](https://github.com/Tim55667757/MT4ForexParser/blob/master/LICENSE)\n\nAll traders sometimes need to get historical data on Forex currencies for further price analysis and charting. Most often this data is supplied for paid or you have to spend a lot of time manually uploading data from special sites.\n\nHowever, most Forex brokers work with the MetaTrader 4 trading platform and upload data there in a special binary MetaTrader 4 .hst format (not in .csv). You can use a trick and get historical candles by connecting to the broker's server in demo mode, which almost all brokers have. The compressed binary .hst file will be downloaded locally to the MetaTrader 4 working directory.\n\nThen you can run the mt4forexparser python module, which can read .hst files and save them as a text .csv file or pandas dataframe. You will get a table that contains columns of data in the following sequence: \"date\", \"time\", \"open\", \"high\", \"low\", \"close\", \"volume\". One line is a set of data for plotting one candlestick.\n\nSee russian readme here (инструкция на русском здесь): https://github.com/Tim55667757/MT4ForexParser/blob/master/README_RU.md\n\n\n## Setup\n\nThe easiest way is to install via PyPI:\n```commandline\npip install mt4forexparser\n```\n\nAfter that, you can check the installation with the command:\n```commandline\npip show mt4forexparser\n```\n\n\n## Usage examples\n\n### From the command line\n\nGet help:\n```commandline\nmt4forexparser --help\n```\n\nOutput:\n```\nusage: python MT4ForexParser.py [some options] [one command]\n\nMetatrader 4 forex history parser. Read, parse and save history as .csv-file\nor pandas dataframe. Also you can draw an interactive chart. See examples:\nhttps://tim55667757.github.io/MT4ForexParser\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --mt4-history MT4_HISTORY\n                        Option (required): full path to Metatrader 4 forex\n                        history file.\n  --output OUTPUT       Option: full path to .csv output file. Default is\n                        None, mean that returns only pandas dataframe.\n  --debug-level DEBUG_LEVEL\n                        Option: showing STDOUT messages of minimal debug\n                        level, e.g. 10 = DEBUG, 20 = INFO, 30 = WARNING,\n                        40 = ERROR, 50 = CRITICAL.\n  --parse               Command: read, parse and save mt4-history as pandas\n                        dataframe or .csv-file if --output is define.\n  --render              Command: use PriceGenerator module to render\n                        interactive chart from parsed data. This key only used\n                        with --parse key.\n```\n\n\n.hst-file formats are supported in two versions: 400 and 401 and are automatically detected. Try to check how the parser work through the command line using two attached files of different formats: ./tests/EURUSD240_old_format_400.hst and ./tests/EURUSD240_new_format_401.hst.\n\nThe command could be like this:\n```commandline\nmt4forexparser --mt4-history ./tests/EURUSD240_old_format_400.hst --output ./tests/EURUSD240_old_format_400.csv --debug-level 10 --parse\n```\n\nIf successful, you should get a log output similar to the following:\n```\nMT4ForexParser.py   L:118  DEBUG   [2020-07-21 20:47:00,134] MT4 parser started: 2020-07-21 20:47:00\nMT4ForexParser.py   L:38   DEBUG   [2020-07-21 20:47:00,134] MT4 history file: [./tests/EURUSD240_old_format_400.hst]\nMT4ForexParser.py   L:42   DEBUG   [2020-07-21 20:47:00,171] MT4 history file format version: [400]\nMT4ForexParser.py   L:63   INFO    [2020-07-21 20:47:00,334] It was read 5909 rows from file [./tests/EURUSD240_old_format_400.hst]\nMT4ForexParser.py   L:64   INFO    [2020-07-21 20:47:00,334] Showing last 3 rows:\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:47:00,339]             date   time     open     high      low    close  volume\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:47:00,339] 5906  2013.10.18  12:00  1.36918  1.37036  1.36690  1.36780    8193\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:47:00,340] 5907  2013.10.18  16:00  1.36779  1.36993  1.36773  1.36795    6639\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:47:00,340] 5908  2013.10.18  20:00  1.36793  1.36849  1.36765  1.36839    1955\nMT4ForexParser.py   L:73   INFO    [2020-07-21 20:47:00,383] Forex history saved to .csv-formatted file [./tests/EURUSD240_old_format_400.csv]\nMT4ForexParser.py   L:148  DEBUG   [2020-07-21 20:47:00,384] All MT4 parser operations are finished success (summary code is 0).\nMT4ForexParser.py   L:153  DEBUG   [2020-07-21 20:47:00,384] MT4 parser work duration: 0:00:00.249747\nMT4ForexParser.py   L:154  DEBUG   [2020-07-21 20:47:00,384] MT4 parser work finished: 2020-07-21 20:47:00\n```\n\nThis will give you file ./tests/EURUSD240_old_format_400.csv with the following content (5909 lines in total):\n```\n2009.12.21,00:00,1.4311,1.4347,1.4311,1.4342,5504\n2009.12.21,04:00,1.4342,1.4357,1.4327,1.4334,5234\n2009.12.21,08:00,1.4334,1.4342,1.428,1.4337,8366\n...\n2013.10.18,12:00,1.36918,1.37036,1.3669,1.3678,8193\n2013.10.18,16:00,1.36779,1.36993,1.36773,1.36795,6639\n2013.10.18,20:00,1.36793,1.36849,1.36765,1.36839,1955\n```\n\nLikewise for parsing a file with new format:\n```commandline\nmt4forexparser --mt4-history ./tests/EURUSD240_new_format_401.hst --output ./tests/EURUSD240_new_format_401.csv --debug-level 10 --parse\n```\n\nIf successful, you will receive something like this output:\n```\nMT4ForexParser.py   L:118  DEBUG   [2020-07-21 20:55:42,594] MT4 parser started: 2020-07-21 20:55:42\nMT4ForexParser.py   L:38   DEBUG   [2020-07-21 20:55:42,595] MT4 history file: [./tests/EURUSD240_new_format_401.hst]\nMT4ForexParser.py   L:42   DEBUG   [2020-07-21 20:55:42,675] MT4 history file format version: [401]\nMT4ForexParser.py   L:63   INFO    [2020-07-21 20:55:43,098] It was read 12969 rows from file [./tests/EURUSD240_new_format_401.hst]\nMT4ForexParser.py   L:64   INFO    [2020-07-21 20:55:43,099] Showing last 3 rows:\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:55:43,103]              date   time     open     high      low    close  volume\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:55:43,104] 12966  2019.07.08  08:00  1.12305  1.12339  1.12190  1.12310    8894\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:55:43,104] 12967  2019.07.08  12:00  1.12309  1.12322  1.12123  1.12228    9257\nMT4ForexParser.py   L:69   INFO    [2020-07-21 20:55:43,104] 12968  2019.07.08  16:00  1.12228  1.12240  1.12091  1.12153    7381\nMT4ForexParser.py   L:73   INFO    [2020-07-21 20:55:43,187] Forex history saved to .csv-formatted file [./tests/EURUSD240_new_format_401.csv]\nMT4ForexParser.py   L:148  DEBUG   [2020-07-21 20:55:43,188] All MT4 parser operations are finished success (summary code is 0).\nMT4ForexParser.py   L:153  DEBUG   [2020-07-21 20:55:43,188] MT4 parser work duration: 0:00:00.594304\nMT4ForexParser.py   L:154  DEBUG   [2020-07-21 20:55:43,189] MT4 parser work finished: 2020-07-21 20:55:43\n```\n\nThe file ./tests/EURUSD240_new_format_401.csv will be completely similar and include the same columns: \"date\", \"time\", \"open\", \"high\", \"low\", \"close\", \"volume\" (total 12969 lines):\n```\n2009.12.21,00:00,1.4311,1.4347,1.4311,1.4342,5504\n2009.12.21,04:00,1.4342,1.4357,1.4327,1.4334,5234\n2009.12.21,08:00,1.4334,1.4342,1.428,1.4337,8366\n...\n2019.07.08,08:00,1.12305,1.12339,1.1219,1.1231,8894\n2019.07.08,12:00,1.12309,1.12322,1.12123,1.12228,9257\n2019.07.08,16:00,1.12228,1.1224,1.12091,1.12153,7381\n```\n\nAlso, you can draw an interactive chart (see: [PriceGenerator](https://github.com/Tim55667757/PriceGenerator) library) using `--render` key after `--parse` key:\n```commandline\nmt4forexparser --mt4-history ./tests/EURUSD240_new_format_401.hst --output test.csv --parse --render\n```\n\nAfter running the command above, you will get three files:\n- `test.csv` — .csv-file containing prices (example: [./media/test.csv](./media/test.csv));\n- `index.html` — price chart and statistics drawn using the Bokeh library and saved to an .html-file (example: [./media/index.html](./media/index.html));\n- `index.html.md` — statistics as simple text, saved in markdown format (example: [./media/index.html.md](./media/index.html.md)).\n\n![](./media/index.html.png)\n\n\n### Using import\n\nLet's look an example of parsing a history file of a new format (version 401 for MetaTrader 4) ./tests/EURUSD240_new_format_401.hst:\n```\nfrom mt4forexparser.MT4ForexParser import MT4ParseToPD as Parser\n\n# Parsing historical candles and save the data into a pandas dataframe variable.\n# To save candles to a file, you can specify the variable outputFile=\"./tests/EURUSD240_new_format_401.csv\"\n# If the variable outputFile is not specified, the module will only return data in pandas dataframe format.\ndf = Parser(historyFile=\"./tests/EURUSD240_new_format_401.hst\")\nprint(df)\n```\n\nAt run we get a completely similar output:\n```\n...\n\u003e\u003e\u003e print(df)\n             date   time     open     high      low    close  volume\n0      2009.12.21  00:00  1.43110  1.43470  1.43110  1.43420    5504\n1      2009.12.21  04:00  1.43420  1.43570  1.43270  1.43340    5234\n2      2009.12.21  08:00  1.43340  1.43420  1.42800  1.43370    8366\n3      2009.12.21  12:00  1.43370  1.43710  1.43300  1.43330    8456\n4      2009.12.21  16:00  1.43320  1.43350  1.42860  1.42940    8488\n...           ...    ...      ...      ...      ...      ...     ...\n12964  2019.07.08  00:00  1.12230  1.12293  1.12192  1.12204    3455\n12965  2019.07.08  04:00  1.12205  1.12307  1.12203  1.12307    4173\n12966  2019.07.08  08:00  1.12305  1.12339  1.12190  1.12310    8894\n12967  2019.07.08  12:00  1.12309  1.12322  1.12123  1.12228    9257\n12968  2019.07.08  16:00  1.12228  1.12240  1.12091  1.12153    7381\n```\n\n\nI wish you success in the automation of exchange trading! ;)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim55667757%2Fmt4forexparser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftim55667757%2Fmt4forexparser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftim55667757%2Fmt4forexparser/lists"}