Enhancing MetaTrader 5 Development with GitHub: A Step-by-Step Guide for Mac

Meta Trader 5 is a great tool for retail traders to develop, test and live trade their custom trading strategies. Coming from a software development background I found it odd that there was not an easy way to integrate with a source control tool such as GitHub. In this article I'll show you the exact steps required to setup the integration so you can ensure all your code is safely committed and pushed to GitHub.
Getting Started
First of all, make sure you have the latest version of Meta Trader 5 installed. This guide works on Windows and Mac but some of the steps are slightly different. Also make sure you have the GitHub client installed, this is especially important on Windows as it doesn't come pre-installed.
Step 1: Create an empty repository
Open up a terminal window and change directory by running the following:
cd ~/Library/Application\ Support/net.metaquotes.wine.metatrader5/drive_c/Program\ Files/MetaTrader\ 5/MQL5
A recent update to MT5 has changed the location of this directory on the Mac. If you're struggling to find the directory try these steps:
- Open the Finder app and from the menu click on Go
- Hold down the Option key and select Library
- Scan through the items inside Application Support for anything relating to Meta Trader or Meta Quotes
Unfortunately, the MT5 app on the Mac is an emulated version of the Windows app so it's notoriously difficult to track down the correct directory.
Once you're in the correct place, you should see the following after running ls -l
:
drwxr-xr-x 6 jwfranklin staff 192 21 Feb 13:59 Experts
drwxr-xr-x 2 jwfranklin staff 64 21 Feb 14:00 Files
drwxr-xr-x 4 jwfranklin staff 128 21 Feb 13:21 Images
drwxr-xr-x 23 jwfranklin staff 736 21 Feb 14:00 Include
drwxr-xr-x 5 jwfranklin staff 160 21 Feb 16:07 Indicators
drwxr-xr-x 2 jwfranklin staff 64 21 Feb 13:22 Libraries
drwxr-xr-x 4 jwfranklin staff 128 21 Feb 13:22 Logs
drwxr-xr-x 8 jwfranklin staff 256 21 Feb 13:25 Profiles
drwxr-xr-x 5 jwfranklin staff 160 21 Feb 16:05 Scripts
drwxr-xr-x 2 jwfranklin staff 64 21 Feb 13:25 Services
drwxr-xr-x 2 jwfranklin staff 64 21 Feb 13:21 Shared Projects
-rw-r--r-- 1 jwfranklin staff 169760 21 Feb 13:21 experts.dat
Now we can initialise the repository:
git init
Step 2: Exclude MT5 files
MT5 comes pre-installed with a bunch of files that you won't want to commit to your repository. Excluding these files in a particular way will allow you to exclude them but include your own files and directories.
Below is a .gitignore
file that excludes everything you don't want to commit with a list of exclusions which allows you to commit your own code. Copy and paste this into a new file called .gitignore
and save.
Towards the end of the file replace NAME
with your name or something to uniquely identify your code. Use it a bit like a namespace that belongs to you.
- Copy and paste
.gitignore
file - Replace NAME with your name or something to uniquely identify your own code
# exclude compiled files
*.ex5
*.dat
# exclude directories completely
Images
Libraries
Logs
Profiles
Services
"Shared Projects"
# exclude directory contents
Experts/*
Files/*
Include/*
Indicators/*
Scripts/*
# except for directories
!Experts/NAME
!Files/NAME
!Include/NAME
!Scripts/NAME
!Indicators/NAME
Step 3: Create a new remote repository
Head over to GitHub and create an empty and private repository. Choose a repository name, make sure you select Private and click Create Repository.

Copy the new remote URL

Then add the new remote to your local repository by running the following:
git remote add origin git@github.com:[GITHUBUSER]/mt5.git
Step 4: Review files to commit
Before you commit and push your changes make sure the .gitignore
has successfully excluded the files and directories we don't want to commit. With a completely empty repository you'll only be committing the .gitignore
file and any files and directories that exist under the rules you've stated in the .gitignore
file:
> git status
On branch main
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
nothing added to commit but untracked files present (use "git add" to track)
The output shows that only the .gitignore
file is being committed and all of the pre-installed MT5 files and directories have been excluded.
Step 5: Commit and push local changes
All that's left to do is add the .gitignore
file, commit and push to your new repository:
git add .gitignore
git commit -m "Initial commit"
git push -u origin main
Wrap up
With all this completed you're now able to add our own custom expert advisors, indicators and other files to your new repository. You can easily share the repository with your team and keep everything synchronised with GitHub.