MT5 Expert Advisors on GitHub: Source Code, Licences, Tests
Yes, GitHub hosts MT5 expert advisors: search for repositories that contain .mq5 files and you will find complete projects, single-file examples and abandoned experiments side by side. What you download is source code to read, compile in MetaEditor and test yourself, not a tested strategy or a trading result. An MT5 expert advisor from GitHub is worth running only after four checks:
- Licence: a public repository is not automatically free to reuse; the licence file decides.
- Completeness: include files and Git submodules are often missing from a ZIP download.
- Logic: what the code actually trades, how it sizes positions, whether it imports DLLs or makes web requests, and what it does after a rejected order or a restart.
- Evidence: your own Strategy Tester run and demo record, because stars, forks and screenshots prove nothing about results.
Where to find MT5 expert advisor source code on GitHub
Search GitHub for terms such as 'mt5 expert advisor', 'mt5 ea' or 'mt5 scalping ea', then use code search to find files ending in .mq5, the MT5 source extension. A repository that holds only a README and a download link is a distribution page, not source code. What the files tell you:
| File | What it is | What it does not prove |
|---|---|---|
.mq5 | The main editable MT5 source file | That the project is complete or compiles |
.mqh | An include file with functions or classes | That every dependency is in the repository or has been reviewed |
.ex5 | The compiled MT5 program | Anything about the source or future results; you cannot read or safely edit it |
.set | Saved input values for one EA | Trading logic, or that the values suit your account and broker |
Then check the repository itself: a licence file, a README that states the platform and the strategy, recent commits and how open issues are answered. Scalping EAs need extra care, because their results hinge on spread, commission and execution speed that a backtest does not fully reproduce. A repository labelled as a trading bot for MT5 tells you nothing about its risk handling by the label alone.
A worked example: one MT5 repository pinned to a commit
As a worked example, we pinned the public EA31337/EA31337 repository on GitHub, a project for MT4 and MT5. The source we checked on 15 October 2026 is commit 9b9bd38c4e49dd6916f4fe3936e50e97fca7a692, dated 19 September 2024, which was also the master commit at the time. We read its README, licence, submodule manifest, build file and MT5 entry point. We did not compile it, run the Strategy Tester or forward test it, so nothing here is a performance claim or a recommendation.
| What we looked at | What it shows |
|---|---|
| LICENSE | The repository includes the GNU GPL version 3 text. Dependencies can carry their own terms. |
.gitmodules | Framework classes, indicators and strategies live in separate repositories, so the main ZIP is not a complete build checkout. |
src/EA31337.mq5 | The MT5 entry point includes other files and hands tick processing to an EA object; this file is not the whole trading system. |
| Makefile | The build has its own mode, toolchain and resource requirements, so copying one file into MetaTrader is not enough. |
To get exactly that source tree, with its four code submodules (src/include/classes, src/indicators, src/strategies and src/strategies-meta) at their pinned commits rather than whatever the default branch holds today, run these commands in a working directory you control:
git clone --no-checkout https://github.com/EA31337/EA31337.git
cd EA31337
git checkout --detach 9b9bd38c4e49dd6916f4fe3936e50e97fca7a692
git submodule update --init --recursive
git rev-parse HEAD
git submodule status --recursiveKeep the output of the last two commands with your notes; in the submodule status, a leading minus sign marks a submodule that is not initialised and a plus sign one that differs from the pinned commit. The commands fetch source only. In the entry file, OnInit() builds the EA object and its strategies and OnTick() passes each tick to ea.OnTick(...), so the signal, order and position logic sits in the included components. A risk input in the settings does not prove that an account-wide loss limit is implemented correctly.
Compiled .ex5 downloads versus source you can read
Most searches for a free MT5 EA, free EA code for MT5 or an MT5 EA source code free download end on one of four kinds of file, with very different risks:
- Open-source projects with a licence. You can read and compile every line. The licence sets what you may do with it, and all of the testing is yours.
- Compiled .ex5 files offered as a free download. Forum posts, download sites and chat groups share these. Without the source you cannot see what the program does, whether it opens network connections or how it behaves after a loss.
- Free versions with conditions. Some free expert advisors are tied to one broker, limited in lot size or symbols, or exist to sell a paid upgrade.
- Copies of paid EAs. These are usually a licence violation, and you cannot know whether the file was altered. Leave them alone.
That is also why no honest list can name one best free MT5 EA, or one best expert advisor for MT platforms: the answer depends on the symbol, broker, account type and loss limits you trade under. A free file is worth testing only if its entries, exits, stop loss and sizing are described, it uses no grid or martingale sizing, and any results state the period, symbol and costs so you can reproduce them. Our guide to the best free MT4 expert advisor shows how to judge a free EA before you trust it.
Is a public GitHub repository free to use?
Not automatically. Without a licence file, visibility alone gives you no right to copy, modify or redistribute the code. A licence such as the GNU GPL version 3 allows use and modification, with conditions when you distribute the code or a changed version of it, and every dependency can carry its own licence.
Searching for one named EA
Some searches name a single free EA, for example a Nyao Scalper v43.0 download. We have not reviewed that file and make no claim about its source, licence or results. Ask of any named EA who published the original, whether the source and a licence come with it, and what it does on a demo account you control; with no traceable publisher, treat it as unknown software.
How to install an MT5 EA from GitHub and compile it
- Get the complete source. Clone the repository with its submodules, or use a release archive that states it includes them. A plain ZIP of the main branch can miss included files.
- Open the data folder. In MetaTrader 5, choose File, then Open Data Folder. Expert advisors live in the Experts folder within it; place the project folder there and keep the paths its include lines expect.
- Compile in MetaEditor. Open the main
.mq5file and compile it; a successful compile writes an.ex5next to it. Read every warning instead of treating zero errors as a finished review. - Attach it to a chart. Drag the EA from the Navigator onto the chart of the symbol it was written for, set the inputs and allow algorithmic trading for it. Watch the Experts and Journal tabs for errors.
- Test before any real account. Run it in the MetaTrader 5 Strategy Tester with realistic costs and an unseen period kept back, then on a demo account long enough to see it handle news, gaps and a restart.
If the EA loads but places no trades, the cause is usually permissions, symbol names, volume limits or stop distances. Our guide to an MT5 expert advisor not working goes through those checks in order.
Simple MT5 expert advisor code for gold trading
Every MT5 expert advisor is built on three event handlers. OnInit() runs when the EA loads: validate the inputs and create indicator handles there. OnTick() runs on new ticks for the chart's symbol, though a new tick event is not queued while the previous one is still waiting or being processed. OnDeinit() runs when the EA is removed or reinitialised, for example after an input change, and releases resources.
Two details catch most people who copy code from GitHub. An indicator function such as iMA() returns a handle, not a value; the values come from CopyBuffer(). And a successful trade call is not a fill: check the result code and the resulting position. On a hedging account several positions can exist per symbol, so code that selects one position can miss part of the exposure.
Gold adds its own traps. The symbol is XAUUSD at many brokers but GOLD, or XAUUSD with a suffix, at others, so never hardcode it. Contract size, tick value, minimum lot, volume step and minimum stop distance all differ between brokers, so read them from the symbol at runtime instead of copying numbers from someone else's code. Gold spreads often widen around major news releases and the daily rollover, which matters most for scalping code.
The sketch below reads two moving averages on closed H1 bars and prints a signal once per new bar. It deliberately sends no orders: it is a reading aid, not a strategy, and we have not compiled or run it for this article.
#include <Trade\Trade.mqh>
input int FastPeriod = 20; // fast EMA period
input int SlowPeriod = 50; // slow EMA period
input ulong MagicNumber = 240501; // tags this EA's positions
CTrade trade;
int fastHandle = INVALID_HANDLE;
int slowHandle = INVALID_HANDLE;
datetime lastBar = 0;
int OnInit()
{
if(StringFind(_Symbol, "XAU") < 0 && StringFind(_Symbol, "GOLD") < 0)
Print("Note: attached to ", _Symbol, ", this sketch expects a gold symbol");
fastHandle = iMA(_Symbol, PERIOD_H1, FastPeriod, 0, MODE_EMA, PRICE_CLOSE);
slowHandle = iMA(_Symbol, PERIOD_H1, SlowPeriod, 0, MODE_EMA, PRICE_CLOSE);
if(fastHandle == INVALID_HANDLE || slowHandle == INVALID_HANDLE)
return(INIT_FAILED);
trade.SetExpertMagicNumber(MagicNumber);
return(INIT_SUCCEEDED);
}
void OnDeinit(const int reason)
{
IndicatorRelease(fastHandle);
IndicatorRelease(slowHandle);
}
void OnTick()
{
datetime bar = iTime(_Symbol, PERIOD_H1, 0);
if(bar == lastBar) return; // once per new H1 bar
double fast[2], slow[2]; // [0] older closed bar, [1] last closed bar
if(CopyBuffer(fastHandle, 0, 1, 2, fast) != 2) return;
if(CopyBuffer(slowHandle, 0, 1, 2, slow) != 2) return;
lastBar = bar; // only after the data was read
if(fast[0] <= slow[0] && fast[1] > slow[1]) Print("Buy signal on ", _Symbol);
if(fast[0] >= slow[0] && fast[1] < slow[1]) Print("Sell signal on ", _Symbol);
// A trading version would size the volume from the symbol's tick value,
// check the volume step and minimum stop distance, call trade.Buy() or
// trade.Sell() with a stop loss, then read trade.ResultRetcode().
}Reading the signal on closed bars means it cannot change after it prints; a value from the forming bar can. A tradable version still needs position sizing from the account's risk, a stop loss on every order, handling for rejected requests, a restart rule and limits that match the account's loss rules, which is where most free code is weakest.
Can a free or GitHub EA run on a prop firm challenge?
Only where the firm allows expert advisors on that exact programme and account size, and only if the code respects that programme's loss formula. Permissions differ from firm to firm and some ban automation outright, so check our overview of which prop firms allow EAs and the firm's own rule page, not the repository's README. A generic free EA built for raw profit usually checks none of those limits, and even a well-built one cannot remove gaps, slippage or a broker outage between a close request and the fill. Test the loss logic on a demo with the firm's daily reset time and baseline before you run it on an evaluation.
When a licence beats maintaining repository code
GitHub is the right place if you want to read, change and own the code, and all of the compiling, testing and fixing stays with you. If you are a prop-firm trader on MT4 or MT5 who keeps failing evaluations on the daily loss or drawdown rules, maintaining an open-source EA becomes a second job. The JPTC EA Hub is the licensed alternative: a paid one-time licence for expert advisor software you download and run on your own MT4 or MT5 terminal, with configurable setfiles and limits built around prop-firm risk rules. Its limits are part of the decision:
- It does not promise a pass, a payout or profit. Enabled limits can stop new entries and request closure of open positions, but they cannot guarantee an execution price or prevent every breach.
- A firm preset or name is not proof of compatibility or approval. Check which programme, phase and account version a setfile was set up for, and under which test conditions; where that is not stated, treat it as a starting point and run it on a demo first.
- It is not for Topstep or Apex accounts, and JPTC does not run it for you: you keep your own terminal running on a reliable PC or VPS.
For automation on your own capital instead, the separate hosted Algo runs on JPTC's infrastructure, connected to your own broker account, with nothing to install and no VPS. It is built to grow your own account, with no promised return, and is not offered for prop-firm evaluations. Its monthly figures on JPTC's results page are company-published from the broker statement, not an independent audit, and are no evidence for any GitHub EA or setfile.
Would you rather load a configurable setfile than keep a repository compiling and tested? Compare the current EA Hub versions and terms on the product page: See the JPTC EA Hub.
FAQ
Can I convert an MT4 EA from GitHub to MT5?
Can I edit an .ex5 file?
Can I run a GitHub EA next to other EAs on the same account?
Forex & Gold Signals, No Monthly Fee
Entry, stop loss and targets on every trade we take. It costs you nothing: open an account through one of our partner brokers and they cover it for you. You place every trade on your own account.
Join the signals channel