MetaTrader Trading Tools
Showing 318 results in this view

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

History of trade

The script allows you to place the deals history on the chart using the graphic objects.

SelfGenerator

This script generates a file with its own source code (solution of the classical program in MQL5).

It may be useful to study programming and algorithms.

- Where is the source code?

- Just launch the script and you will get it in 'MQL5\Files' folder.

To check it, please copy the file, created in \Files\ to the "\Experts\" folder, compile it and launch the script. After that you can compare them byte by byte.

Also you can check several generations...... ;-)

sChartsSynchroScroll_v2

Just attach script to one chart and that's all.

You can change shift and chart scale, the different charts may have different scales.

Export Indicator's Values

After searching for such script, I decided to create mine, and decided to share it with the MQL5 community.

This script exports indicator's values to CSV File along with date and time (you can change the function parameters to change what indicator to export).

  • Enhanced code;
  • Values are now exported as numbers in spreadsheets e.g Excel, so you can do calculation on them easily (no need to convert them to numbers in Excel);
  • Script now asks for inputs : Indicator Directory and name + Indicator's Period. (see Attached picture);
  • Exported file name is now looks like : e.g EURUSD_PERIOD_H1(RSI,14).
Any suggestions are welcomed.

Demo_Create_OBJ_BITMAP_Script

The graphic object of type allows to show the .BMP images on the chart.

  • Unzip the mql5_logo.bmp to terminal_data_folder\MQL5\Images\ folder

It's possible to draw the image as background ("Draw image as background" object property).

By default, the "Disable selection" property is enabled for all graphic objects, created in MQL5.

ChartNavigate Demo

Simple script with demonstration of use of the function.

The script uses several chart functions:

  • - to get the handle of the chart with the script launched (the handle is used in )
  • - to get the number of the first visible bar on the chart ( is used - the last (uncompleted) bar has index 0),
  • - to set chart shift from the right border of the chart, to disable autoscroll when new tick, to set drawing as candles and showing of tick volumes.

Each navigation demo is commented using the function.

t

downloadhistory.mq5

The script downloads historical data (for the current symbol), available at trade server.

The download progress is plotted using the CProgressBar class, proposed in article.

In "Experts" tab of Toolbox window it prints the first date of the server history.

If error it prints error code (see CheckLoadHistory in )