Loading…

Daily Loss Guarantee Sizer

A daily loss limit is only a real guarantee if it accounts for the worst case of everything already committed, not just today's realised P/L. This adds up realised losses since the start of the trading day and the worst case of every open position - the loss that would occur if every single stop-loss on the account were hit - and subtracts both from the day's configured loss budget. What is left is the genuine remaining room, and from it the tool derives the largest new position this chart's symbol could take, at a given assumed stop distance, without that combined worst case being able to exceed the limit even in the worst possible sequence of ticks. This is a sizing HELPER, not an entry-signal EA, and it is explicit about what that means in MQL4: nothing lets one program override another's OrderSend call or force it to use a particular lot size. The numbers this tool computes are published as GlobalVariables under a fixed prefix (DLGS_) - RemainingBudgetMoney, RealisedLossToday, OpenWorstCase, DailyLimitMoney, a Valid flag, and MaxNewLotSize_<Symbol> for the chart's own symbol. Any EA that wants the guarantee has to explicitly call GlobalVariableGet() on these before sizing its own order. Nothing in MQL4 enforces that a strategy actually does so - the contract is a convention, not a mechanism, and this document says so plainly rather than implying otherwise. If any open position has no stop-loss at all, the worst case is unbounded and no guarantee can be computed - the tool flags this loudly (Valid = 0) rather than quietly reporting a number that understates the real risk. Notes and limitations - Advisory only. It cannot force any EA to read or respect the published GlobalVariables, and it cannot intercept or resize an order another program sends. - Worst case for an open position is measured from that position's own OPEN price to its stop-loss, not from the current market price - this is the static bound the position was originally sized against, and it does not shrink just because the position is currently sitting in profit. - Any open position missing a stop-loss makes the whole guarantee unbounded; the tool reports this via the Valid GlobalVariable rather than substituting an estimate. - Day-start balance is recorded the first time the EA sees a given server-side calendar day after attaching - if it is attached mid-day, that day's start balance is balance at attach time, not balance at actual midnight.

Expert advisor · MT4 · v1.0 · Free

About Daily Loss Guarantee Sizer

Daily Loss Guarantee Sizer is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Daily loss limit percent, Assumed stop loss pips and Magic filter. MQL source code included.

Files in the download: DailyLossGuaranteeSizer.ex4, DailyLossGuaranteeSizer.mq4, DailyLossGuaranteeSizer.txt.

Settings

SettingDefaultWhat it does
Daily loss limit percent3.0Maximum acceptable loss today, as a percent of the day's starting balance
Assumed stop loss pips30Template stop distance used to publish this symbol's max new lot size
Magic filter-1Only count open risk for this magic number; -1 = every magic (account-wide)
Scan interval sec15Seconds between recalculations
Realert cooldown min15Minutes before repeating the "budget exhausted" alert

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Risk & Lot Size · Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria