MetaTrader

MetaTrader Scripts for MT5

UPDATE
Showing 325 results

Export historical data

The script purpose is to export historical rates data to format, convenient for analysis in external programs, for example, in MathCad (example is attached).

The output file contain the historical price data (bars) of the specified month in the following form:

Clipboard

The script gets contents from the Windows Clipboard.

WININET_TEST

The WININET_TEST.mq5 script is a modified version of script , published by Integer in MQL4.Codebase.

It's a simple example that shows how to download page(file) from Internet using the wininet.dll library.

Input parameters:

  • URL - address of page or file (also it can reference to a binary file)
  • FileToSave - file name, that will be saved to terminal_data_folder\MQL5\Files\ folder of the client terminal.

To see how does it works, don't forget to "Allow DLL imports" in the options of the client terminal and execute it at any chart.

sChartsSynchroScroll

The script provides a synchronous scrolling for all charts opened in the client terminal.

Before the script run, enable the chart shift from the right part of the window (enable the button on the Standard toolbar, if the button is absent, you can add it to the toolbar using the right mouse button click on the panel - "Customize..."):

Specify the shift size using the triangle marker, located on the upper edge of the chart and configure it as you like:

The script should be executed only on one chart. The red markers will be created on all of the opened charts after the script running. While scrolling of any chart, the other charts will be scrolled automatically so the bars with the same time will under these lines.

The input parameters of the script are absent.

ObjChartSample

The script ObjChartSample.mql5 illustrates control of chart properties using the classes from the ().

SphereSample

The script SphereSample.mq5 illustrates control of graphic objects using the classes from the (Base class of objects array , ).

MW Download History

This script allows the user to download all the available OHLC info in his Terminal to a file located in the Commons folder. This data can later be used to create custom symbols. If a file already exists there, it will be updated with any new information available since the last tick data recorded in that file.

