Watch how to download trading robots for free
Find us on Telegram!
Join our fan page
Access the CodeBase from your MetaTrader 5 terminal
Couldn't find the right code? Order it in the Freelance section
How to Write an Expert Advisor or an Indicator

MQL5 Source Codes of Scripts for MetaTrader 5

icon

Scripts perform one-time actions in MetaTrader 5 using an MQL5 program and are deleted from the chart immediately afterwards. Sample functions include uploading trading history, generating a report and sending it by email, downloading and processing data from a file. Scripts can also be used to create graphical interface or quickly execute single-type trading operations, for example, close all positions immediately.

You can download and launch offered scripts in MetaTrader 5. The library of scripts is also available directly from MetaEditor development environment allowing you to learn MQL5 programming.

Submit your code
latest | best

This Screener was created to simplify the process of finding assets trading at discounted prices. Initial usage may take slightly longer due to the data loading process for all selected instruments. The tool can scan all available broker assets or be limited to specific asset classes.

This function performs the main logic of opening a trade. It calculates the opening price, take profit levels and stop loss based on the symbol information and parameters provided by the user. Prepare a trade request (MqlTradeRequest) with the necessary information such as symbol, volume, order type, slippage, comment, magic number, etc. Call the OrderSend function to send the trade request and get the result. SetTypeFillingBySymbol function: determines the order fulfilment type (Fill or Cancel, Immediate or Cancel or Return) according to the symbol's fulfilment policy. GetMinTradeLevel function: calculates the minimum trade level based on the freeze level and stop level of the symbol. Adjusts the minimum level to ensure that it is within certain limits and returns the result.

Functions for use instead of ChartXYToTimePrice and ChartTimePriceToXY, working correctly and quickly over the entire range of input parameters

The script calculates the autocorrelation and partial autocorrelation functions and displays them on a graph

Script for displaying updating data on open positions.

The script provides a set of functions for creating all standard graphical objects for use in your own developments. The functions presented in the script can be used "as is" or modified to your requirements.

This script helps traders understand the distribution and breadth of candlesticks over a specific period, which can be useful in making trading decisions such as which Take Profit or Stop Loss to use based on historical values.

The Clean Market Watch script is a simple utility tool designed to quickly remove all symbols from your MetaTrader 5 Market Watch window with a single click. This is particularly useful when you want to start fresh with a clean workspace or when your Market Watch has become cluttered with too many symbols. Purpose Over time, traders often accumulate numerous symbols in their Market Watch window, making it difficult to focus on the instruments they actively trade. Manually removing symbols one by one can be tedious and time-consuming. This script automates the entire process, clearing all symbols in seconds.

It is a script to display the time remaining until next bar arrives.

The script removes all autotrading icons from the current chart

A tool to align the trading sessions names with broker server time, and local time

This is a tester script that extends the standard MetaTrader 5 optimisation capabilities, allowing you to evaluate strategies according to complex user-defined criteria (with separation into in-sample and out-of-sample periods, advanced metrics and statistical tests).

Showing different ways of the Aroon values calculation

Provide simplest class to write CSV file

This script is a reference solution for mapping symbol names configured by users in MetaTrader 5 EAs or scripts to the actual names provided by the broker. It uses the Levenshtein distance algorithm to automatically identify the most similar symbol in Market Watch. Ideal for developers facing compatibility issues with prefixes or suffixes in symbol names. It is a customisable starting point to suit any specific need.

This is an example of ascending sort a struct list by a field. You can find out and customize the above algorithm depending on the purpose of use, this is the most basic example is also a direction to resolve the arrangement in an array of structure. The algorithm used in this example is Quick Sort and Merge Sort.

Unfortunately, I found that some brokers Changing the time on the server is a bit incorrect, which I didn't expect. and which surprised me a lot. Here is a script that anyone can use to check their broker.

Unfortunately I had to realise that some brokers are a bit careless with the server time changeover, which I had not expected and which surprised me a lot. Here is a script with which everyone can check their broker.

MQL5 script for MetaTrader 5 that adds two buttons to close all buy or sell positions for the current symbol.

This is a simple script file to compute lot size either using risk percentage approach or the actual amount to risk.

A quick little script to make traders' lives easier. The one thing that always annoys me is resetting the properties like colors for a new chart, to make it look the way i like it. So Here is a script to make things smoother.

The TradeReportExporter script is designed to export the history of trades (trades) into a convenient CSV file. It automatically collects data on all trades for the last year for the instrument it is installed on. The file includes such data as date and time, transaction type (buy/sell), price, volume, commission and profit/loss. The result is saved in a file that can be opened in Excel or any other spreadsheet editor.

Partially close active sell orders

Script for partially close active buy orders

Population-based optimisation algorithms are collected here. The archive contains all necessary files to run the algorithms on test functions.

The function can be useful to not overload the server with trade requests at times when the market is closed for trading

A professional script that automatically sets Stop Loss and Take Profit for all open positions based on a customizable Risk:Reward ratio. Perfect for traders who want to maintain consistent risk management across their trades.

It is taken into account that there are 30 days in a month, 365 days in a year The script demonstrates the counter of time until the beginning of the new year

Trading XAUUSD (Gold) is often influenced by major economic news events like USD, GBP, or EUR releases. To mitigate risks during these volatile periods, using a News Filter in your Expert Advisor (EA) is essential. In this article, I’ll share how to create a simple News Filter on MT5 and apply it to XAUUSD trading.

A simple and effective Expert Advisor based on Stochastic Oscillator reversal signals on the H1 timeframe. Buy signals are triggered when %K crosses above %D below the 20 level. Sell signals are triggered when %K crosses below %D above the 80 level. Risk is calculated based on the account balance, with the lot size set to 0.1 (adjustable as needed). Take Profit (TP) is set to 300 points for all positions. Stop Loss (SL) is dynamically calculated based on the opposite crossover signal. The position is closed when a crossover in the opposite direction occurs, as well as when TP or SL is reached

This CalculateHistoryProfit script version 1.0 is designed to calculate profit for a specified period using a chart panel.

Candle Signature with Example | For Research and Development

These are some #define statements that are useful to perform operations in your EA. You only need to assign the name of your variables at the beginning of the file, and then let the other #define statements do the work. In order to use this file, add #include <DEFINE_statements.mqh> to the first line in your EA file.

A simple starting-point script to collect data and send to a CSV in oldest-newest ordering. In this example only the close price data is collected.

A script which when dragged onto the chart will print out in the experts window the number of bars that are on that chart - like magic.

Unfortunately, I discovered that some brokers are a bit sloppy with the server time change due to the daylight saving time (DST), which I did not expect and which surprised me a lot. Here is a script with which anyone can check their broker.

This script was developed for displaying saved Strategy report from the Strategy Tester into a chart.

This script is a reference solution for mapping symbol names configured by users in MetaTrader 5 EAs or scripts to the actual names provided by the broker. It uses the Levenshtein distance algorithm to automatically identify the most similar symbol in Market Watch. It is ideal for developers facing compatibility issues with prefixes or suffixes in symbol names. This is a customizable starting point to adapt to any specific needs.

12345678