How to publish code to CodeBase: A practical guide
Contents
- Introduction
- General rules and recommendations for posting codes
- How to load the code directly from MetaEditor 5
- Script
- Indicator
- Service
- Simple Expert Advisor
- Code Base
- EA with the include file and indicator
- Conclusion
Introduction
CodeBase is the largest repository of free programs for the MetaTrader 5 and MetaTrader 4 platforms. Here, traders and developers can share their scripts, indicators, EAs, and other useful tools written in MQL5. Publishing your own code to CodeBase is a great way to contribute to the community, get feedback, build your reputation, and even attract potential clients.
In this article, we will look at publishing various types of programs in CodeBase: from simple scripts and indicators to EAs with include files. Using real-life examples, we will focus on step-by-step process of publishing each type of program. The article will be useful for those who have decided to post their works for public use for the first time. We will provide general recommendations for publication design – texts and images, codes and attached files.
General rules and recommendations for publishing codes
By publishing code in CodeBase, we share our work with the community, allowing them to use our source code in the terminal "as is" or in their own developments. We also give people the opportunity to see how everything works from the inside, gain additional knowledge, and study the algorithms and logic behind a particular program.
To publish your code in CodeBase, you only need to follow a few simple steps and adhere to these simple rules:
- before publishing, tidy up the codes by creating neat formatting (Ctrl + , in the editor);
- comment on key decisions in the program logic;
- prepare images up to 750x500 pixels in size that explain how your program works;
- come up with a good, concise description of the program and its settings and parameters.
This way, your code will be understandable both for others and for yourself if you return to it in, say, six months. It is much easier to support and improve such projects.
If you are publishing an EA, it is worth checking it in advance using the checklist in the article "The checks a trading robot must pass before publication in the Market". This will eliminate typical errors and make the code more professional.
The process of publishing source code itself is quite simple and straightforward.
- Follow the link to the source code base and click the green "Submit your code" button.
- Fill in the fields:
- Subject — indicate the name of the program that clearly reflects its essence and purpose. This name will be displayed in the list of programs on the main page of the CodeBase section.
- Language — select the language the program is written in: MQL5 or MQL4.
- Account type — specify the account type the program can work correctly on.
- Categories — select the correct type of program to be published.
- Click "Create a code"
-
The system will prompt you to review the rules for formatting code and text. After reading, check the boxes and save.
Next, a page will open where you need to write a description of the program and attach all the necessary project files.
Code Description
- "Short description". Enter a short and concise description of your program. Its text will be displayed on the main CodeBase page under the name of the published program. Describe the very essence of the code you are publishing so that the purpose of your code is immediately clear to users.
- Field for entering code description. Fill out this section with detailed information about the functionality, features and usage: what it is intended for, and what problems it solves. If there are input parameters, describe them using bulleted or numbered lists. Do not forget about the possibility of attaching images that clearly demonstrate the program operation and use. Stick to the general presentation guidelines when publishing programs on mql5.com.
Adding project files
Click "Attach file". The buttons for selecting the file and its location will appear:

Click "Browse..." and select the source code file for the program you want to publish. Its name will appear to the right of the button. If your project consists of multiple files, you will need to add each one to the list of attachments one by one.
When adding files, pay special attention to the Location drop-down list to the right of the name of each added file. Here you can specify the folder in the editor where the published code for the selected file should be placed after downloading. There are three options:
- Default — the file is placed in the Downloads subfolder in the standard directory for the selected program type:
- Script → Scripts\Downloads,
- Indicator → Indicators\Downloads,
- EA → Experts\Downloads,
- Service → Services\Downloads,
- Library → The "Default" option for libraries is not used.
- <MQL5\Include> directory - the file will be located in the root directory of included files. It is logical to place libraries and included files in the Include folder, but only in the simplest cases. Putting everything directly in the root of this folder will quickly become an unstructured storage area. Therefore, this option is controversial and undesirable.
- <MQL5> custom directory — here we specify the exact path to the file location relative to the MQL5\ directory. This is the most competent way. Here you specify the path relative to the MQL5 folder and structure the project so that everything is clear to both the author and users.
In large projects that use many included files and libraries, we should choose this option and correctly specify all paths for included files. This will allow you to properly arrange your project files, maintaining the file structure, and will allow the validator to correctly position them for error-free compilation.
General recommendations for storing and specifying published files
Each project must have one executable file (source file extension *.mq5). Always place the sources of *.mq5 executable files in the default folders. Placing source codes of executable files in subfolders is not allowed.
If the executable file uses custom include files or libraries (*.mqh files), then place them in the Include\ folder and its subfolders. Place custom indicators used in the published EA in the folders referenced in the iCustom() source code. To do this, select the third method for specifying the file location - "<MQL5> custom directory".
Files that are located in default folders during publication will be located in the Downloads\ subfolder of the default location directory after they are downloaded from MetaEditor 5.
Suppose that a user wants to publish their EA named ExpMAFractals.mq5 containing the ExtFile.mqh include file (not included in the standard terminal distribution). If they specify the Default EA location path, while the include file is sent to "<MQL5\Include> directory", then the EA is located in
(MQL5\) Experts\Downloads\ExpMAFractals.mq5
While the include file path is
(MQL5\) Include\ExtFile.mqh
Thus, when loading the files of this project from CodeBase into MetaEditor 5, the user will have the ExpMAFractals.mq5 file in the MQL5\Experts\Downloads\ directory, while the include file ExtFile.mqh will be located in the standard MQL5\Include directory of the client terminal.
We can also place the include file not in the Include\ root, but by specifying its location in a subfolder, for example, \MAFractals\. To do this, set the location of the include file to "<MQL5> custom directory" and specify the path relative to MQL5\ : Include\MAFractals\. In this case, the location folder of the include file will have the path -
(MQL5\) Include\MAFractals\ExtFile.mqh
In any case, it is always necessary to structure your projects, placing files in convenient and correct locations, and specifying exactly the paths that the executable file should use to read them correctly after loading your project from CodeBase.
Be sure to attach at least one image up to 750x500 in size to your description. Be sure to follow the recommendations in the article "Tips for effective product presentation on the Market" when preparing your images.
After filling out the description and attaching all project files, click the "Save" button and you will be prompted to submit the code for verification to the auto validator in the left panel:

