Trade Equity Guardian
- Utilità
- LEE SAMSON
- Versione: 1.0
Automatic Trade Protection EA For MT5
Overview
Trade Equity Guardian is a lightweight, always-on Expert Advisor that continuously monitors all open positions on your account and automatically closes any trade that breaches your predefined risk thresholds. It acts as a safety net — protecting your account from oversized positions, runaway losses, or locking in profits when targets are hit.
Attach it to any chart and let it run in the background. It works alongside your other EAs and manual trades without interfering — it only steps in when a position crosses one of your limits.
How It Works
It checks all open positions at a regular interval you define (default: every 5 seconds). For each position, it evaluates up to four independent criteria. If any single criterion is triggered, the position is immediately closed.
Each criterion has its own input. If the input is set to 0, that criterion is completely disabled and ignored. If it is set to any value greater than 0, it becomes active and will be monitored. This means you can use any combination of the four criteria — just one, two, three, or all four at the same time.
The EA loops through positions in reverse order to ensure that closing one position does not cause others to be skipped. If a close attempt fails (due to requotes, server issues, etc.), it will automatically retry up to the number of attempts you specify.
Input Parameters
Close Criteria (0 = Disabled)
Max Lot Size (close if >= this) Set this to the maximum lot size you want to allow on any single trade. If a position's lot size is equal to or greater than this value, it will be closed. For example, setting this to 1.0 will close any position of 1.0 lots or above. Set to 0 to disable.
Max % of Account Equity (close if >= this) Set this to the maximum percentage of your account equity that any single position's margin should represent. The EA calculates what percentage of your current equity is being used as margin for each position. If it meets or exceeds this value, the position is closed. For example, setting this to 10 will close any position using 10% or more of your equity as margin. Set to 0 to disable.
Max Profit Amount $ (close if profit+swap >= this) This acts as a profit target in dollar terms. Set this to the maximum profit (including swap) you want any single trade to reach. If a position's combined profit and swap is equal to or greater than this amount, it will be closed. For example, setting this to 200 will close any trade that reaches $200 or more in profit. Set to 0 to disable.
Max Loss Amount $ (close if loss <= -this) This acts as a stop loss in dollar terms. Set this to the maximum loss you are willing to accept on any single trade. Enter the value as a positive number. If a position's combined profit and swap falls to the negative of this amount or worse, it will be closed. For example, setting this to 100 will close any trade that reaches -$100 or worse. Set to 0 to disable.
Monitoring Settings
Check Interval (seconds) How often the EA checks all open positions. The default is 5 seconds. Lower values mean faster detection but slightly more processing. A value of 1–10 seconds is recommended for most users. The EA also checks on every new tick as a backup, so positions are monitored even during quiet market periods.
Slippage (points) The maximum allowed slippage in points when closing a position. If the price moves beyond this amount during the close attempt, the broker may reject the order. The default of 10 points is suitable for most pairs and brokers. Increase this if you trade volatile instruments or experience frequent requotes.
Max Close Retries If a close attempt fails, the EA will retry up to this number of times with a short pause between each attempt. The default is 3 retries. This helps ensure positions are closed even during periods of high volatility or temporary server issues.
Filters
Magic Number Filter (0 = All) If you only want TradeGuard to monitor positions opened by a specific EA, enter that EA's magic number here. Only positions matching this magic number will be checked. Set to 0 to monitor all positions on the account, including manual trades and trades from any EA.
Symbol Filter (blank = All) If you only want TradeGuard to monitor positions on a specific symbol, enter the symbol name here exactly as it appears in your Market Watch (e.g., EURUSD, GBPJPY). Leave blank to monitor all symbols.
Alerts
Alert When Trade Closed When enabled, a pop-up alert will appear on your screen each time TradeGuard closes a position, showing the ticket number, symbol, lot size, profit/loss, and the reason it was closed.
Send Push Notification When enabled, a push notification will be sent to your mobile device via the MetaTrader 5 app each time a position is closed. You must have push notifications configured in your MT5 terminal under Tools > Options > Notifications for this to work.
Log Closures to Experts Tab When enabled, all closure activity and any errors are printed to the Experts tab in your MT5 terminal. This provides a full audit trail of every action taken by the EA. Recommended to leave enabled.
Example Configurations
Account protection only — prevent oversized trades: Set Max Lot Size to 2.0 and leave everything else at 0. Any trade of 2 lots or more will be closed immediately.
Dollar-based risk management: Set Max Loss Amount to 500 and Max Money Amount to 1000. Any trade that loses $500 will be cut, and any trade that profits $1000 will be locked in.
Monitor only one EA's trades: Set Magic Number Filter to your EA's magic number. Only that EA's positions will be monitored — everything else is left untouched.
Full protection suite: Set Max Lot Size to 5.0, Max Account % to 15, Max Loss Amount to 1000, and Max Money Amount to 2000. Any position that breaches any one of these limits will be closed.
Important Notes
- Can be attached to any chart on any timeframe. It monitors the entire account (or filtered positions), not just the chart it is attached to.
- The EA does not open any trades. It only closes positions that breach your criteria.
- All threshold inputs must be set to a value greater than 0 to be active. A value of 0 means that criterion is disabled.
- Negative values in any input field will be treated as disabled.
- The EA works alongside other Expert Advisors and manual trading without conflict.
- Ensure your broker allows automated trading and that the AutoTrading button is enabled in MT5.
- For push notifications, configure your MetaQuotes ID in Tools > Options > Notifications.
