Daily and Max Loss Limit Guard
- Utilities
-
Kazuma Uezono
MQL5 / MQL4 / Pine Script v6 developer and active trader.
Seller on the MQL5 Market (indicators for MT4/MT5).
Services:
- TradingView Pine Script to MT5/MT4 conversion (bar-by-bar matching, with tester report)
- MT4 to MT5 migration - Version: 1.1
- Activations: 5
Daily and Max Loss Limit Guard watches the equity of your MetaTrader 5 account and stops trading when a limit you set is reached: a daily loss limit, a maximum (overall) loss limit with a static or trailing floor, and an optional daily profit target. At a limit it deletes the pending orders and closes the positions in scope. While this stop is active it also closes any new position that appears, whether it was opened by hand or by another EA. The panel on the chart shows the short name "Equity DD Guard".
This is a risk-control utility. It does not open trades on a real or demo account, it gives no buy or sell signals, and it is not a trading strategy. It cannot prevent losses: it sends close orders after a limit has been reached, so the final result can be worse than the limit (see the limits below).
In this description "lock" means the EA's stop state (positions closed, new positions closed). It is not a hedging lock.
DAILY LIMITS
- Daily loss limit and daily profit target, each Off / money (account currency) / percent.
- Day-start reference for the daily P/L and the percent: day-start balance (default), day-start equity, or the higher of the two.
- Daily P/L = current account equity (closed trades plus the floating P/L of all open positions) minus the day-start reference. Deposits and withdrawals made today are not counted as profit or loss.
- New day: broker server time, UTC, New York or Central Europe (both with daylight saving time), Japan (UTC+9) or a fixed UTC offset, at the hour and minute you choose.
- After the daily loss limit or the daily profit target is reached, the lock lasts until the next day starts.
- On an account funded today (for example the first day of a new account) the daily percent is calculated from the balance after the deposit.
MAXIMUM LOSS (prop-firm style)
- Money, or percent of the initial capital.
- Three floors: Static (initial capital - limit), Trailing from the highest closed balance, Trailing from the highest equity seen while the EA runs.
- Initial capital: entered by you, or automatic = deposits - withdrawals in the account history (optionally counted from a start date).
- Equity is compared without credit (bonus).
- The maximum loss lock stays, also after a restart, until you change the maximum loss inputs.
- If the equity is already below the floor when you attach the EA (older losses or a wrong initial capital), the maximum loss is shown as NOT ARMED and nothing is closed. It is armed once the equity has been above the floor. NOT ARMED is also shown when the automatic mode finds no deposit in the history; then enter the initial capital.
ACTION AT A LIMIT
- Pending orders are deleted first (so they cannot be filled during the closing), then positions are closed.
- Scope: the whole account (all symbols, manual trades and all EAs), only listed magic numbers (0 = manual trades), only listed symbols, or both.
- While locked, every new position in scope is closed as soon as the EA sees it, and new pending orders in scope are deleted.
- Warning-only mode: closing is turned off and the EA only shows and sends alerts.
- Default settings: daily loss 4% of the day-start balance, maximum loss 8% static, closing ON, scope = whole account. Check them before you attach the EA to a real account.
POSITION LIMITS (optional, off by default)
- Maximum lot per position, maximum total lots and maximum number of positions (in scope).
- Warning only (default), or close the positions over the limit (the oldest positions are kept).
WARNINGS AND PANEL
- Early warning when 80% of a limit is used (adjustable, 0 = off), on the panel and optionally as a popup.
- Popup alert at a limit (default on) and push notifications to your phone (optional).
- Panel: state (active / locked / standby / warning only), today's P/L against the limit and target, maximum loss floor and remaining room, time to the new day, scope, open positions and pending orders, and the reason when the EA cannot close (for example Algo Trading is off).
- English or Japanese, chosen automatically from the terminal language.
MEASURED IN OUR TESTS (demo account, one computer)
- 26 positions and 3 pending orders were closed / deleted in about 0.6 s, with no failed and no duplicate close.
- A new position opened during a lock was closed about 0.25 to 0.4 s after it appeared.
- After the terminal was killed and started again, the lock was active right after the start.
Your times depend on your broker, your connection and your computer.
LIMITS YOU SHOULD KNOW BEFORE BUYING
- Not a guarantee. The EA closes after a limit has been reached. Fast moves, slippage, gaps (for example at the weekly open), rejected or delayed orders and a closed market can make the loss larger than the limit. In one of our tests with a daily limit of -1,500 JPY, trading stopped at -1,890 JPY.
- The EA works only while MetaTrader 5 is running and connected and Algo Trading is ON (toolbar button) and allowed in the EA settings. Right after you switch to another account the terminal may turn Algo Trading off; check the button. The panel shows when the EA cannot close.
- The daily P/L uses the equity of the whole account, not only the positions in scope: the floating loss of positions carried over from earlier days, other EAs and manual trades all count. The scope only decides what is closed.
- Changing any daily input (limit, target, reference, time zone or day start) releases the daily lock. If you loosen the limit, you can trade again on the same day. This is your decision; the EA does not prevent it.
- The maximum loss lock stays until you change the maximum loss inputs. Changing them also restarts the trailing peak that was recorded while the EA ran.
- The trailing floor follows the peak without a cap (it does not stop at the initial capital). Rules of funded-account programs differ; compare them with these settings yourself.
- If the EA was not running at the start of the day, the day-start equity is not known and is estimated from the day-start balance (marked * on the panel).
- For about 3 seconds after the start the EA reads the account history and does not set a new lock. A lock that was already saved is active from the start.
- One EA per account in one terminal: a second copy on another chart stays on standby. Copies in different terminals on the same account cannot see each other; do not run two.
- The lock is saved in the terminal where the EA runs. If you move to another terminal or computer (for example a virtual server), the saved lock does not move with it.
- The EA cannot stop another EA from opening trades. If another EA keeps opening trades during a lock, each trade is closed and each one costs spread and commission.
- Tested on hedging accounts. Netting accounts have not been tested.
- Strategy Tester: manual trades cannot be simulated there, so the EA runs a demonstration. It opens one small position on the chart symbol at intervals so that the daily lock, the closing of new positions and the maximum loss lock can be seen, and it stops opening positions after the maximum loss lock. The tester report shows only this demonstration and is not a trading result. The demonstration never runs on a real or demo account. In the tester, the New York and Central Europe day changes assume that the broker's server midnight is 17:00 New York time.
SETUP
1. Attach the EA to any one chart. The chart symbol does not limit what is watched.
2. Set the daily and maximum loss limits, the time zone of the new day and the scope. Read the note on the panel and press OK.
3. Turn on Algo Trading and allow it in the EA settings. Try everything on a demo account first.
IMPORTANT
- No profit and no maximum loss is promised. Losses can exceed the limits.
- If you use a funded-account program, check its rules yourself (how the daily loss and the drawdown are counted, when the day changes, whether such tools are allowed). The EA does not judge whether you meet any rule.
OTHER
- 34 inputs in 8 groups. The maximum slippage for closing is adjustable (points).
- Support through MQL5 messages, reply within 3 business days: installation, settings and bug reports. Questions about what or when to trade cannot be answered.
