MT5 Risk Manager: Setup Daily Loss Limits and Account Protection
1. What Risk Manager MT5 Does
Risk Manager Pro MT5 is an account-level protection Expert Advisor for MetaTrader 5. Attach it to one chart, configure the limits and actions that match your trading plan, and let it continuously monitor account activity, close positions, and delete pending orders when a configured rule is reached.
Account Protection, Not a Pre-Trade Lot-Size Calculator
Risk Manager MT5 is not a pre-trade lot-size calculator. Its documented role is to monitor account and trade state after attachment and enforce the limits you configure, including daily or weekly loss, equity and drawdown, open-position and loss counters, trading-session rules, notifications, and supported close or shutdown actions.
Use position sizing and a per-trade Stop Loss when planning an entry. Use Risk Manager as an additional account-level enforcement layer for the rules that must continue to be checked across manual trades and Expert Advisor activity.
Official Links
Contents
- Account-wide protection scope and installation
- Daily, weekly, equity, and drawdown calculations
- Simple and trailing-limit behavior
- Input parameters and configuration examples
- Controlled demo-account testing
- Runtime requirements and practical safeguards
- Troubleshooting and frequently asked questions
- Final checklist before live trading
The EA can control:
- minimum account equity;
- daily and weekly loss limits;
- daily and weekly profit targets;
- daily percentage drawdown;
- maximum number of trades and losing trades;
- consecutive losses;
- maximum number of open positions;
- loss of one position or all open positions;
- grid exposure in one direction;
- allowed trading hours;
- alerts, push notifications, email notifications, another EA's chart, and terminal shutdown.
Operating boundary: Risk limits act as enforcement triggers. Final fills can differ from a configured threshold during fast markets, gaps, slippage, rejected orders, lost connectivity, terminal/VPS interruption, or broker restrictions. For continuous protection, keep MT5 connected and configure a practical safety buffer for the markets you trade.
2. Account-Wide Protection Scope
Attach one instance of Risk Manager to one chart. The chart symbol does not limit normal account monitoring.
By default, the EA monitors and may close positions across the entire MT5 account, including positions on other symbols and positions opened by other Expert Advisors. This is intentional for account-level protection.
If CheckOnlyOrdersWithoutMagic = true , only trades with Magic Number 0 are included in the applicable calculations and closing actions. This normally means manually opened trades, although another EA can also use Magic Number 0 .
For a persistent stop-after-limit workflow, use CloseChartWithOtherEAAfterLimitOverrun to stop the source EA chart or CloseTerminalAfterLimitOverrun to close the terminal after the account-wide protection action runs.
3. Installation and First Launch
- Install Risk Manager MT5 through the MQL5 Market in MetaTrader 5.
- Open any liquid symbol chart. The timeframe is not important for the risk calculations.
- Drag Risk Manager from Navigator → Expert Advisors onto the chart.
- In the Common tab, enable Allow Algo Trading.
- Configure the required parameters in the Inputs tab.
- Click OK and make sure the Algo Trading button in MT5 is enabled.
- Keep MetaTrader 5 and the chart running. A VPS is recommended for continuous protection.
MetaTrader's official Virtual Hosting documentation describes running robots on a hosted terminal around the clock. After migrating to a VPS, verify that Risk Manager, its inputs, the required symbols, and Algo Trading are active in the hosted environment.
After installation, test the settings on a demo account before using them on a live account.
4. How the Calculations Work
All money values use the deposit currency of the trading account. For example, on a USD account, DayLimitToLose = 500 means USD 500.
Daily statistics use the broker server's calendar day. Weekly statistics start on Monday according to broker server time. Trading-session hours also use broker server time, not local PC time.
When countOpenedPositions = true , floating profit/loss and swap from open positions are included in daily and weekly results. Open positions are also counted in the daily trade and daily loss counters. When it is false , those aggregate daily and weekly counters are based on closed deals only.
CountBrokerCommission and CountSwaps determine whether commission and swap are included where supported by the relevant calculation.
5. Simple Limit vs Trailing Limit
TypeOfLimit selects the reference used by the main loss and drawdown controls.
SimpleLimit
The daily or weekly result is compared with the configured limit for the current broker day or week.
Example:
- start-of-day balance: USD 10,000;
- CheckDayLimit = true ;
- DayLimitToLose = 300 ;
- current daily result: -USD 305.
The limit is breached and the EA attempts to close the monitored positions and delete monitored pending orders.
TrailingLimit
The EA records the highest tagged account equity and compares current equity with that high-water mark.
Example:
- highest tagged equity: USD 10,800;
- DayLimitToLose = 500 ;
- current equity: USD 10,295.
The equity has fallen USD 505 from the tagged maximum, so the trailing limit is breached.
ResetTrailingLimitDaily = true resets the high-water reference to current equity at the beginning of each new broker day. When it is false , the tagged maximum persists through an MT5 terminal global variable.
6. Input Parameters
Account Protection
| Parameter | Description |
|---|---|
| CheckLimitToLose | Enables an absolute minimum-equity floor. |
| TotalLimitToLose | Account equity level below which the EA closes monitored trades. This is an equity value, not a loss amount. |
| TypeOfLimit | Selects SimpleLimit or TrailingLimit for relevant loss controls. |
| ResetTrailingLimitDaily | Resets the trailing high-water equity at the start of each broker day. |
Example: on a USD account, TotalLimitToLose = 9,000 means close when account equity falls below USD 9,000.
Daily Limits
| Parameter | Description |
|---|---|
| CheckDayLimit | Enables the daily loss limit in account currency. |
| DayLimitToLose | Maximum daily loss amount. Enter a positive number. |
| CheckMaxDrawdownPercentagePerDay | Enables the daily drawdown percentage limit. |
| MaxDrawdownPercentagePerDay | Maximum allowed daily drawdown in percent. |
| CheckMaxProfitPercentagePerDay | Closes monitored exposure after the daily profit percentage target is exceeded. |
| MaxProfitPercentagePerDay | Daily profit target in percent. |
| CheckMaxProfitPerDayLimit | Enables a daily profit target in account currency. |
| ProfitDayLimitToClose | Daily profit target amount. |
| CheckMaxDayTradesAmount | Enables the daily trade-count limit. |
| MaxDayTradesAmount | Maximum daily trade count. The trigger is reached when the count is equal to or above this value. |
| CheckMaxLossesPerDayAmount | Enables the daily losing-trade counter. |
| MaxLossesPerDayAmount | Configured daily losing-trade limit. |
| CheckMaxLossesInARow | Enables the consecutive-loss counter for the current broker day. |
| MaxLossesInARow | Configured consecutive-loss limit. |
Daily profit controls provide a “stop after target” rule for existing monitored exposure. Combine them with the chart-close or terminal-close action when your workflow must also stop the source of new orders.
Weekly Limits
| Parameter | Description |
|---|---|
| CheckWeekLimit | Enables a weekly loss limit in account currency. |
| WeekLimitToLose | Maximum weekly loss amount. |
| CheckWeekLossPercentage | Enables the weekly loss percentage limit. |
| WeekLossPercentage | Maximum weekly loss percentage. |
| CheckWeekProfitLimit | Enables a weekly profit target in account currency. |
| WeekProfitLimit | Weekly profit target amount. |
| CheckWeekProfitPercentage | Enables a weekly profit percentage target. |
| WeekProfitPercentage | Weekly profit target in percent. |
Position Management
| Parameter | Description |
|---|---|
| CheckMaxOpenedOrdersAmount | Enables the maximum open-position count. |
| MaxOpenedOrdersAmount | Maximum permitted number of open positions. The action occurs when the count becomes greater than this value. |
| MaxOpenedOrdersCloseToFitTheLimit | If true , closes one position to reduce the count; if false , closes all monitored exposure. |
| CheckMaxLossPerTrade | Enables a maximum floating loss for each position. |
| MaxLossPerTrade | Loss amount at which the individual position is closed. |
| CheckMaxAllOpenedPositionsLoss | Enables a combined floating-loss limit in account currency. |
| MaxAllOpenedPositionsLoss | Maximum combined floating loss. |
| CheckMaxAllOpenedPositionsLossPercent | Enables the combined floating-loss percentage limit. |
| MaxAllOpenedPositionsLossPercent | Maximum combined floating loss as a percentage of current equity. |
| AntiGrid | Enables protection against too many same-direction positions on one symbol. |
| maxOrdersInGrid | Maximum same-direction grid size before the newest excess position is closed. |
Example: with MaxOpenedOrdersAmount = 5 , the EA acts when a sixth monitored position appears. With MaxOpenedOrdersCloseToFitTheLimit = true , it attempts to remove one excess position instead of flattening everything.
Example: with AntiGrid = true and maxOrdersInGrid = 3 , a fourth BUY position on the same symbol is treated as excess. BUY and SELL directions are counted separately.
Trading Session Control
| Parameter | Description |
|---|---|
| UseTradingSession | Enables enforcement of permitted trading hours. |
| SessionStartHour , SessionStartMinute | Start of the allowed session in broker time; inclusive. |
| SessionEndHour , SessionEndMinute | End of the allowed session in broker time; exclusive. |
An ordinary session such as 08:00–20:00 is supported. An overnight session such as 22:30–04:30 is also supported. If start and end are identical, the window is treated as 24 hours.
Any monitored exposure found outside the allowed session is closed. Use this control to enforce the permitted holding window and keep entry scheduling in your trading strategy or source EA.
Risk Counting Options
| Parameter | Description |
|---|---|
| countOpenedPositions | Includes open-position floating P/L in daily and weekly calculations and counters. |
| CountBrokerCommission | Includes broker commission in closed-deal results. |
| CountSwaps | Includes swap in supported closed and open-position calculations. |
| CheckOnlyOrdersWithoutMagic | Restricts applicable monitoring and closing actions to Magic Number 0 . |
For the strictest account-level protection, leave countOpenedPositions , CountBrokerCommission , and CountSwaps enabled.
Actions on Limit Breach
| Parameter | Description |
|---|---|
| CloseChartWithOtherEAAfterLimitOverrun | Closes another open chart with the specified symbol after a supported breach. This can stop an EA attached to that chart. |
| ChartSymbolToClose | Symbol of the other chart to close. Broker suffixes must match, for example EURUSD.a . |
| CloseTerminalAfterLimitOverrun | Enables MT5 terminal shutdown after a supported breach. |
| CloseTerminalImmediately | If true , closes MT5 immediately; otherwise uses the delay. |
| SecondsBeforeClose | Delay before terminal shutdown. |
The chart-closing option identifies a chart by symbol. If several charts use the same symbol, more than one matching chart may be closed. The Risk Manager's own chart is excluded.
Notifications and Display
| Parameter | Description |
|---|---|
| SendPushNotifications | Sends MT5 push notifications after successful closing actions. Configure MetaQuotes ID under Tools → Options → Notifications. |
| SendEmailNotifications | Sends email after successful closing actions. Configure email under Tools → Options → Email. |
| TurnOnComments | Displays active limits and current values on the chart. |
| FontSize | Chart-panel font size. |
| FontColor | Chart-panel text color. |
7. Recommended Configuration Examples
These are examples only. They are not financial advice and must be adapted to the account, strategy, broker, and risk tolerance.
Example A — Conservative Manual-Trading Guard
Account balance: USD 10,000.
CheckLimitToLose = true TotalLimitToLose = 9000 TypeOfLimit = SimpleLimit CheckDayLimit = true DayLimitToLose = 200 CheckMaxDrawdownPercentagePerDay = true MaxDrawdownPercentagePerDay = 2 CheckMaxDayTradesAmount = true MaxDayTradesAmount = 5 CheckMaxLossesInARow = true MaxLossesInARow = 3 CheckMaxOpenedOrdersAmount = true MaxOpenedOrdersAmount = 2 CheckOnlyOrdersWithoutMagic = true
Purpose: control manual trades only, stop excessive activity, and maintain an absolute account-equity floor.
Example B — Prop-Style Daily Protection
Account equity near USD 50,000; internal daily loss allowance USD 1,500.
TypeOfLimit = SimpleLimit CheckDayLimit = true DayLimitToLose = 1200 CheckMaxDrawdownPercentagePerDay = true MaxDrawdownPercentagePerDay = 2.4 countOpenedPositions = true CountBrokerCommission = true CountSwaps = true CloseChartWithOtherEAAfterLimitOverrun = true ChartSymbolToClose = EURUSD SendPushNotifications = true
Purpose: use a buffer below an external USD 1,500 rule because execution costs and slippage can make the realized close worse than the trigger value.
Example C — Lock in Gains with a Trailing Equity Limit
TypeOfLimit = TrailingLimit CheckDayLimit = true DayLimitToLose = 300 ResetTrailingLimitDaily = true countOpenedPositions = true
If equity rises to USD 10,700 and then falls below USD 10,400, the USD 300 trailing threshold is breached. At the next broker day, the high-water reference is reset to current equity.
Example D — Limit Portfolio Floating Loss
CheckMaxLossPerTrade = true MaxLossPerTrade = 150 CheckMaxAllOpenedPositionsLoss = true MaxAllOpenedPositionsLoss = 500 CheckMaxAllOpenedPositionsLossPercent = true MaxAllOpenedPositionsLossPercent = 4
Purpose: close an individual position below -USD 150, or flatten monitored exposure when combined floating loss exceeds either USD 500 or 4% of current equity.
Example E — Overnight Trading Session
UseTradingSession = true SessionStartHour = 22 SessionStartMinute = 30 SessionEndHour = 4 SessionEndMinute = 30
Positions are permitted from 22:30 through 04:29 broker time. Monitored exposure held outside that interval is closed.
8. Safe Testing Procedure
- Use a demo account.
- Enable only one protection rule at a time.
- Choose a very small test threshold that can be reached safely.
- Open a minimum-volume test position.
- Confirm that the chart panel updates.
- Confirm that the expected position closes and pending orders are removed.
- Check Toolbox → Experts and Journal for execution messages or broker errors.
- Test notifications separately.
- Restore realistic limits before live use.
Do not test terminal shutdown or chart closure on an account that is running important Expert Advisors.
9. Practical Risk Guidelines
- Set internal limits below any broker or prop-firm maximum to allow for slippage and costs.
- Use one Risk Manager instance per account, not one per symbol.
- Run MT5 on a stable VPS close to the broker server.
- Keep Algo Trading enabled and verify the smile/EA status on the chart.
- Do not remove the chart or close MT5 while protection is required.
- Use push notifications as monitoring, not as a substitute for automatic protection.
- After deposits, withdrawals, broker-time changes, or a new trading week, verify the displayed reference values.
- Test both normal and overnight sessions if session control is enabled.
- If other EAs can reopen trades, configure a method to stop those EAs after a breach.
10. Troubleshooting
The EA is attached but does not close trades
Check that Algo Trading is enabled globally and for the EA. Review the Experts and Journal tabs for rejected close requests, market-closed messages, invalid filling mode, or connectivity errors.
The daily result differs from my manual calculation
Check countOpenedPositions , CountBrokerCommission , and CountSwaps . Also verify broker server time and whether a closing transaction was recorded as more than one deal.
The session uses the wrong time
Session inputs use broker server time. Compare the time shown in Market Watch with your intended schedule.
Trades from another EA are also closed
This is normal account-level behavior. For a Magic Number 0 -only workflow, set CheckOnlyOrdersWithoutMagic = true ; the current version supports this focused filter rather than a custom Magic Number whitelist.
New trades appear after a limit closes everything
The trading source is still active. Configure chart closure for the other EA, terminal shutdown, or disable that strategy after the breach.
Push or email messages are not received
Configure and test the relevant MT5 service under Tools → Options. Notifications are sent after successful closing actions; a rejected close can therefore produce a different result.
11. Frequently Asked Questions
Does the chart timeframe matter?
No. The EA uses account, position, order, deal-history, and broker-time data.
Does it protect all symbols?
Yes, by default it works at account level, not chart-symbol level.
Can it work with both manual trading and Expert Advisors?
Yes. By default it monitors both. The Magic Number 0 option can narrow applicable activity.
Will it work while my PC is off?
No. MT5 must be running and connected. Use a suitable VPS for continuous operation.
Can the final loss exceed my limit?
Yes. The EA reacts when the threshold is detected, but the final execution price depends on liquidity, gaps, slippage, connection quality, and broker execution.
Does a profit target prevent all future trading that day?
It closes current monitored exposure. To prevent another EA from reopening trades, also stop its chart or close the terminal.
12. Final Checklist Before Live Trading
- One Risk Manager instance is attached.
- Algo Trading is enabled.
- The intended account scope is understood.
- Money values match the account currency.
- Broker server time is verified.
- Commission, swap, and floating P/L options are correct.
- Limits contain a safety buffer for execution costs.
- Notifications have been tested.
- Chart/terminal shutdown behavior has been tested on demo.
- MT5 will remain online on a stable PC or VPS.
Risk Manager MT5 should be treated as the last layer of account protection. It works best together with sensible position sizing, stop losses, strategy-level controls, stable infrastructure, and regular supervision.


