Version 1.0 | MetaTrader 5 | Account risk utility
RiskFrame Account Guard monitors the whole trading account and applies the selected protective response when a configured rule is tripped. It works with manual trading, third-party Expert Advisors, trade panels and other order sources. It does not open positions or generate signals; depending on the selected mode, it may cancel orders or close positions.
1. What You Can Do
- See daily and max-drawdown headroom on fuel-gauge plaques (optional Axis layout when Profit > 0).
- Set a buffer warning zone before the hard daily limit.
- Choose Alert, Lock or Close when a limit is tripped.
- Optionally flatten the account in Close mode after AllowFlatten + session ARM.
- Set maximum open-position and total-lot exposure limits.
- Choose Max DD period: Lifetime, Week, or Month (Inputs).
- Keep day / period trip state after a rule is tripped even if floating P/L later recovers.
- See DEGRADED when Algo Trading, baseline recovery or cancel capability is impaired.
- Optionally use Practice Tools on a separate demo account to validate responses.
Always test on a demo account first.
2. Install and First Run
- Install from the MQL5 Market.
- Restart MetaTrader 5 or refresh Navigator.
- Enable Algo Trading in the terminal toolbar.
- Attach Account Guard to one chart only.
- In EA Inputs, allow Algo Trading.
- Open Settings on the panel: choose Mode, then expand Limits to set Daily / Max DD / Buffer / Max pos / Max lots.
Important: a second chart attach is refused (one Guard per account).
The Strategy Tester cannot properly exercise this interactive panel — use a demo chart.
3. Quick Start
- Attach to one demo chart.
- Configure realistic Daily / Max DD / Buffer limits for how you trade.
- Start in Alert mode.
- Confirm the status strip shows a healthy watching state (for example WATCHING · alert).
- Trade normally and observe remaining headroom on the plaques.
- Validate the selected response on a separate demo account, optionally using Practice Tools (section 12).
4. Safe Protection Test
Use a demo account and minimal volume. Do not run aggressive tests on live or funded accounts.
- Set a small Daily limit you can reach safely.
- Start in Alert, confirm the warning path, then switch to Lock.
- Open a small position and let Day P/L move through the limit (or use Practice Tools — section 12).
- Confirm the strip shows LOCKED (or ALERT in Alert mode) and the breached limit stays marked even if Day P/L later recovers.
- Place a pending order while Lock/Close is active — Guard should cancel it on sight when Algo Trading is on.
- Open a new market position while Lock/Close is active — Guard should close that new market exposure on sight (section 6a).
- Separately test Close+ARM on demo (AllowFlatten on, ARM on chart, then trip).
- Restart the EA and confirm ARM is cleared.
5. Panel Overview
- Status strip — watching / BUFFER / LOCKED / ALERT / DEGRADED with reason. Healthy examples: WATCHING · alert, WATCHING · lock, CLOSE · NOT ARMED, WATCHING · close · ARMED.
- Daily / Max DD plaques — remaining headroom; a tripped limit keeps a marked visual state. With Profit > 0 and Goal UI = Axis: one full-width Daily axis (Budget / P/L / Goal) plus compact Max DD.
- Day P/L — live day change (stays live so you still see recovery). On Axis, center of the Daily plaque shows signed Daily P/L.
- Warning rails — budget/goal visual cues; tripped limits keep warning colour on the rails.
- Lock-state border — gold edge while Lock/Close and day/period-locked.
- Settings panel — Style (Classic|Charcoal), Goal UI (Axis|Stacked), Mode chips, ARM (Close). Daily / Max DD / Profit / Warn zone live under a secondary Limits fold (collapsed by default).
- Info icon — in-chart mini-manual.
- Practice tools (optional Input) — chart button when Show Practice Tools is on.
6. Modes
After a trip, Guard is reactive: MetaTrader still accepts orders; Guard acts after they appear. Terminology:
- Trip state — a rule is marked for its day or period (sticky until reset).
- ALERT — trip state under Alert mode (warn / mark only).
- LOCKED — trip state under Lock or Close (cancel / close-new active).
- Flatten — Close+ARM full-account close on Daily / Max DD / Profit trips.
- Alert — warns and marks state. Does not cancel pendings or close positions. Does not show trade-permission DEGRADED for AutoTrading-off (monitoring still works).
- Lock — cancels new pending orders and closes new market exposure on sight. Positions already open at trip time are kept. Strip: LOCKED … · close new.
- Close (not armed) — same as Lock for cancel + close-new. Strip: CLOSE · NOT ARMED or LOCKED … · Close NOT ARMED (close new).
- Close (armed) — Lock behaviour plus account flatten on Daily / Max DD / Profit trips. Requires AllowFlatten (Inputs) + session ARM. ARM does not survive restart. Exposure caps reduce excess in Lock/Close (section 6b), with or without ARM.
Mode behaviour after a trip
- Show warning / status: Alert yes · Lock yes · Close (not armed) yes · Close (armed) yes
- Cancel new pending orders: Alert no · Lock yes · Close (not armed) yes · Close (armed) yes
- Close new market exposure (Daily/Max DD/Profit lock): Alert no · Lock yes · Close (not armed) yes · Close (armed) yes
- Reduce excess over Max Positions / Max Lots: Alert no · Lock yes · Close (not armed) yes · Close (armed) yes (offending ticket/symbol — section 6b)
- Close positions already open at Daily/Max DD/Profit trip time: Alert no · Lock no · Close (not armed) no · Close (armed) yes (full flatten)
- ARM survives restart: no (Close only)
6a. New market exposure (Lock / Close-new)
When Lock or Close becomes active, Guard captures a lock snapshot: each open position ticket and its volume at trip time. Those tickets/volumes are grandfathered. Guard then closes only exposure that is beyond that snapshot.
Hedging accounts
- A position ticket that did not exist at trip time is new exposure and is closed fully (newest first).
- Tickets present in the snapshot are not closed, as long as volume is not above the snap volume.
- A pending order that fills after the trip creates a new ticket and is treated as new exposure (full close).
Netting accounts
- There is typically one position ticket per symbol. If volume on a known ticket increases above the snap volume, Guard closes only the excess volume (partial close back toward the snap volume), newest excess first.
- If volume decreases or the position is fully closed, Guard takes no close action for that reduction.
- A full close followed by a new opposite position usually creates a new ticket → treated as new exposure and closed fully.
Other cases
- Several deals in a short window: Guard processes newest excess first, one close at a time. The timer and trade events continue enforcement on later ticks.
- Failed or partial close: that pass stops; the failure is audited. Guard retries on subsequent evaluations while still locked. Persistent cancel failures contribute to DEGRADED.
- Restart / re-attach while still tripped: the in-memory lock snapshot is not restored from disk. On attach, if Lock/Close-new is still required, Guard captures a new snapshot from positions present at attach. Positions opened while Guard was offline become grandfathered at that moment. Prefer keeping Guard attached during lock periods when you rely on close-new.
6b. How excess exposure is reduced (Max Positions / Max Lots)
When Max Positions and/or Max Lots is exceeded, Guard trips exposure state. In Alert mode it only warns and marks status (no cancel, no close). In Lock and Close it reduces exposure to the active caps. This is different from Daily / Max DD / Profit locks, which grandfather positions open at trip time.
Reduction always targets the exposure that just exceeded the cap — the ticket and symbol of the most recent inbound deal (volume-add or new position), not an older ticket on another chart.
- Max Positions over: that ticket is closed fully, then totals are rechecked.
- Max Lots over (count already ok): only the excess volume is closed on the offending ticket (partial close). Example: Max Lots = 3, EURUSD 2 + USDJPY 1, then +1 on EURUSD → 1 lot is closed on EURUSD; USDJPY stays.
- It continues until position count is at or under Max Positions (if set) and total lots are at or under Max Lots (if set).
- Both active caps are considered in the same loop (position-count first when both are breached).
- After closes (Lock/Close), Guard cancels remaining pending orders.
- At capacity in Lock/Close (count or lots already at the max, not yet over), Guard cancels new pendings so further orders cannot stack. Alert never cancels.
- If a close fails, that pass stops; outcome is audited. Guard may retry later while still over the cap.
Examples
- Max Positions = 1, three hedging tickets: the tickets that pushed over the cap are closed until one remains.
- Max Lots = 5, netting position 10 lots: partial close of 5 lots on that position → 5 lots remain.
- Max Lots = 3, EURUSD 2 + USDJPY 1, add 1 on EURUSD: partial close of 1 lot on EURUSD → EURUSD 2 + USDJPY 1 remain.
- Hedge or netting, Max Positions = 2, open a third ticket: that third ticket is closed fully.
7. Axis Goal layout (Profit > 0)
When Profit target is greater than zero and Goal UI = Axis:
- Budget Left and Goal Left show remaining room on each side.
- Daily P/L (center) shows the current signed day result ($ or %, click to toggle).
- The bar is centered at zero: negative P/L fills left toward the daily boundary; positive P/L fills right toward the goal.
- Left and right halves are equal (50/50 scale).
- Buffer is a warning pocket on the daily side — not a second hard trip.
- If a limit has already tripped, recovering Day P/L does not clear that trip.
- Title bands still follow live Day P/L after a goal hit: goal title stays pale green only while P/L is positive; daily title turns pale red if P/L reverses negative.
- Daily and Goal can both be tripped on the same day if P/L swings through both thresholds.
When Profit = 0, Axis is not used; Daily and Max DD appear as separate plaques (Stacked layout).
8. Limits, models and examples
- Daily model — Equity: day P/L = current equity − day-start equity. Example: day-start equity 10 000, equity now 9 850 → day P/L = −150. Daily limit 2% of day-start equity = 200, so about 50 of daily budget remains.
- Daily model — Balance: same idea using balance instead of equity (floating open P/L is excluded from the day change).
- Buffer: warning zone before the hard daily limit. Example: daily limit 200, buffer 10% → BUFFER status as remaining daily room falls into the last 20 of the budget.
- Max DD — trailing: drawdown from the equity high-water inside the active DD period.
- Max DD — static: drawdown from the period anchor (period start reference), not from a moving high-water.
- Max DD period: Lifetime (no auto clear), Week (Mon–Sun on the reset-hour clock), or Month (calendar month on the reset-hour clock). Week/Month rollover resets the DD window and clears a Max DD trip. No Day period — Daily budget covers the day.
- Profit target: optional daily threshold that triggers the selected response and remains tripped until the next daily reset.
- Max positions / max lots: hold up to the cap; trip when strictly over. Set in Settings → Limits (0 = off). Lock/Close reduce excess on the offending ticket/symbol (section 6b) and cancel new pendings at capacity. Alert only warns. Stored per account.
- Reset hour: see next section.
9. Time, reset hour and persistence
- Day and Max DD period keys use broker/server trade time ( TimeTradeServer ), shifted by your Reset hour Input (0–23).
- Example: Reset hour = 0 → day rolls at server midnight. Reset hour = 22 → the “trading day” rolls at 22:00 server time.
- Week periods start Monday on that same reset-hour clock. Month periods use the calendar month on that clock.
- Attach mid-day: Guard restores the existing day baseline and trip flags (does not invent a fresh “safe” baseline).
- Terminal closed overnight: on next attach, if the day key changed, a new day is seeded and daily/profit trips clear; Max DD follows the period rules above.
- Account login change loads this login’s same-day baseline and trip flags when stored (so Day P/L stays honest when you return to an account). Only if this login has no same-day baseline does Guard force-seed from equity/balance at switch (then briefly re-anchors if AccountInfo settles while the book is flat). Chart limits (Daily / Max DD / Profit / Max pos / Max lots), Mode and buffer reload from this login’s stored chart values (or product defaults / caps off if none).
- Session ARM does not survive restart — ARM again after attach if you want Close-all.
- Corrupt / partial baseline storage → DEGRADED with Invalid baseline until a safe baseline exists (see FAQ).
10. DEGRADED
Means protection is impaired, for example:
- Terminal Algo Trading off (Lock/Close).
- EA Algo Trading disallowed (chart button / Allow Algo Trading).
- Account trade / experts disabled.
- Disconnected.
- Pending cancel failures while Lock/Close must clear orders.
- Invalid baseline (corrupt or partial stored state).
Fix the cause; do not ignore a DEGRADED strip.
11. Inputs (summary)
- AllowFlatten — master gate for Close-all.
- Daily / DD models, Max DD period, reset hour, cooldown — account policy.
- Max positions / max lots — set on the chart under Settings → Limits (not Inputs). 0 = off. Stored per account.
- Audit log — optional diagnostics file.
- Show Practice Tools — optional Practice Tools button (off by default). See section 12.
12. Practice Tools
Warning: Use Practice Tools only on a separate demo account. They may trigger real protective actions under the selected mode, including cancelling orders and closing positions.
Practice Tools are disabled by default (Show Practice Tools Input). When enabled, the chart shows a Practice tools button. While the panel is open or a Practice P/L nudge is active, the status strip shows PRACTICE TOOLS ON so simulated state cannot be mistaken for normal account state.
P/L Nudge
Temporarily adjusts the P/L value used by Guard so you can test BUFFER, Daily, Max DD and Profit Goal states without waiting for market movement. Type the offset in the editable field (it stays attached to the Practice Tools window), use − / + only to set the sign, then Apply. Clear sets the nudge to 0.
- Applied to Day P/L and to simulated equity used for Max DD.
- Does not change broker balance, equity or stored baseline Global Variables.
- Survives closing the Practice panel.
- Does not survive EA restart or re-attach (session-only).
- Apply with a draft of ±10 or larger asks for confirmation (smaller applies immediately).
Reset Trip States
Clears stored limit-trip states. This can remove an active day or period lock and must not be used as a way to bypass account rules.
- Clears Daily, Max DD, Profit and exposure trip flags, lock snapshot, cooldown, session ARM and related retry counters.
- Does not clear Practice P/L nudge by itself.
- Optional Input Reset trips also sets day-start = now: also writes day-start balance/equity and high-water to the current account (for repeated daily tests).
- Confirmation is always required.
Reseed Baselines
Creates new protection reference values from the current account state. This changes the baselines used for future Daily and Max DD calculations.
- New day key, day-start balance/equity, Max DD high-water, DD period key and static reference.
- Clears all trip states and clears Practice P/L nudge.
- Saves the new baseline; open positions are not closed. Reseed may run with positions open (it only resets references).
- Confirmation is always required. Do not reseed blindly on live or funded accounts.
Leaving simulated state
- Clear (or Apply 0) — removes Practice P/L nudge.
- Reset trip states — if practice trips left LOCKED/ALERT markings.
- Reseed baselines — if references must match live account metrics (also clears nudge and trips).
- Closing the Practice panel alone does not clear an active nudge; the strip keeps PRACTICE TOOLS ON until nudge is cleared or the EA is restarted.
13. FAQ
Why can I still open a market trade while LOCKED?
MetaTrader accepts the click at the broker. Guard cannot refuse the order at source. In Lock (and Close without ARM), after a Daily / Max DD / Profit trip Guard cancels new pendings and closes new market exposure on sight (positions already open at that trip are kept). Exposure caps are different: when Max Positions or Max Lots is exceeded in Lock/Close, Guard reduces to the cap on the ticket/symbol that just exceeded the limit. Alert mode never closes or cancels. Close+ARM also flattens the account on Daily / Max DD / Profit trips.
Why do plaques stay tripped after P/L recovers?
Trip states are intentional day/period marks, not live “headroom still open.” Daily and Profit trips stay until day reset (or Reset trip states in Practice Tools). Max DD stays for the active DD period: Lifetime until you clear/reseed; Week and Month clear the Max DD trip when that period rolls over. Live Day P/L can recover; tripped plaques stay marked so a recovered float cannot look “safe.”
Can Daily and Goal both trip on the same day?
Yes. If floating P/L swings through both thresholds, both trip states can be active. Each limit is an independent day/period state; live Day P/L still shows the current day change.
Why DEGRADED after I turned AutoTrading on?
Also enable Allow Algo Trading on the EA (chart button). Terminal AutoTrading and EA permission are separate.
Can I run Guard on two charts?
No. The second attach is refused so account state stays consistent.
What should I do if Guard reports Invalid baseline?
Stop adding new exposure and confirm the correct trading account is connected. Reload the EA once. Guard does not silently invent a new baseline when stored keys are corrupt or partial — it stays DEGRADED on purpose. Do not reseed blindly on a live or funded account: Reseed creates new protection references and changes available headroom. Prefer verifying recovery on a separate demo account first (Practice Tools → Reseed baselines). Enable audit logging if you contact support.
14. Using Account Guard with a Trade Manager
Account Guard works independently and does not require a separate trade-management product. When used alongside a trade manager, the trade manager handles individual order planning while Account Guard monitors account-wide limits.
15. Support
Product Comments or private messages on MQL5. Enable audit logging if a support log is requested.
Links
RiskFrame Account Guard MT5: https://www.mql5.com/en/market/product/187027


