Lot Size Sanity Guard
- Yardımcı programlar
- Sürüm: 1.0
- Etkinleştirmeler: 5
See it work before you trust it: load Lot Size Sanity Guard into the Strategy Tester, switch on visual mode and watch a deliberately oversized demo trade open, then see it trimmed back to the allowed size a moment later, with the reason printed in the journal.
ONE EXTRA ZERO SHOULD NEVER COST YOU AN ACCOUNT.
Lot Size Sanity Guard is a utility Expert Advisor for MetaTrader 5. It does not search for entries and it does not open trades for you. It watches the size of every new position and every pending order in scope, and the moment a volume is larger than you ever intended, it acts: the position is trimmed back to the largest allowed size, or closed, or only reported, and an oversized pending order is deleted before it can fill. A slip of the finger, a wrong lot field in another Expert Advisor, a volume typed as 10 instead of 1.0, a copied signal with the wrong multiplier: all of them are caught within a second.
At a glance
• Up to four independent size rules, each one can be switched off with 0.
• Hard cap: the largest volume one trade may have, in lots.
• Typical lot rule: a multiple of your own typical lot, learned automatically from your account history.
• Margin rule: the margin of one trade as a percent of equity.
• Risk rule: the loss at the stop-loss of one trade as a percent of equity.
• The tightest active rule wins and is shown by name, so you always know why a trade was flagged.
• Trim, not kill: by default only the excess volume is closed, the trade you meant to take stays open.
• Oversized pending orders are deleted before they can turn into an oversized position.
• A reaction window, so trades that were already open before the utility started are reported, never touched.
• Re-check on stop change: adding or moving a stop-loss checks the risk rule again.
• Size headroom meter, live table with LOTS, ALLOWED, MARGIN, RULE and STATE, daily counters and quick controls.
• Chart symbol only or every symbol of the account, with any magic, one magic number or manual trades only.
• Not a grid, no martingale, no averaging, no DLLs, no extra files.
QUICK START
Attach it to any chart, for example EURUSD H1, and make sure Algo Trading is on. Keep the defaults: a hard cap of 2.00 lots, a typical lot multiple of 4, 60 days of history, 5 entries before the typical lot rule starts, 25 percent margin per trade, 5 percent risk at the stop, trim as the action, oversized pending orders deleted and a reaction window of 120 seconds. Now open a trade with a normal size: the panel lists it as OK. Open one far above the cap: within a second it is trimmed to 2.00 lots and the journal tells you exactly which rule was used.
Why fat-finger protection matters
Most trading platforms will accept any volume your margin allows. A single mistyped digit can open a position ten or a hundred times larger than planned, and on a fast market the damage happens before you notice the number. The same risk exists with Expert Advisors: a wrong input after an update, a lot multiplier copied from another account size, a signal copier that maps volumes incorrectly. A normal stop-loss does not help, because the stop is sized for the trade you planned, not for the trade that was actually opened. Lot Size Sanity Guard is the second pair of eyes that checks every size before the market has time to punish it.
What is new and different here
Learned baseline. You do not need to tell the utility what a normal lot is for you. It reads the entry deals of your account history inside the scope you selected, takes the median volume and treats a chosen multiple of it as the limit. The median ignores the occasional larger trade, so one exception in the past does not loosen the rule. Until enough entries exist, the panel shows how many it has learned and the rule simply waits.
Trim, not kill. Closing the entire position after a mistake throws away a trade you probably wanted, and pays the full spread for nothing. Here the default action closes only the excess part with a partial close, so the position is left at exactly the allowed size. If you prefer the strict way, choose close, or choose alert only to be informed without any change.
The tightest rule wins. Every active rule calculates its own allowed volume; the smallest one is used, rounded down to the volume step of the symbol and never below the minimum volume. The name of the binding rule, for example HARD CAP, TYPICAL x4.0, MARGIN 25% or RISK 5.0%, is shown in the table and written in every message.
Re-check on stop change. A trade opened without a stop cannot be measured by the risk rule. As soon as a stop-loss is added or moved, the trade is checked again, so a far-away stop on a large position is still caught.
Size headroom meter. A progress bar shows how close the largest trade in scope is to its own allowed size, green below 80 percent, amber close to the limit and red above it.
How one trade is handled
1. Detection. A new position or pending order in scope appears. The check runs on the trade event itself, on every tick and once per second.
2. Measuring. The allowed volume is calculated from every active rule, using the open price, the stop-loss and the current equity.
3. Decision. If the volume is above the allowed volume by more than half a volume step, the trade is oversized. Otherwise it is marked as checked and listed as OK, or NEAR when it uses more than 80 percent of its allowance.
4. Action. A young oversized position is trimmed or closed according to your choice. An oversized pending order is deleted. In alert only mode, or for trades older than the reaction window, only an alert is sent.
5. Record. The action is counted in TODAY, shown as LAST ACTION, printed in the journal and, if enabled, sent as a pop-up or push notification.
Inputs, every one explained
LIMITS - WHEN IS A LOT TOO BIG (0 = rule off)
InpMaxLots = 2.0. The hard cap: the largest volume one single trade may have, in lots. Set it to the biggest size you would ever open on purpose. 0 switches the rule off.
InpMaxMultiple = 4.0. The largest allowed multiple of your typical lot. With a typical lot of 0.10 and a multiple of 4, any trade above 0.40 lots is oversized. 0 switches the rule off.
InpHistoryDays = 60. How many days of account history are read to learn the typical lot. The baseline is refreshed every five minutes and on demand with the RELEARN LOT button.
InpMinSamples = 5. How many entry deals in scope are needed before the typical lot rule becomes active. Until then the panel shows learning and the other rules keep working.
InpMaxMarginPct = 25.0. The largest margin one trade may use, as a percent of equity. Useful on small accounts and on high-margin instruments. 0 switches the rule off.
InpMaxRiskPct = 5.0. The largest loss one trade may reach at its stop-loss, as a percent of equity. Only trades with a stop-loss are measured by this rule. 0 switches the rule off.
ACTION - WHAT HAPPENS TO AN OVERSIZED TRADE
InpAction = Trim. Trim closes only the excess volume and keeps the allowed part open. Close closes the whole position. Alert only changes nothing and sends an alert.
InpDeletePending = true. Delete oversized pending orders before they can fill. Off means alert only for pending orders.
InpReactSec = 120. Only positions younger than this many seconds are trimmed or closed. Older positions, for example trades that were already open when you attached the utility, are reported once and never touched.
InpRecheckOnStop = true. Check the trade again when its stop-loss is added or moved, so the risk rule can catch a large trade whose stop is placed later.
FILTER - WHICH TRADES ARE IN SCOPE
InpSymbolScope = Chart symbol only. Choose the chart symbol only, or every symbol of the account. With all symbols, one chart protects the whole account.
InpMagicFilter = Any magic. Any magic checks manual and Expert Advisor trades, Only the magic number checks one Expert Advisor, Only manual trades checks trades with magic 0.
InpMagic = 0. The magic number used when the filter is set to Only the magic number. The typical lot is learned only from trades inside the same scope.
ALERTS
InpAlertPopup = true. Show a pop-up alert in the terminal for every action.
InpAlertPush = false. Send a push notification to the MetaTrader app on your phone. Push notifications must be enabled in the terminal options.
PANEL
ShowPanel = true. Show or hide the panel. The guard keeps working with the panel hidden.
PanelX = 12 and PanelY = 15. Panel offset from the top left corner of the chart. The MOVE button lets you drag the panel anywhere.
PanelFontSize = 9. The base font size. The panel shrinks the font automatically when the chart is too small, so it always fits the screen.
MaxTableRows = 6. How many trades are listed in the in-scope table. The rest is counted below the table.
STRATEGY TESTER DEMO
InpTesterDemo = true. Only in the Strategy Tester: once per day one oversized demo position is opened, about twice the allowed size and never more than half of the free margin, so the trim can be watched. It is closed again after six hours. This never happens on a live or demo account chart.
The panel
SIZE HEADROOM shows the largest trade as a percent of its allowed size. SIZE RULES lists every rule with its current value, the action, the reaction window, the trades and lots in scope, today's counters for trim, close, delete and alert, and the last action. IN-SCOPE TRADES lists side, lots, allowed lots, margin percent, binding rule and state. The banner tells you in one line whether everything is within limits. QUICK CONTROLS: ARMED or PAUSED switches checking on and off, TRIM or CLOSE switches to ALERT ONLY and back, RELEARN LOT reads the history again at once. The minus button folds the panel to its header.
How to use it well
Set the hard cap first, as a last line of defence that never depends on history. Then let the typical lot rule learn your habits; a multiple between 3 and 5 catches typing mistakes without blocking a deliberate larger trade. Use the margin rule on small accounts and the risk rule if you always trade with a stop-loss. Run one copy with all symbols to protect the whole account, or one copy per Expert Advisor with its magic number when different strategies use very different sizes. Keep the terminal running, for example on a VPS, because a utility can only protect trades while it is running.
Good to know
The utility only touches trades that match the symbol scope and magic filter you choose. It never increases a volume, never opens trades outside the Strategy Tester, never moves stops or targets and never touches other positions. Netting accounts are supported: when a fill makes the net position oversized, the excess is closed. If the broker rejects a trim, the failure is counted in red and written to the journal.
Try it in the Strategy Tester
Open the Strategy Tester, choose Lot Size Sanity Guard, any symbol and visual mode, and press Start. You will see the oversized demo trade appear, flagged in red for a moment and then trimmed to the allowed size, with the message in the journal. Change the limits and watch how the allowed size and binding rule change.
If Lot Size Sanity Guard protects your account the way you expect, an honest review on the product page helps other traders decide, and tells me what to improve next.