Click Ready and wait a bit until the validator finishes its work.
Once the test is completed, you will receive an automatic message in your personal account about the results, and the Publish button will be activated:

If a validation error occurs, you will receive a report indicating the reasons for the errors. Correct them and resubmit the code for verification. To correct errors reported by the validator, follow the recommendations in the article "The checks a trading robot must pass before publication in the Market".
Once successfully published, your code will be available for download via the link to CodeBase, or directly from MetaEditor 5, which is more convenient than downloading archives from the website and manually placing them in the correct folders in the MQL5 directory.
How to load the code directly from MetaEditor 5
To download a program from the CodeBase in MetaEditor 5, open the Code Base tab of the Toolbox panel (Ctrl + T), find the required program in the list and press "D", or select Download in the context menu. The program and all files required for its compilation will be downloaded into the editor, and the program will be automatically compiled:

The code of the downloaded program will be opened in a new tab of the editor window.
To see where the file was downloaded, press Alt + N, and the navigator will expand the file tree branches to the desired program:

We can also use the search by the name of the necessary program. To do this, go to the Search tab, or press "F" in the list of library programs, or select Search in the context menu. In any case, the Search tab will open, where you need to select Code Base as the search source, enter the name of the program you are looking for in the search input field and press Enter.
The program will be displayed on the tab and the download button will become active after the link to the program in Code Base. After clicking the button, the program and all its include files will be loaded into the code editor:

The code of the downloaded program will be opened in a new tab of the editor window.
To see where the file was downloaded, press Alt + N, and the navigator will expand the file tree branches to the desired program:

Let's now look at the process of publishing different types of programs in CodeBase using specific examples.
Script
As an example, we will publish a script that removes all auto trading icons from the current chart.
- In the program name field, enter "Delete Trading History",
- Language — MQL5,
- Account type — Any,
- Categories — Scripts.
Click "Create a code". On the next two pages, check the boxes to confirm you have read the publication rules and click Save. A new page will open where we need to add a brief description of the program, its files, the path in the terminal directory, and a full description:
- In the short description field, enter a short description of the script to be displayed in the announcement on the main page of CodeBase;
- "Browse..." button — select the script file in the MetaEditor 5 directory;
- Location — select Default;
- In the code description field, enter a full description of the published script.
Be sure to attach at least one image up to 750x500 in size. Click Save and submit the code for verification. Wait till the validator finishes checking the code.
Once the code is successfully verified, you can publish it. Once published, the script will be available in the code editor for all users of mql5.com.
When loading the code from MetaEditor 5, the script will be downloaded to MQL5\Scripts\Downloads\:

You can see the script in CodeBase.
Indicator
We will publish an indicator that displays Pin Bar Price Action pattern icons on the chart.
- In the program name field, enter Find Pin Bars,
- Language — MQL5,
- Account type — Any,
- Categories — Indicators.
Click "Create a code". On the next two pages, check the boxes to confirm you have read the publication rules and click Save.
A new page will open where you need to add a brief description of the program, its files, the path in the terminal directory, and a full description.
- In the short description field, enter a short description of the indicator, which will be displayed in the announcement on the main page of CodeBase;
- "Browse..." button — select the indicator file in the MetaEditor 5 directory;
- Location — select Default;
- In the code description field, enter a full description of the published indicator.
Be sure to attach at least one image up to 750x500 in size. Click the Save button and send the code to the auto validator for verification. Wait for the code to be verified.
Once the code is successfully verified, you can publish it. Once published, the indicator will be available in the code editor for all mql5.com users.
When loading the code from MetaEditor 5, the indicator will be downloaded to the MQL5\Indicators\Downloads\ folder:

