Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

Daily loss and max loss guard - prop firm rules in one include - library for MetaTrader 5

Lukas Szyry
Lukas Szyry
Gold Trading Specialist | XAUUSD Expert Advisors
I develop rule-based Expert Advisors for gold (XAUUSD) on MetaTrader 5. My focus is on robust systems for long-term account growth: no martingale, no grid, no averaging down.
Views:
38
Published:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Most prop firm accounts are not lost by a bad strategy but by one bad day. The daily loss rule counts the floating loss too, and it counts from the start of the day, not from your last trade. A stop-loss on every trade does not help if three trades go wrong in the same morning.

This include does the counting for you and acts before the firm does:

  • daily limit in % of the initial balance (prop style) or of the day start
  • day start = balance, or the higher of balance and equity at the reset hour
  • max limit static (initial balance) or trailing (highest equity seen)
  • warning level: from e.g. 80 % of the daily limit no new trades until the next day
  • breach: closes all positions, deletes pending orders, blocks until the next day (daily) or until Reset() (max)
  • all values are kept in global variables of the terminal, so a restart in the middle of the day does not forget the day start or a breach
  • guard the whole account (magic -1) or only one EA
LS_EquityGuard guard;
guard.Init(5.0, 10.0);            // OnInit: 5 % daily, 10 % max, prop defaults
guard.Update();                   // OnTick and/or OnTimer
if(guard.CanOpen()) ...           // false after warning level or breach
guard.RoomMoney()                 // money left until the nearest limit
guard.Fits(riskMoney)             // would a full stop-loss still stay above both limits?
guard.StatusText()                // one line for the journal or Comment()

Set your limits a bit tighter than the rule of your firm: the price can jump between two ticks and the close happens on the next one. In the real tick test below the overshoot was between 0.07 and 10.27 USD on a 10,000 USD account.

The demo EA works as an account guard on a live or demo account: attach it to any chart, it opens no trades and checks once per second. Only in the strategy tester "Test lots" opens one buy per day without a stop-loss, so you can watch the guard work. The screenshot: XAUUSD real ticks October 2026, 10,000 USD, 0.3 lot per day - three daily stops, then the max stop, after that every test trade is skipped.

LS_EquityGuard_Demo journal, XAUUSD real ticks

Return-to-Mean Clock: How Many Bars Does Price Take to Come Back to the Moving Average Return-to-Mean Clock: How Many Bars Does Price Take to Come Back to the Moving Average

Measures how long price takes to come back to its moving average. The histogram shows the distance of the close from an EMA in ATR. Every time that distance first reaches a stretch level (1, 2 and 3 ATR by default), the indicator follows the stretch until the close is back at the average, runs further, or the wait is over. A panel shows, for each level, how often price came back, how often it ran further first, and the median and 80th-percentile number of bars the return took. One line can be pasted into a comment to compare symbols. It is a statistics tool and gives no trade signals.

Prop Firm Risk Manager - daily loss and trailing drawdown guard Prop Firm Risk Manager - daily loss and trailing drawdown guard

Account guard for prop-firm challenges. It does not open trades: it watches the whole account (manual trades and any EA) and closes everything before the firm's limits are broken. - Daily loss limit: closes all and blocks trading until the next day. - Max drawdown: static or trailing (can lock at the start balance); closes all and locks the account. - Optional profit-target lock, max lots / max positions, Friday close. - On-chart panel (equity, today's P/L, daily and drawdown room left) and push alerts. - Equity peak and lock are saved per account, so a restart does not reset the protection. Main inputs: StartBalance, DailyLossUSD, DDMode, MaxDDUSD, LockAtStart, safety buffers, TargetUSD, MaxOpenLots, MaxOpenPositions, FridayCloseOn, ResetLock. Attach to any one chart, any symbol and timeframe, with Algo Trading enabled.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.