Trade Manager with Prop Firm Rules
- Utilità
-
Ayaz
MQL5 developer working on automated trading systems — Expert Advisors, custom indicators, and TradingView-to-MT5 conversions. - Versione: 1.0
- Attivazioni: 10
Trade Manager with Prop Firm Rules is a trade panel for MetaTrader 5. It sizes each order from your risk, manages the trades it opens, and guards a prop firm account with a daily loss and max drawdown formula you set to match your firm's. It never opens a trade you didn't ask for.
The panel
- BUY and SELL sized by risk: % of balance, % of equity, money or a fixed lot. The lot and the money at risk show before you press.
- SL in points or as a price (default 1.5 x ATR 14). TP as an R multiple (R is your stop distance), points or a price.
- Lines: entry, SL and TP lines on the chart, then Place sends a buy stop, buy limit, sell limit or sell stop.
- Partial take profit at a chosen R, break-even after the partial or at a chosen R, trailing stop in R. They act on the panel's own trades; one setting extends them to your manual trades, or to every trade on the chart's symbol.
- BE now, Close half, Close symbol. Optional hotkeys Shift+B, Shift+S, Shift+X.
- Follows a light or dark chart by itself and minimises to one line.
The prop guard
Set it the way your firm counts:
- Daily loss: the day's base is the balance at the reset, the equity at the reset, or the higher of the two. The allowance is a % of the account size, a % of the day's base, or money.
- Reset time on server time, UTC, a fixed UTC offset, New York or Central Europe time (both with daylight saving).
- Max drawdown: static, trailing on closed balance, or trailing on equity; a % of the account size, a % of the peak, or money; trailing can stop at the account size.
- A buffer (10% of the allowance by default), so it acts before the firm's line, not on it.
For the equity and higher-of bases the terminal has to be running at the reset; if it wasn't, type the day's start figure once. Trailing on equity follows the peak while the terminal runs; after time off, type the firm's peak.
At the acting level it closes every position and deletes every pending order on the account: every symbol, manual trades and other EAs included. Then the panel takes no new trades until the next reset (daily loss) or until you re-arm it (max drawdown). A trade opened elsewhere while it's locked, by hand, from the phone or by another EA, is closed too: up to 10 per lock, then it alerts instead, though anything at or past the acting level is still closed. Alerts at 50%, 80% and at the line. In alert-only mode it alerts and closes nothing. There's also an optional profit-target lock.
Rules it keeps
- An order goes out only when you press, or for a phone trade you placed with phone resize on. One press sends one order; a second click within half a second counts as the same press, and the panel says so. A held hotkey acts once.
- A lot cap and a max risk per order. Above them your order is refused with the reason, never trimmed.
- If a rule needs your account size, the day's start figure or your equity peak and doesn't have it, it shows SET UP and says what to type. It doesn't guess one.
- After a restart it reads the guard's lock, the day's base and the balance peak back from the account history, so a lost file can't unlock it. The one exception is a lock pressed with nothing open: nothing of it reaches the history, so it's kept only in that file. A max drawdown stop read back from the history refuses new trades but leaves the trades already open alone, since a re-arm may have gone with the file; it says so, and you re-arm if you had. The equity at the reset and the equity peak are kept in its own file; if that file is gone, the rule asks for them.
- One guard per account, however many charts you open. If that chart freezes, another one takes over after 30 seconds.
- If Algo Trading is off (the toolbar button or the EA's own "Allow Algo Trading"), the login can't trade or the connection drops, the panel says so in red and alerts once. It sends nothing then, and the guard can't close anything until that's fixed: a line reached meanwhile still locks, and the closes go out once it can trade. When the connection comes back it reads the account again by itself. Starting the terminal without internet doesn't trip the guard: it waits until it can read your account.
Phone trades (optional, off by default)
Open the trigger lot (0.01 by default, a setting) in the MetaTrader 5 phone app while the terminal is running. The EA on your PC or VPS gives it your default SL if it has none, then adds the volume your risk allows, with the same SL and TP: 0.5 to 0.9 s after the phone trade in 15 tries on a demo, and 1.2 s in the one try on a symbol with no chart open. On a hedging account the added part is a second position. The panel manages the part it added; set "Manage which trades" to include manual trades to manage the 0.01 too. If the add would break your lot cap or max risk, the 0.01 keeps its SL and nothing is added. A phone trade the EA first sees more than 60 s after it opened (a setting) is left as it is, SL included. While the guard is locked, the trade is closed instead (0.48 s in a test).
First steps on a prop account
- Open one chart of the symbol you trade and drag Trade Manager with Prop Firm Rules onto it from the Navigator. The Algo Trading button in the toolbar has to be on, and so does "Allow Algo Trading" in the EA's Common tab.
- In the Inputs tab, under "Prop guard", type your "Account start size", for example 100,000 for a 100k account. Then copy your firm's rules into the daily loss and max drawdown settings. "Every setting, in plain words" below says what each one does.
- Press OK. The panel opens at the top left of the chart. "Prop guard: ARMED" in green means the guard is watching. Check both rows under it: a row that reads SET UP names the figure it still needs, and that rule isn't watched until you type it.
A size far from the balance (outside 0.7 to 1.5 times) is confirmed once with OK in the inputs. Outside alert-only mode, a new size, day's start figure or equity peak that would put equity at or under its acting level at once (a typo such as 100,000 on a 10,000 account) isn't taken: the panel and an alert say why, and nothing is closed. In the Strategy Tester the deposit is the account size when "Account start size" is 0, and for a reset clock other than server time you type the server's UTC offset.
Taking a trade
- "Risk" sets the size of each trade. In the default mode it's the % of the balance a trade loses at its stop, so 1.00 means 1%. The "Risk mode" setting can make it a % of equity, an amount of money or a fixed lot.
- "SL" is the stop's distance in points. Type 0 and the box shows ATR: the stop then goes 1.5 x ATR 14 of the chart's timeframe away. The small "pts" button switches the box to "price", so you can type the stop's price instead.
- "TP" is an R multiple by default: 2.00 puts the target twice the stop distance away. 0 means no TP on BUY and SELL.
- Next to TP the panel shows the lot and the money at risk before you press. If something's wrong it shows the reason there instead, such as "risk too small for the minimum lot 0.01". The preview is worked out for a buy. With a stop price set for a sell it says the SL price is on the wrong side, and SELL still works.
- Press BUY or SELL. The line at the bottom of the panel says what happened.
What you type in the boxes, and the pts or price choice, is saved for the account, not for each chart. After a restart every chart on the account opens with the last values typed on any of them. If you change that value in the inputs, the input wins.
On a netting account with a position open, the buttons read ADD and REDUCE. ADD works out the extra volume from the open position's SL, so the position must have one. REDUCE closes part of the position, sized from your risk and never more than the position. Lines can't place a pending order while that position is open.
Pending orders with Lines
- Press Lines. Three lines appear on the chart: entry in blue, SL in red and TP in green.
- Drag them to your levels. The panel shows the lot and the risk for them, and the button beside it names the order: Place BUY STOP, BUY LIMIT, SELL LIMIT or SELL STOP.
- Press it to send the order, or press Cancel to take the lines away.
The SL line decides the side: under the entry it's a buy, above it a sell. The order takes the TP line's price as its TP. It stays until you cancel it, or until the end of the day if you choose that in "Pending order expiry".
While a trade is open
"This symbol" shows how many trades the panel manages here, their lots and their profit. The line under it shows how they're managed, for example "TP1 50% at 1.0R · BE after TP1 · trailing off".
- TP1 closes part of the trade at a chosen R: 50% at 1.0R by default.
- Break-even moves the SL to the entry after TP1, or at a chosen R, plus an offset in points if you set one. "After TP1" needs Partial TP on, and any cut of the volume counts as TP1, Close half too.
- Trailing, once you turn it on, starts at 1.5R and keeps the SL 1.0R behind the price, moving it in steps of 0.1R.
A trade too small to split, such as 0.01 lot, can't take TP1. From the TP1 level on, break-even and trailing skip it too, so if your risk gives trades that small, turn "Partial TP" off.
The SL only ever moves toward profit. The three buttons under it work right away:
- BE now moves the SL to break-even on each managed trade that's far enough past its entry.
- Close half closes half of each managed trade.
- Close symbol closes the managed trades and deletes the panel's own pending orders on this symbol.
When there's more than one to act on, Close half and Close symbol ask for a second press within 3 seconds.
To manage the trades you open by hand too, set "Manage which trades" to include manual trades. TP1, break-even and trailing work in R, and R is the stop distance a trade was opened with. A trade opened without a stop has no R, so they leave it alone, even if you add a stop later.
Reading the prop guard
"Prop guard: ARMED" comes with two rows. For example, on a 100,000 account with a 5% daily loss and equity at 98,750:
Day -1,250 / 5,000 ###....... 25% line 95,000 acts 95,500
That's 1,250 lost of today's 5,000 allowance, 25% used. The firm's line is at 95,000 equity, and the guard acts at 95,500, the line plus the buffer. The Max row reads the same way for the max drawdown, and under them is the time to the next daily reset.
The word after "Prop guard:" is its state:
- ARMED: the guard is watching, and it acts at each rule's acting level. A row that still reads SET UP isn't watched.
- WATCHING: the same with "At the line" set to alert only. It alerts and closes nothing.
- SET UP: neither rule has its figures yet. Each row says what to type.
- LOCKED: the daily loss line was reached, or you pressed Close all + lock. No new trades until the next reset.
- STOPPED: the max drawdown line or the profit target was reached. No new trades until you re-arm.
- OFF: the guard is turned off in the settings.
"(held by another chart)" means another chart on the same account runs the guard. Re-arm works only on that chart, and Close all + lock pressed here is passed on to it. "cannot trade" in red means Algo Trading is off, the connection is down or the account can't trade, and the bottom line of the panel says which.
The button at the bottom right reads "Close all + lock". It closes every position and deletes every pending order on the account, then locks until the next reset. While the guard is STOPPED the same button reads "Re-arm". Both need a second press within 3 seconds. A re-arm is refused while equity is still at or under the max acting level, or still at the profit target.
Alerts come at 50% and 80% of each allowance and at the line. They show in the terminal, and on your phone as well if push notifications are on in the terminal (Tools, Options, Notifications).
Using phone trades
- Turn on "Resize phone trades" in the inputs, and keep the terminal with the panel running on your PC or VPS.
- In the MetaTrader 5 phone app, open the trigger lot (0.01 by default), with or without a stop loss.
- If it has no stop, the EA gives it the SL from "Default SL, points" (the input, not the SL box). Then it adds the volume the Risk box allows, with the same SL and TP.
The chart that holds the guard does this while the guard shows ARMED or WATCHING, or with the guard off. While it shows SET UP a phone trade is left as it is, and while it's LOCKED or STOPPED the trade is closed instead. A phone trade that's already more than 60 seconds old when the EA first sees it is left alone. On a netting account, a phone trade that joins a position already open isn't resized.
Every setting, in plain words
Entry:
- "Risk mode": % of balance (default), % of equity, money or a fixed lot.
- "Risk": the Risk box's starting value, 1.0.
- "SL mode": points (default) or price, for the SL box.
- "Default SL, points": 0 (default) means 1.5 x ATR 14 of the chart's timeframe. Phone trades with no stop get their SL from here too.
- "TP mode": R multiple (default), points or price. "TP": 2.0, and 0 means none.
- "Max lot per order": 5.0. A bigger order is refused with the reason, never trimmed. 0 turns it off.
- "Max risk per order, %": 2.0, of the balance. A riskier order is refused the same way. 0 turns it off.
- "Max spread, points": off at 0. Above it BUY and SELL are refused.
- "Slippage, points": 30, the deviation sent with market orders.
- "Pending order expiry": good till cancelled (default) or end of day.
- "Magic number": 240611, the number on the panel's trades. It can't be 0 or the guard's 7350071 and 7350072.
- "Order comment": TM.
- "Confirm each order (second press)": off. When on, BUY, SELL and Place need a second press within 3 seconds.
- "Hotkeys Shift+B, Shift+S, Shift+X": off. When on, Shift+B buys, Shift+S sells and Shift+X does what Close symbol does. Click the chart first so it gets the keys. They don't work in the Strategy Tester.
Management:
- "Manage which trades": the panel's own trades (default), own + manual trades on this symbol, or every trade on this symbol.
- "Partial TP", "Partial TP: % of the position" and "Partial TP: at R": on, 50%, 1.0R.
- "Break-even": after TP1 (default), at X R, or off. "Break-even at R" (1.0) is for the "at X R" choice. "Break-even offset, points" (0) puts the SL that far past the entry.
- "Trailing stop": off. "Trailing: start at R" 1.5, "Trailing: distance, R" 1.0, "Trailing: step, R" 0.1.
Prop guard:
- "Prop guard": on. Turned off, the panel still works, nothing is guarded, and Close all + lock does nothing.
- "Account start size": the size your firm gave you. At 0 the rules that need it show SET UP.
- "Daily loss" and "Daily loss unit": 5, as % of the start size. The unit can also be % of the day's base, or money.
- "Day's base": balance at the reset (default), equity at the reset, or the higher of the two.
- "Day start figure": only for the equity and higher-of bases, when the terminal wasn't running at the reset. Type the equity at the last reset, as your firm shows it.
- "Reset time" and "Reset clock": 00:00 on server time by default. The clock can also be UTC, a fixed UTC offset (set "Fixed UTC offset, hours"), New York or Central Europe time, both with daylight saving.
- "Server UTC offset in the Strategy Tester, hours": only for tester runs on a clock other than server time.
- "Max drawdown", "Max drawdown unit" and "Max drawdown type": 10, % of the start size, static. The unit can also be % of the peak, or money; the type, trailing on closed balance or trailing on equity.
- "Trailing stops at the start size": off. When on, a trailing line stops rising once it reaches the start size.
- "Current equity peak": for trailing on equity after time off, type the firm's peak. At 0 it uses the peak it saved while running. With nothing saved and trades already on the account, the Max row asks you to type it.
- "Peak counted since": for trailing on closed balance. At 0 the peak is counted from the last deposit or balance adjustment that set the balance to the start size, for example the start of a new phase.
- "Buffer, % of the allowance": 10. The guard acts this much before the firm's line.
- "At the line": close all + lock (default) or alert only.
- "Enforce the lock (up to 10 closes)": on. While locked, a trade opened elsewhere is closed, up to 10 per lock. In alert-only mode nothing is closed.
- "Profit target lock, % above start": off at 0. It needs the start size. At that profit it closes everything and stops until you re-arm; in alert-only mode it only alerts.
- "Alerts at 50%, 80% and the line": on. Off silences the guard's alerts.
Phone trades:
- "Resize phone trades": off. "Trigger lot": 0.01. "Max age, seconds": 60. "Sources": the phone app (default), or the phone app and the web terminal.
Panel:
- "X" and "Y": where the panel opens the first time, 10 and 25. Once you drag it or type in a box, it opens where you left it, on every chart of the account.
- "Start minimised": off. The "-" at the top right folds the panel to one line and "+" opens it again; after that it opens the way you left it.
- "Theme": follow the chart (default), light or dark.
Strategy Tester:
- "Sample trades (tester only)": on, so the demo shows the management and the guard working.
- "Print speed counters once a minute": off. When on, it writes the time per tick to the journal.
Measured (Intel Core i5-6300U laptop, Windows 10)
- Strategy Tester, real ticks: time per tick with nothing open, median about 1 microsecond; with 30 positions managed on the chart, median 9. On a live demo chart over 8 hours with nothing open, panel drawn: 33 microseconds (the median of the one-minute medians), and the slowest single tick 2.8 milliseconds. Terminal memory 146.5 MB ten minutes after the start, 148.2 MB at the end of the 8 hours.
- On a demo account, from the trade that took equity past the acting level to its close: 316, 376, 398 and 464 ms in four trips (one through another symbol, one on the max line).
- Trades in a market that was closed at the time (an index or gold in its daily break): sent again every 5 seconds and closed at the first try the server took once that market opened, 0.46 to 34 s after its opening time in four tests (on gold the server still answered "session closed" for about the first half minute). Meanwhile the panel said so.
- Close all of 20 positions: account flat 0.51 s after the first of two presses (1.25 s in an earlier run), each position closed once.
- Two real connection drops (18 and 21 minutes) during the 8-hour live run: the alert within 0.12 s of the terminal's own "connection lost" line, and the account read again with ARMED shown 0.22 s and 0.07 s after the terminal synchronised with the server again.
- "Close all + lock" on 10 trades pressed 0.34 s after the Wi-Fi went off (off for 1 minute 45 s; the terminal itself took about 15 s to notice): each trade closed once, all 10 about 4 s after the Wi-Fi came back.
- Every daily and max line in the formulas checked against hand figures: 18 of 18 equal. The reset clock checked against Windows' own time zone rules across the 2025 and 2026 daylight saving changes: 82,474 checks (14 reset settings over 5,891 instants), 0 wrong.
Limits, stated up front
- It needs a running MetaTrader 5 terminal on a PC or VPS. EAs run in the desktop terminal, so it can't stop a click in the phone app.
- One terminal per account.
- A market that is closed can't take a close. The guard sends it again every 5 seconds until that market opens, and the panel says "market closed, retried every 5 s".
- A price gap or a large order's spread can carry equity past the line before the close fills. The buffer is there for that, and the firm's own figures always win.
- The money at risk shown is at the price asked. A server stop can fill worse in a fast market (one test: the stop filled 5.24 past the SL in price, 69.09 USD lost against the 49.80 shown).
- Reset clocks other than server time rely on the PC clock being right.
- Partial, break-even and trailing run on the chart's symbol. Open a chart for each symbol you want managed.
- Don't open a panel trade on the same symbol within 90 s of a phone trade: on a server that rewrites order comments it can count as the phone trade's add.
- In alert-only mode a manual "Close all + lock" closes at the press only; trades opened later aren't closed.
- Magic numbers 7350071 and 7350072 are the guard's own.
- Tested on hedging accounts and Windows 10.
In the Strategy Tester
The demo places sample trades so you can see the management and the guard working. They're sized down to your lot cap and max risk so they fit an ordinary deposit (your own orders are never trimmed); on a deposit of 1 or 10 even the minimum lot is too much, so it places none. A sample's spread can trip a tight line in one tick, as a real order can. Sample trades exist only in the Strategy Tester.
Questions: message me here on MQL5. Ayaz Kakepoto