To use this script, execute the following steps:

  1. Go to your Common folder (Archive -> Open Data Folder -> Navigate one step back in Explorer -> Enter in folder "Common")
  2. Create a new folder there with the name "MW Download History"
    1. You may create it with anoter name, but in this case you must rename the "define" compiler directive inside the script called "MW_DH_DEST_FOLDER" with the alternative name you choose
  3. Open the script in your MT5 Editor
  4. Compile it
  5. Open the MT5 Terminal
  6. Open the Tool Box (Ctrl+T) and select the tab "Experts"
  7. Open the Navigator (Ctrl+N)
  8. Open the Market Watch (Ctrl+M)
  9. Add there the symbols whose data you want to download
  10. Open a chart of any of the symbols in Market Watch
  11. Attach the script (compiled file) from the Navigator to it. A popup with input parameters will appear
    1. Input 1: Inform which symbol you want to have its data downloaded, in case it's just one. If this parameter is left empty, all the symbols in Market Watch will be considered minus the exceptions (next inputs)
    2. Input 2: If you want some of the Market Watch symbols not to be downloaded and they have a common string in their names, you may inform that string in this input, and they will be ignored (useful to avoid downloading custom symbols's data)
    3. Input 3: If you want some of the Market Watch symbols not to be downloaded, you may inform which in this input separating each symbol with ";"
    4. Input 4: Select which timeframe you want to have downloaded. M1, the default, is advised
    5. In case the user wants to download more than one timefrime, a new file for the different timeframe will be created. All files have the symbol and the selected timeframe on its name
  12. Press OK and monitor the results in the Tool Box. After finished, you may go to the destination folder (step 2) and check for the files created (one for each symbol)
  13. Repeat steps 5-12 periodically (like at the first Sunday of every new month) to keep the files updated

To learn how to create custom symbols using the created files, you may find tutorials here and in YouTube on how to do that.

Finally,

  • Any suggestions on how to improve this script will be welcomed
  • I'm sorry for any mistakes; this is my first public script
  • I'ld like to thanks a guy/user named "etrader" who provided somewhere the script that served as initial reference for this one, "downloadhistory.mq5"

Project Template Generator

Technical Overview

ProjectTemplateGen.mq5 is a MetaTrader 5 script utility that automates the creation of standardized Expert Advisor project structures. It implements programmatic file system operations within MQL5's security constraints while establishing a consistent foundation for scalable trading system development.

Core Capabilities
  • Programmatic File Operations: Demonstrates MQL5's file handling API for creating directories and writing structured content
  • Template-Based Generation: Produces ready-to-compile MQL5 source files with proper event handler skeletons
  • Configurable Output: Allows runtime customization through input parameters without modifying source code
  • Sandbox Compliance: Operates within MetaTrader 5's secure execution environment
Implementation Details

File Operations Architecture

The script implements a modular approach to file creation, with distinct functions handling different aspects of project generation:

Generated Project Structure

Key Technical Components

1. Dynamic Path Construction

  • Uses relative paths compliant with MQL5 sandbox restrictions
  • Demonstrates string concatenation for dynamic file system navigation

2. Robust File Creation with Error Handling

  • Implements comprehensive error checking for file operations
  • Provides meaningful error messages with system error codes
  • Ensures proper resource cleanup with FileClose() calls

3. Structured Content Generation

  • Generates syntactically valid MQL5 code
  • Maintains consistent formatting and coding standards
  • Creates compilable boilerplate code

Usage Instructions

Basic Operation

  • Compilation: Compile ProjectTemplateGen.mq5 in MetaEditor (F7)
  • Execution: Drag script from Navigator onto any chart
  • Configuration: Set parameters in the input dialog:
  • ProjectName: Destination folder and file naming
  • CreateIncludeFile: Toggle header file generation
  • Output: Check Experts tab for generation status and path information

Post-Generation Workflow

The script creates projects in MQL5\Files\[ProjectName]\ due to MQL5 script security restrictions.

Complete the setup by:

  1. Manually moving the folder to MQL5\Experts\
  2. Opening the main .mq5 file in MetaEditor
  3. Implementing your trading logic in the provided function skeletons

Expansion Opportunities for Advanced Workflows

Scalability Enhancements

  1. Multi-File Templates: Extend to generate indicator scripts, library files, or resource manifests
  2. Configuration Files: Add JSON/XML configuration file generation for parameter management
  3. Build Scripts: Incorporate batch compilation or dependency management files

Code:   

Price Action Dynamic Exit Strategy - Profit Shield pro

ytg_Percent_Lot

The script calculates the number of lots to trade using the specified percentage of risk funds.

s-LastPinkEventDate

Since build 344 of the client terminal display of economic calendar news using special graphical objects () is added.

A script that outputs as a demonstration of the Economic Calendar with current economic data, the date of the last major(Pink) event.

Use the function datetime last_pink_event_date()

Recommendations:

  • On weekends there there are no data objects on the chart
  • Special graphical objects are present and activated

YURAZ_CreateCSV_HistoryFile_From_MT5_For_MT4

When I used the history quotes data from MetaTrader4 client terminal, I have found that some brokers doesn't have the full history.

The quality of the historical bar data is better, so I have decided to export the historical quotes from MetaTrader 5 and import them in MetaTrader 4.

This script will help you to get the full history for MetaTrader 4.

The script creates .CSV file with historical bar data.

The steps:

  • 1 - Install MetaTrader 5 client terminal
  • 2 - Enter the Main Menu->Tools->Options->Max bars in chart, and set MaxBars in chart depending on the historical bars needed:

  • 3 - Load this script and place it to MQL5\Scripts folder in WINDOWS7/VISTA copy it to the Roaming folder instead of Program Files folder: for example c:\Users\<administrator\AppData\Roaming\MetaQuotes\Terminal\D0E8209F77C8CF37AD8BF550E51FF075\MQL5\Scripts\ </administrator
  • 4 - Compile the script and attach it to the charts for each MetaTrader 4 timeframes: M1 M5 M15 M30 H1 H4 D1 W1

  • 5 - Close MetaTrader 5;
  • 6 - Open MetaTrader 4;
  • 7 - Press F2;
  • 8 - Choose currency pair;
  • 9 - Select timeframe;

Let's consider how to dow it for M15 timeframe.
  • 10 - Select the file, created for M15 timeframe;
  • 11 - Press the "Import" button:

  • 12 - Repeat the step №10 for each pair. Repeat Step №11 for each timeframe of the pair:

LET'S CHECK IT! Before:

After:

YURAZ

yzh@mail.ru

RobotFX does not own any of the code provided on this platform. All tools are freely available on the internet; we simply index and re-offer them for download. We are not responsible for any financial losses that may occur. Trading responsibilities rely solely on the traders downloading and using the displayed Expert Advisors, indicators, and scripts. These tools are provided for educational purposes only and may require modification or optimization to align with a trader's specific strategy or needs.
© ROBOTFX - Best MetaTrader Expert Advisors & Indicators