You can see the indicator in CodeBase.
Service
Let's publish a service program that creates a custom USD index symbol. The service consists of the main program USD_Index.mq5 and the include file CurrencyIndex.mqh located in the program directory.
- In the program name field, enter USD Index,
- Language — MQL5,
- Account type — Any,
- Categories — Services.
Click "Create a code". On the next two pages, check the boxes to confirm you have read the publication rules and click Save.
A new page will open where we need to add a brief description of the program, its files, the path in the terminal directory, and a full description:
- In the short description field, enter a short description of the service, which will be displayed in the announcement on the main page of CodeBase;
- "Browse..." button
- select the service file in the MetaEditor directory (USD_Index.mq5)
- for Location, select Default
- select the included file in the MetaEditor directory (CurrencyIndex.mqh)
- for Location, select Default
- for Location, select Default
- select the service file in the MetaEditor directory (USD_Index.mq5)
- In the code description field, enter a full description of the published service.
Be sure to attach at least one image up to 750x500 in size. Click Save and submit the code for verification. Wait till the validator finishes checking the code.
Once the code is successfully verified, you can publish it. Once published, the service will be available in the code editor for all mql5.com users.
When loading the code from MetaEditor 5, the USD_Index.mq5 service and CurrencyIndex.mqh include file will be downloaded to the MQL5\Services\Downloads\ folder:

You can see the service in CodeBase.
Simple Expert Advisor
Publish an EA that opens positions using two standard indicators: an oscillator and a trend indicator.
- In the program name field, enter the name "Simple EA based on WPR, Bollinger Bands and ATR",
- Language — MQL5,
- Account type — Hedged,
- Categories — Experts.
It should be noted here that the account type should be selected based on the account type, on which the EA should work and for which it was created.
Click "Create a code". On the next two pages, check the boxes to confirm you have read the publication rules and click Save. A new page will open where you need to add a brief description of the program, its files, the path in the terminal directory, and a full description.
- In the short description field, enter a short description of the EA, which will be displayed in the announcement on the main page of CodeBase;
- "Browse..." button — select the EA file in the MetaEditor 5 directory;
- For Location, select Default;
- In the code description field, enter a full description of the published EA.
Be sure to attach at least one image up to 750x500 in size.
Click the Save button, send the code to the auto validator for verification and wait until the code is verified.
In case of testing errors, an error report will be available. All errors that occur during automatic code checking must be corrected in accordance with the article "The checks a trading robot must pass before publication in the Market".
Once the code is successfully verified, you can publish it. Once published, the EA will be available in the code editor for all mql5.com users.
When loading the code from MetaEditor 5, the EA will be downloaded to the MQL5\Experts\Downloads\ folder:

You can see the EA in CodeBase.
Library
We will publish a class library that allows you to add a trailing StopLoss to any EA.
- In the subject field, enter "StopLoss trailing class library for MQL5",
- Language — MQL5,
- Account type — Any,
- Categories — Libraries.
Click "Create a code". On the next two pages, check the boxes to confirm you have read the publication rules and click Save. A new page will open where you need to add a brief description of the program, its files, the path in the terminal directory, and a full description.
To publish libraries, we need at least two files — the library file with the *.mqh extension and the source code of the executable file with the *.mq5 extension.
- In the short description field, enter a short description of the library, which will be displayed in the announcement on the main page of CodeBase;
- "Browse..." button — select the library file in the MetaEditor 5 directory.
- For Location, select "<MQL5> custom directory", in the address input field, enter the path to the file relative to the MQL5\ folder: "Include\Trailings\".
- "Browse..." button — select the source file of the executable file in the MetaEditor 5 directory.
- For Location, select "<MQL5> custom directory", in the address input field, enter the path to the file relative to the MQL5\ folder: "Experts\Trailings\".
- In the code description field, enter a full description of the published library.
Be sure to attach at least one image up to 750x500 in size. Click the Save button, send the code to the auto validator for verification and wait until the code is verified.
In case of testing errors, an error report will be available. All errors that occur during automatic code checking must be corrected in accordance with the article "The checks a trading robot must pass before publication in the Market".
Once the code is successfully verified, you can publish it. Once published, the library will be available in the code editor for all mql5.com users.
When loading the code from MetaEditor 5, the library will be downloaded to MQL5\Include\Trailings\ folder:

The source code of the test EA will be located in the MQL5\Experts\Trailings\ folder:

If we had used "<MQL5\Include> directory",
while selecting Default for the EA, they would have been placed in the following folders when loading files from the editor:


