Preventing Multiple Expert Advisor Trades on the Same Symbol
Info
The Preventing Multiple Expert Advisor Trades on the Same Symbol is a Expert Advisor for MetaTrader 5 that multiple expert advisors (eas) on the same trading symbol can lead to unintended consequences if not properly managed. Each EA might independently check for existing positions using its own magic number, find none, and proceed to open a new trade.
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 Preventing Multiple Expert Advisor Trades on the Same Symbol
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
Multiple Expert Advisors (EAs) on the same trading symbol can lead to unintended consequences if not properly managed.
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: expert advisor for opening multiple buy and sell orders based on user input - another powerful expert for MetaTrader 5 traders.
Multiple Expert Advisors (EAs) on the same trading symbol can lead to unintended consequences if not properly managed. Each EA might independently check for existing positions using its own magic number, find none, and proceed to open a new trade. If this occurs on every new bar while already positioned, and the system doesn't track positions across all EAs, it can result in an excessive number of trades for a single symbol. For example, one scenario led to 22 contracts on a symbol intended for a single position, requiring an external tool to close 16 positions in one morning. This incurred unnecessary spread costs and cluttered trading history with trades that were not intentionally managed.Also recommended: multiple ea tracking with a magic number based profit and loss live dashboard in mq l5 - similar expert with strong performance on MetaTrader 5.
The solution is to implement a position capping mechanism at the entry point, refusing orders before they are placed, rather than dealing with the consequences of over-exposure afterwards.
Library Functionality
The ExposureCap library provides the following functions:
ExposureCap::Allowed(symbol, requestedLots, cap, callerName)
This function calculates the total volume of all open positions for the specified symbol (including manual trades and trades from all magic numbers). It then determines if adding the requested number of lots would exceed the defined cap. If the order would exceed the cap, it logs a message containing the currently held volume, the requested volume, the cap, and the caller's name. This ensures the reason for refusal is recorded in the expert advisor's log.
ExposureCap::Held(symbol)
Returns the total gross volume of open positions for the given symbol.
ExposureCap::Room(symbol, cap)
Returns the remaining volume available under the specified cap for the given symbol.
A cap value of zero or less will disable the check.
Usage Instructions
Include the ExposureCap library file in your EAs. Before every call to OrderSend, add the following check:
if(!ExposureCap::Allowed(_Symbol, lots, InpCap, "MyEA")) return;
Replace `lots` with the volume you intend to trade and `InpCap` with your defined cap value. Ensure the same `InpCap` is used across all EAs trading on the same account for the same symbol. This prevents the EAs from accumulating excessive positions.
Limitations
This library implements a simple gross exposure check per symbol. It does not net long and short positions or provide per-EA quotas. The focus is on the total gross exposure, which is the primary factor that can lead to account issues. More refined strategies can be built upon this foundation. It is a check, not a foolproof lock; if two EAs decide to trade on the exact same tick, both might pass the check simultaneously. However, in practice, EAs on different charts typically act on different ticks, and the observed outcome is usually at most one refusal per bar.
Demo Script Inputs
The included demo script uses the following inputs:
InpCap
(Default: 1.0) - The gross position size limit for the chart's symbol, in lots.
InpRequested
(Default: 1.0) - The volume, in lots, that a hypothetical trade would request.
The script will output the current held volume, the cap, and the available room for the symbol. It will also demonstrate the refusal message when a request exceeding the available room is simulated, without actually executing any trades.
You may also like: butterfly strategy expert advisor with multiple time frames - excellent alternative for expert users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property link "https://robotfx.org"
#property version "1.00"
#property script_show_inputs
#include "ExposureCap.mqh"
input double InpCap = 1.0;
input double InpRequested = 1.0;
void OnStart()
{
string sym = _Symbol;
.......
⚠ 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.