No Hedge Guard - Close Newer Opposite Position on Hedging
Info
The No Hedge Guard - Close Newer Opposite Position on Hedging is a Expert Advisor for MetaTrader 5 that no hedge guard ensures your account remains hedge-free by automatically closing the most recently opened position when a buy and a sell trade exist simultaneously on the same symbol. This tool is compatible with both manual trades and Expert Advisors (EAs).
Usage
This tool is typically used for hedging and risk management in volatile market conditions.
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 No Hedge Guard - Close Newer Opposite Position on Hedging
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
No Hedge Guard ensures your account remains hedge-free by automatically closing the most recently opened position when a buy and a sell trade exist simultaneously on the same symbol.
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: Prop Firm Equity Guard: Daily and Maximum Drawdown Protection - another powerful expert for MetaTrader 5 traders.
No Hedge Guard ensures your account remains hedge-free by automatically closing the most recently opened position when a buy and a sell trade exist simultaneously on the same symbol.Also recommended: Daily Drawdown Guard for MetaTrader 5 - similar expert with strong performance on MetaTrader 5.
This tool is compatible with both manual trades and Expert Advisors (EAs). It functions by monitoring existing trades and does not initiate new ones.
Many proprietary trading firms prohibit hedging. Accidental hedges can occur when multiple EAs trade the same symbol. Attaching this indicator to a single chart provides account-wide hedging protection.
Functionality:
The indicator utilizes the OnTradeTransaction event to detect new trades and a one-second timer for continuous monitoring. For each symbol, it identifies the oldest open position and closes any newer positions opened in the opposite direction.
Features include an alert-only mode, an optional magic number filter (set to 0 for manual trades only), and on-chart status display.
Inputs:
Action on hedge detection: Close the newer opposite position or alert only.
Symbols to monitor: Watch all symbols or only the symbol of the current chart.
Magic numbers: Specify comma-separated magic numbers to watch (leave empty to monitor all).
Alerts: Enable popup alerts and on-chart status.
Important Considerations:
The indicator closes a position shortly after it is opened; it cannot prevent an order from being placed. It is recommended to address the root cause of hedging (e.g., two EAs trading in opposite directions on the same symbol).
Hedging is not possible on netting accounts, so this tool will not be applicable.
Tested on a MetaQuotes demo account, an accidental sell trade on EURUSD was immediately closed when a buy trade was already open.
This tool is effective from 2026 onwards.
You may also like: Prop Firm Guardian: Manage Daily Loss, Max Loss, and Profit Target - excellent alternative for expert users on MetaTrader 5.
Source Code
#property copyright "RobotFX"
#property version "1.00"
#property description "This code is educational. Feel free to use, modify and upgrade as you wish. Visit ROBOTFX.ORG for professional trading tools"
#include <Trade/Trade.mqh>
enum ENUM_GUARD_ACTION
{
ACTION_CLOSE = 0,
ACTION_ALERT = 1
};
enum ENUM_GUARD_SCOPE
.......
⚠ 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.