This is inconvenient: the library is located in the root of Include, which clutters this directory, and the test EA is located in the Libraries\Downloads\ library folder, which is logical but inconvenient, since this file is not a library, but an EA.
You can see the library in CodeBase.
EA with the include file and indicator
Let's publish an EA which uses custom indicator signals and trailing library.
- In the subject field, enter "ExpPinBar — Pin bar price action pattern EA",
- Language — MQL5,
- Account type — Hedged,
- Categories — Experts.
Click "Create a code". On the next two pages, check the boxes to confirm you have read the publication rules and click Save.
A new page will open where you need to add a brief description of the program, its files, the path in the terminal directory, and a full description. Here, we will need to attach all files used by the EA, specifying the correct paths to them.
- In the short description field, enter a short description of the EA, which will be displayed in the announcement on the main page of CodeBase;
- Attach three project files:
- EA file:
- "Browse..." button — select the EA file in the MetaEditor 5 directory,
- For Location, select Default;
- Indicator file:
- "Browse..." button — select the indicator file in the MetaEditor 5 directory,
- For Location, select "<MQL5> custom directory", enter the path to the file relative to the MQL5\ folder: "Indicators\PriceAction\";
- Library file:
- "Browse..." button — select the library file in the MetaEditor 5 directory,
- For Location, select "<MQL5> custom directory", in the address input field, enter the path to the file relative to the MQL5\ folder: "Include\Trailings\".
- In the code description field, enter a full description of the published EA.
Be sure to attach at least one image up to 750x500 in size.
Click the Save button, send the code to the auto validator for verification and wait until the code is verified.
In case of testing errors, an error report will be available. All errors that occur during automatic code checking must be corrected in accordance with the article "The checks a trading robot must pass before publication in the Market".
Once the code is successfully verified, you can publish it. Once published, the EA and all its include files will be available for download in the code editor for all mql5.com users.
When loading the code from MetaEditor 5, the EA will be downloaded to the MQL5\Experts\Downloads\ folder:

The indicator file will be downloaded to the MQL5\Indicators\PriceAction\ folder:

The library file will be downloaded to MQL5\Include\Trailings\:

As we can see, with this variant of project files' location, all of them were placed in the correct folders when loaded from the MetaTrader 5 editor, and the EA project itself compiled without errors.
You can see the EA in CodeBase.
Conclusion
Provide a clear, concise, and accurate description of the code you publish, and give it a descriptive name. Check out these articles for comprehensive recommendations on formatting text, names, and descriptions for your codes:
- Tips for effective product presentation on the Market
- How to publish a product on the Market
- Market Product rating calculation now includes description quality
Follow the recommendations from these sources so that your codes in Code Base remain easy to read and professional, while the description is neat, precise and comprehensive.
Let's sum it up:
When publishing your work, you need to correctly specify the paths to the files of your projects so that users can easily download them directly from the code editor.
- If this is a separate source file for a standalone program, you can select its default location.
In this case, when downloaded, the file will be placed in the terminal folder corresponding to the program category, where the Downloads subfolder will be created.
It is there that you can find the file downloaded from CodeBase. - If this is an include file or a library of functions or classes, you can choose to locate the file in the terminal Include\ folder, but in this case the file will be placed in the root of that folder, which will clutter its contents.
It is better to place such files in subfolders of the Include directory, which allows the third method of specifying the location of downloaded files. - If you have a large project, for example, an EA with various include files, then you need to specify the exact location of each file in your project relative to the MQL5\ directory. The location of the executable file itself should be set to Default. In this case, the Downloads subfolder will be created for it in the directory corresponding to the program category.
This way, your project will be fully structured and correctly loaded into the appropriate project folders.
Please note that to publish libraries, you need at least two files: a library code file with the *.mqh extension and a test program file (script/indicator/EA/service)
with the *.mq5 extension.
The 'Default' location is not supported for libraries. Specify either the MQL5\Include\ folder (second option) or the full path relative to the MQL5\ directory (third option when choosing a location).
Translated from Russian by MetaQuotes Ltd.
Original article: https://www.mql5.com/ru/articles/19441
Warning: All rights to these materials are reserved by MetaQuotes Ltd. Copying or reprinting of these materials in whole or in part is prohibited.
This article was written by a user of the site and reflects their personal views. MetaQuotes Ltd is not responsible for the accuracy of the information presented, nor for any consequences resulting from the use of the solutions, strategies or recommendations described.
Market Simulation (Part 03): A Matter of Performance
Price Action Analysis Toolkit Development (Part 44): Building a VWMA Crossover Signal EA in MQL5
Reusing Invalidated Orderblocks As Mitigation Blocks (SMC)
Building AI-Powered Trading Systems in MQL5 (Part 4): Overcoming Multiline Input, Ensuring Chat Persistence, and Generating Signals
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use