Exposure Time Budget Guard
Some desks and prop-firm rules limit exposure TIME, not just position size or loss - a strategy that is technically inside every other rule but sits in the market around the clock still breaches that kind of limit, and nothing about price or P/L would ever trigger a normal risk EA to notice it. This EA tracks that directly: it samples, once per timer tick, whether at least one watched order is currently open, and accumulates that sampling interval into a running daily and weekly total. Once either total reaches its configured budget, the watched orders are flattened outright. Because the accumulator only advances while something is genuinely open, a quiet account with no positions never burns its budget just sitting there. The daily and weekly totals live in GlobalVariables, so a terminal restart mid-day or mid-week does not quietly reset the clock - the same running totals are picked back up. Once a budget is exhausted for the period, InpKeepClosingAfterBudget controls what happens to any exposure that reopens later in the same period: left alone until the next rollover, or swept away again exactly like the first breach. Notes and limitations - Exposure time is sampled, not measured continuously - a position opened and closed entirely between two timer ticks contributes nothing to the accumulator. A shorter InpTimerIntervalSec narrows this gap at the cost of more frequent order-pool scans. - Flattening requires AutoTrading to be enabled; if it is off when a budget is exhausted, the EA alerts loudly but cannot act, and says so. - The weekly label is keyed to InpWeekStartDay, not the platform's own calendar week numbering, so changing that input mid-week shifts the accumulator's rollover point immediately.
Expert advisor · MT5 · v1.0 · Free
About Exposure Time Budget Guard
Exposure Time Budget Guard is an expert advisor (trading robot) for MetaTrader 5. It has 9 settings, such as Daily budget hours, Weekly budget hours and Week start day. MQL source code included.
Files in the download: ExposureTimeBudget.ex5, ExposureTimeBudget.mq5, ExposureTimeBudget.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Daily budget hours | 8.0 | Maximum hours of exposure allowed per calendar day (0 = no daily cap) |
| Weekly budget hours | 30.0 | Maximum hours of exposure allowed per calendar week (0 = no weekly cap) |
| Week start day | 1 | Day the weekly budget resets on: 0=Sunday .. 6=Saturday |
| Magic filter | 0 | 0 = watch every position/order on the account, otherwise only this magic number |
| Keep closing after budget | true | Once a budget is exhausted, keep closing any NEW exposure for the rest of the period too |
| Dry run | false | true = alert only when a budget is exhausted, never actually flattens |
| Timer interval sec | 30 | Sampling interval for both the exposure clock and the budget check |
| Max retries | 5 | Attempts per order action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code