Skip to content

Free MT5 Expert Advisor

Equity Protector EA

MT5 account guard that closes positions and deletes pending orders when a daily loss %, maximum drawdown % or equity target is hit, then blocks new trades.

Risk managementv1.0MetaTrader 5 (MQL5) Compiles with 0 errors Non-repainting signals Stop-loss on every trade
Strategy
Does not open trades. Closes all matching positions and deletes pending orders when the account loses the daily limit, falls the maximum drawdown from its peak or reaches the equity target, then keeps closing new positions while locked.
Risk model
Opens no trades; caps daily loss and total drawdown by flattening the account and blocking re-entry

What it does

Equity Protector EA is a safety net for the whole account. It watches equity every second and, when one of your limits is reached, closes positions, deletes pending orders and locks trading. While the lock is active, any new position that appears, whether from you or another EA, is closed again. A status block on the chart shows the numbers it is watching.

How it works

Three limits can be used, alone or together:

  • Daily loss: the day-start balance is the current balance minus today's closed trade results (profit, swap, commission and fees since server midnight). Daily loss % = (day-start balance − equity) ÷ day-start balance × 100. Because equity is used, open losses count.
  • Maximum drawdown: the EA records the highest equity it has seen (the high-water mark). Drawdown % = (peak − equity) ÷ peak × 100.
  • Equity target: equity at or above the amount you set.

When a limit triggers, the EA loops through positions from last to first, closes each matching one by ticket, and deletes matching pending orders. A daily-loss lock ends at the next server midnight. Drawdown and target locks stay until you restart the EA with "Reset lock" set to true. The lock and peak are stored in terminal global variables, so they survive a restart.

Example (illustrative): with a 10,000 day-start balance and a 3% limit, the lock triggers once equity falls to 9,700 or below.

How to use it

Attach it to one chart only and leave the terminal running. Keep "All symbols" and "All positions" so the protection covers the whole account; narrow the filters only if you want to protect one strategy. Watch the status block to see the day-start balance, daily result, peak, drawdown and lock state.

Settings

InputDefaultWhat it changes
Daily loss limit (%)3.0Daily stop (0 = off)
Max drawdown (%)10.0Peak-to-equity stop (0 = off)
Equity target0Close-all target (0 = off)
Delete pending orderstrueAlso removes pending orders
Block after triggertrueRe-closes new positions while locked
Reset lock / Reset peakfalse / falseClears saved state on start
Symbols / PositionsAll / AllScope of closing
Max slippage (points)20For closing orders

Limitations

The EA reacts to prices it sees; in a fast market or a weekend gap the final loss can exceed the limit. Closing many positions takes time and each can slip. The day starts at the broker's server midnight, not your local time. It cannot protect the account when the terminal is off, and it does not stop trades opened from another device until it sees and closes them.

Before you run it live

Test the limits on a demo account by opening small trades and setting a tight limit. Decide in advance what you will do after a lock. Read about drawdown and equity, and keep the EA on a reliable, always-on terminal. Trading carries a substantial risk of loss.

Key inputs

Key inputs of Equity Protector EA
InputDefaultDescription
Daily loss limit (%)3.0Loss from the day-start balance, including open trades, that triggers the lock.
Max drawdown (%)10.0Fall from the highest recorded equity that triggers the lock.
Equity target0 (off)Equity level, in account currency, that closes everything.
Block after triggertrueCloses any new position while the lock is active.
Symbols to manageAll symbolsWhich positions are closed when the lock triggers.
Reset lockfalseClears a saved lock when the EA starts.

Educational tools, not advice. Automated trading can lose money quickly. Indicators and Expert Advisors describe price; they do not predict it, and past behaviour does not guarantee future results. Test everything on a demo account first and never risk money you cannot afford to lose. See our disclaimer.

Keep exploring

Related mt5 expert advisors