Trade Settings: Persisting and Migrating Per-Trade Configurations

Trade Settings: Persisting and Migrating Per-Trade Configurations
Download ALL MT5 experts (1800)
YouTube Video Thumbnail



Similar MetaTrader Tools

Trade Settings: Persisting and Migrating Per-Trade Configurations

Info

The Trade Settings: Persisting and Migrating Per-Trade Configurations is a Expert Advisor for MetaTrader 5 that template record (ticket 0) is saved with points=200. 00 and mode=1, then loaded back with the same values using the public TradeSettings API.

Usage

This tool is typically used for automated trading on major forex pairs and gold.

Platform

This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.


How to Install and Use Trade Settings: Persisting and Migrating Per-Trade Configurations

1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.

2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.

3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.

4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.

Frequently Asked Questions

Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.

Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.

Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.

What this tool does

Template record (ticket 0) is saved with points=200.

Typical Use Case

This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.

Compatible Platform & Setup

This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.

Description & Settings

Related: Ezo Trade Manager: Break-Even and Trailing Stop for Open Positions - another powerful expert for MetaTrader 5 traders.

Template record (ticket 0) is saved with points=200.00 and mode=1, then loaded back with the same values using the public TradeSettings API.

Also recommended: Devil Trader AI Lite: Exclusive Gold Strategy for M30 & H1 Timeframes - similar expert with strong performance on MetaTrader 5.


Overview

An Expert Advisor or manual trading panel may require distinct settings for each individual order or position, such as a specific distance and mode. The Trade Settings system stores these custom values separately for each ticket, associated with its position identifier, pending/position status, and base volume. It supports double, ulong, and price-unit quantities; any saved quantity is automatically converted when the current price unit changes.

Lifecycle Behavior

Ticket zero is reserved as a separate template. Following an initial scan, the library can create a record for a newly detected trade and track a pending order into a position once the source is verified. Cleanup procedures incorporate checks for connection status, absence, and history. Incomplete records, invalid aliases, and ambiguous histories are preserved and reported, rather than being silently assigned default values or assumed as closed.

Usage Example

//+------------------------------------------------------------------+
//| ShowTicket: print saved settings for a ticket |
//+------------------------------------------------------------------+
void ShowTicket(CTradeSettings &settings,const ulong ticket)
{
TSResult locked=settings.Lock();
if(locked==TS_BUSY)
return;
if(locked!=TS_OK)
{
Print(settings.LastError());
return;
}
TSRecord record;
TSResult status=settings.Load(ticket,record);
if(status==TS_OK)
PrintFormat("distance=%.2f, mode=%I64u",
record.values[0].number,record.values[1].integer);
else if(status==TS_MISSING)
Print("No settings record for ticket ",ticket);
else
Print(settings.LastError());
if(settings.Unlock()!=TS_OK)
Print(settings.LastError());
}

Retry a busy lock on a subsequent timer event. Always acquire the lock before executing operations like Load, Has, Save, Scan, or Cleanup, and ensure it is released immediately after the operation completes.

Installation and Files

Navigate to File > Open Data Folder within MetaTrader 5 and extract the TradeSettings-Source.zip file into your data folder. Compile the Expert Advisor and self-test script in MetaEditor, then refresh the Navigator window. Attach the TradeSettings TradeSettingsDemo Expert Advisor to a demo chart. This EA monitors trades and does not initiate trade requests. Execute the TradeSettings TradeSettingsSelfTest script and review the Experts tab for any RESULT failures.

TradeSettings.mqh
— This is a standalone library requiring no DLL or external library dependencies.

TradeSettingsDemo.mq5
— This is a polling example Expert Advisor designed for observing saved settings.

TradeSettingsSelfTest.mq5
— This script performs offline checks for hashes, key limits, ulong words, unit conversion, incomplete records, and identity-alias states.

TradeSettings-Source.zip
— This archive contains the complete MQL5 installation layout, including the demo EA, self-test script, header files, and guides.

README.md and TEST_GUIDE.md
— These files provide instructions for integration and runtime testing and are included within the archive.

Tested Scope and Limitations

Tests were conducted on an ePlanet hedging demo account, observing a pending order that filled using the same ticket. Scenarios included timeframe changes, normal terminal restarts, partial closes, and API-level cleanup after a full close. The self-test script and a two-chart library lock handover were also executed within an MT5 demo terminal environment.

Untested Scenarios:
Transitioning to a different ticket, reconnection as a distinct event, and netting account behavior. While the different-ticket and history-based functionalities are implemented, they have not been validated through these live demo tests.

Storage utilizes the terminal's Global Variables, stored within the same terminal data folder. Data is not automatically transferred to another computer, installation, or VPS. MetaTrader automatically removes Global Variables after four weeks of inactivity; however, regular access may extend this period. Uncertainty in historical data can impede migration or cleanup processes. The library does not merge multiple netting entry orders and does not guarantee multi-key transactions or recovery from forced terminations or power outages. The last update was in 2026.

You may also like: Seven-Bar Pressure Flip (SBPF) Sell-Only Expert Advisor for MetaTrader 5 - excellent alternative for expert users on MetaTrader 5.

Source Code

#property version "1.00"
#property script_show_inputs
#define TRADE_SETTINGS_INTERNAL_TEST
#include "TradeSettings.mqh"
int Failures=0;
void Check(const bool passed,const string name)
  {
   Print("TradeSettingsSelfTest: ",passed ? "PASS " : "FAIL ",name);
   if(!passed)
      Failures++;

.......

Leave your opinion, ask a question, share some knowledge

⚠ Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.