Position Manager with Loss Lock and Lot Sizer MT4
- Utilities
-
Kazuma Uezono
MQL5 / MQL4 / Pine Script v6 developer and active trader.
Seller on the MQL5 Market (indicators for MT4/MT5).
Services:
- TradingView Pine Script to MT5/MT4 conversion (bar-by-bar matching, with tester report)
- MT4 to MT5 migration - Version: 1.8
- Updated: 17 November 2026
- Activations: 5
Position manager for MetaTrader 4. You open your trades; this EA looks after them from one panel on the chart and applies the rules you set: a stop loss and take profit for trades that have none, break-even, trailing stop, two-step partial close, a daily loss limit or profit target, and a maximum loss lock for accounts with an overall loss rule. An order panel sizes the lot from your risk before you send. The panel on the chart is titled "Trade Manager".
It is a management tool. It does not look for entries, gives no signals and never trades by itself on a live account: a position is opened only when you click the order button on its panel twice. You make every trading decision and you are responsible for the result.
READ FIRST: HOW THE MT4 VERSION DIFFERS
- No news filter. MetaTrader 4 has no built-in economic calendar, so this version cannot pause or close trades around news releases.
- A partial close creates a new ticket. When part of a position is closed, MT4 gives the rest a new ticket with the comment "from #<old ticket>". The EA reads this comment and carries the state (initial stop, R, partial-close progress) over to the new ticket. If your broker does not use this comment format, the state is lost after the first partial close: the second partial close and the functions based on R do not continue on the remaining position.
- Accounts that reject SL / TP on market orders (error 130): the panel then sends the market order without stops and adds the panel's SL / TP right after the position opens. For a short moment the position has no stop.
- History depends on the "Account History" tab. MT4 lets an EA read only the period selected in that tab. The automatic initial capital and the day's closed P/L are calculated from that period. Select "All History", or type the initial capital in the inputs.
- Server time is estimated from your computer clock. Keep the clock correct (automatic time sync); otherwise the day start of the daily limit can shift.
- Panel items that change only with time are refreshed on the next price tick, so in a quiet market they can lag a little.
- Orders and closes are sent one at a time and the EA waits for each reply, so "Close all" with many positions can take a few seconds.
NOTHING CHANGES UNTIL YOU SWITCH IT ON
With the default inputs the EA does not modify, close or open anything. Each function has a button on the panel (and an input for its state at start). Check the settings, then switch on only what you need. Try everything on a demo account before using a live account.
MANAGING OPEN TRADES
- Stops for trades without them: if a new trade has no SL or TP, the EA adds one at a distance in pips, as an ATR multiple, or as an amount of account currency. An SL or TP that already exists is left as it is.
- Break-even: once the trade is in profit by a number of pips or by a multiple of R (R = initial stop distance), the stop goes to entry plus an offset.
- Trailing: fixed pips, ATR multiple, or the low / high of the last N closed bars. It starts at once, after X pips, after X R, or after break-even. The stop is never moved against you.
- Partial close: up to two steps, each at a profit in R and a percentage of the initial lot (default step 1: 50 % at 1R).
- Six ON / OFF buttons: SL/TP, BE, Trail, Partial, Daily, Max loss.
- Four action buttons, each confirmed by a second click: Close all, Close buys, Close sells, SL to break-even.
- Target trades: this chart's symbol or every symbol; manual trades, one magic number, or every trade on the account. Trades already open when you attach the EA are left alone unless you select them.
DAILY LIMIT AND DAILY TARGET
- Set in account currency or as a percentage of the balance or equity at the start of the day. Closed and open P/L both count.
- The day can start on server time, UTC, New York or Central European time (daylight saving included), Japan time or a fixed UTC offset, at the hour and minute you choose.
- When the limit or target is hit, trades in scope are closed, their pending orders can be deleted, and by default any trade opened later that day is closed as well. The order panel stays blocked until the next day start.
- The daily lock is released before the next day start if you change a daily setting (limit, target, time zone, hour, minute or basis), the target trades, the scope of closing, or the chart symbol when only this chart's symbol is managed.
MAXIMUM LOSS LOCK
- For accounts with an overall loss rule. Limit in account currency ("Money (account currency)") or as a share of the initial capital ("Percent of initial capital").
- Up to version 1.02 that percent choice was shown as "Percent of the day-start basis", although the floor was always based on the initial capital. Version 1.07 fixes only the label, so .set files you saved earlier keep working.
- The floor is measured in one of three ways: static (initial capital minus limit), trailing the highest balance, or trailing the highest equity seen while the EA runs.
- Initial capital: typed in, or worked out from the history (deposits and withdrawals included; see the "Account History" point above). Equity without credit is compared with the floor.
- At the floor, trades in scope are closed, pending orders can be deleted, and new trades in scope keep being closed. The lock survives a restart and is lifted only when you change the maximum loss settings.
- What the limits close: the target trades above, or everything on the account (manual trades and all EAs).
ORDER PANEL (this chart's symbol)
- Lot from risk: % of balance, % of equity, an amount of money, or a fixed lot, with an optional lot cap.
- Market, limit or stop orders. Drag the entry line for pending orders and the SL / TP lines to set distances; TP is set as a risk:reward ratio. Default SL = ATR x 1.
- The lot and the money at risk are shown before sending. The order goes out on the second click.
- No order is sent when the SL is under 3 x the current spread, when the SL or entry is inside the broker's stop level, or while a daily or maximum loss lock is active.
- If the broker does not answer an order, the EA searches the order list for up to 15 seconds and does not accept the order button during that time and just after. A fill can still arrive after the 15 seconds: look at the "Trade" tab before clicking again.
ONE COPY PER TARGET
- Please keep to one copy for each target (overlapping symbol and magic number settings). If two copies on the same account in the same terminal still cover the same trades, one manages and the other stands by: it does nothing and sends no alerts or notifications. Copies in two different terminals do not know about each other.
- The manager is the copy that was put on the chart first, also after a timeframe or input change and after a terminal restart. A copy brought back by a template or a profile is treated as the newer one.
- If the managing copy may not trade ("Allow live trading" unticked in its own settings), the other copy takes over. Tick the box again and the first copy manages again; for up to about 2 seconds during that switch both copies can act.
- Just after loading (attaching, terminal start, template or profile, but not a timeframe or input change) the EA spends about 3 seconds looking for other copies and manages nothing. The panel reads "Starting: checking for other Trade Manager copies". A daily or maximum loss lock reached in those seconds still closes the trades once the check is over, but the alert for it may not be shown.
ALSO GOOD TO KNOW
- English or Japanese, following the terminal language. Popup and push alerts. The panel can sit in any corner and can be collapsed. Inputs are arranged under 14 headings.
- MT4 version: if the Windows "Language for non-Unicode programs" cannot display Japanese, the panel and its messages switch to English automatically, even when Japanese is selected (an MT4 limitation).
- A limit does not guarantee the size of a loss. The EA acts after the level is crossed; gaps, fast markets, requotes or rejected orders, a lost connection or a closed terminal can make the loss larger. It works only while MT4 is running and connected and AutoTrading is on.
- Anything you switch off (panel button, input, AutoTrading) is not enforced.
- Another EA can still open trades; during a lock they are closed again each time, and each time costs the spread.
- Commission and swap are left out of the lot size, money-based SL / TP and R; the limits use the real account P/L, which includes them.
- Pips: 1 pip = 10 points on 3- and 5-digit symbols, otherwise 1 point (for example 0.01 on a 2-digit gold or index price). Adjustable in the inputs.
- Functions based on R need a stop loss on the trade.
- If the broker replies more than 10 seconds late and the order is filled afterwards, a partial close can be done twice, leaving a smaller position than planned.
- While disconnected, a missing SL is resent about every 3 seconds until it is set.
- Withdrawals also lower the maximum loss base; the automatic initial capital can be wrong when the history contains withdrawals.
- The trailing-equity mode knows only the equity seen while running. After an abnormal shutdown some state (such as partial-close progress) can be lost. Trades opened while the terminal was closed are treated as new trades at the next start.
- Funded-account programs have their own rules. Check whether this kind of tool is allowed and how their limits are calculated; the EA does not check whether you meet any rule.
IN THE STRATEGY TESTER
Manual trading cannot be shown in the tester, so there the EA opens small demonstration trades (4 x the minimum lot by default, if the margin allows) on a fixed schedule with all functions on. The tester result shows the tool working; it is not a trading performance. The demonstration never runs on a live or demo account.
SUPPORT AND RESPONSIBILITY
- No profit is promised and no loss level is guaranteed.
- Support through MQL5 messages, reply within 3 business days: installation, settings and bug reports. Questions about what or when to trade, or about the rules of a specific funded-account program, cannot be answered.
- A MetaTrader 5 version is sold separately.
