Position Manager Pro MT4
- ユーティリティ
- Hyoseog Kim
- バージョン: 1.0
Dual Magic Number Independent Group Manager with Live P&L Dashboard
Overview
Position Manager Pro is a powerful trade management Expert Advisor for MetaTrader 4 that operates as an overlay manager — it does not open positions itself, but instead manages and monitors positions opened by other EAs or manually by the trader.
The core concept is two fully independent groups, each identified by a unique Magic Number. Each group has its own Take Profit, Stop Loss, and Trailing Stop thresholds defined in dollar amounts, not pips. This makes the EA universal — it works with any symbol, any lot size, and any broker.
A compact, real-time on-chart dashboard displays everything you need at a glance: live floating P&L per group, today's closed P&L per group, and a combined summary panel showing Monthly / Weekly / Daily performance across both groups.
Key Features
- Two independent magic number groups — manage two separate EAs (or strategies) simultaneously on the same chart
- Dollar-based thresholds — Take Profit, Stop Loss, and Trailing Stop are set in account currency ($), not pips
- Combined mode — treats all positions in a group as one unit; closes all positions together when the combined P&L target is hit
- Individual mode — applies TP / SL / Trailing to each position separately
- Trailing Stop — profit-lock trailing that activates after a configurable start level, then trails by a step amount
- Historical P&L dashboard — shows today, this week, and this month closed P&L (including commission and swap) broken down by group
- One-click manual close buttons — close an entire group instantly with a single button click; optional double-click confirmation mode to prevent accidents
- Symbol filter — optionally restrict management to a single symbol
- Timer-based refresh — panel updates every 2 seconds even during low-tick periods
How It Works
Position Assignment
Positions are assigned to a group based on their Magic Number:
- Group 1 manages all positions with G1_MagicNumber
- Group 2 manages all positions with G2_MagicNumber
- Positions with any other magic number are completely ignored
Set MagicNumber = 0 to disable a group entirely.
Combined Mode (default)
All positions in the group are treated as one portfolio. The EA sums the total floating P&L (profit + swap) across all positions in the group, then:
- Closes the entire group when total P&L ≥ TakeProfit
- Closes the entire group when total P&L ≤ −StopLoss
- Activates trailing when total P&L ≥ TrailingStart, then trails at (totalP&L − TrailingStep) — ideal for grid and martingale strategies
Individual Mode
Each position is evaluated independently:
- Closes the position when position P&L ≥ TakeProfit
- Closes the position when position P&L ≤ −StopLoss
- Moves the position's SL price to lock in profit once position P&L ≥ TrailingStart
Trailing Stop Logic
Combined: The trailing stop level is stored in memory (not as a broker SL order). Once activated, the level rises as profit increases, and all positions are closed the moment total P&L drops back to the stop level.
Individual: The EA modifies the actual SL price on the broker's server as profit grows, locking in profit at (currentProfit − TrailingStep) converted to the corresponding price level.
Input Parameters
Group 1 / Group 2 Settings
| Parameter | Default | Description |
|---|---|---|
| G1_MagicNumber | 91919191 | Magic number to identify Group 1 positions. Set to 0 to disable. |
| G1_TakeProfit | 15.0 | Close all (or each) position when P&L reaches this dollar amount. Set 0 to disable. |
| G1_StopLoss | 0.0 | Close all (or each) position when P&L drops to this loss amount. Set 0 to disable. |
| G1_UseTrailing | false | Enable profit-locking trailing stop. |
| G1_TrailingStart | 2.0 | Trailing activates only after P&L exceeds this dollar amount. |
| G1_TrailingStep | 0.5 | The trailing buffer — stop level is always (peak P&L − step). |
| G1_IndividualMode | false | false = Combined mode, true = Individual mode. |
(Group 2 parameters are identical with the G2_ prefix)
UI / General Settings
| Parameter | Default | Description |
|---|---|---|
| UI_X | 10 | Horizontal pixel position of the panel (from left edge). |
| UI_Y | 30 | Vertical pixel position of the panel (from top edge). |
| TargetSymbol | "" | Leave blank to manage all symbols. Enter a symbol name (e.g. "XAUUSD") to restrict management to that symbol only. |
| RequireDoubleClick | false | If true, the Close button turns yellow and requires a second click to confirm. Prevents accidental closes. |
Setup Guide
Step 1 — Installation
- Copy Position_Manager_Pro_v1_0_MT4.mq4 to your MetaTrader 4 Experts folder: [MT4 Data Folder] → MQL4 → Experts
- Restart MetaTrader 4 or click Refresh in the Navigator panel.
- The EA will appear under Expert Advisors in the Navigator.
Step 2 — Attach to Chart
- Open any chart (symbol does not matter — use TargetSymbol to filter if needed).
- Drag and drop the EA onto the chart.
- In the Inputs tab, configure your magic numbers and thresholds.
- Ensure "Allow live trading" is checked in the Common tab.
- Click OK.
Important: Make sure your MetaTrader 4 has AutoTrading enabled (green play button in the toolbar). Without it, the EA cannot close positions.
Step 3 — Configure Magic Numbers
Match the magic numbers in this EA to the magic numbers used by the EAs that open your positions. For example:
- If your grid EA uses magic number 12345 , set G1_MagicNumber = 12345
- If your second EA uses magic number 67890 , set G2_MagicNumber = 67890
Step 4 — Choose Combined or Individual Mode
- Grid / Martingale strategies → Use Combined mode (default). The group closes only when the combined total P&L reaches the target.
- Scalpers / single-position EAs → Use Individual mode. Each position is closed independently.
Step 5 — Set Dollar Thresholds
All thresholds are in account currency (USD, EUR, etc.):
Example — Combined grid, $15 take profit, $5 trailing start, $0.50 step: G1_TakeProfit = 15.0 G1_StopLoss = 0 (disabled — let trailing handle it) G1_UseTrailing = true G1_TrailingStart = 5.0 G1_TrailingStep = 0.50 G1_IndividualMode = false
Frequently Asked Questions
Q: Can I run this EA on multiple charts at the same time? A: No. Run it on one chart only. Duplicate instances will cause conflicts and double-closes. Use the TargetSymbol parameter to restrict which symbol's positions are managed.
Q: Does this EA open its own trades? A: No. It only manages positions that were opened by other EAs or manually. No trading signals are generated.
Q: What happens if I manually close a position that the EA is tracking? A: The EA detects the closed position on the next tick and removes it from the group count. No errors occur.
Q: Can I use this alongside a hedging strategy (simultaneous Buy and Sell)? A: Yes. In Combined mode, the group P&L includes both Buy and Sell positions, so hedged positions will partially cancel each other's P&L — which is the correct behavior for a hedging setup.
Q: Why does Today P&L sometimes differ from Live P&L? A: Today P&L shows closed trades for the current day (from account history). Live P&L shows open floating profit. They will match only after all positions are closed.
Q: The panel does not appear on the chart. What should I do? A: Ensure AutoTrading is enabled, the EA is attached and running (smiley face icon in the top-right of the chart), and that UI_X / UI_Y values place the panel within the visible chart area.
Important Notes
- Requires MetaTrader 4 build 765 or later (supports #property strict , ObjectsDeleteAll with prefix, and OnChartEvent ).
- Historical P&L is read from the broker's account history. Make sure your broker provides sufficient history depth. If the broker limits history, older trades will not appear in the Monthly summary.
- Commission data ( OrderCommission() ) is included in all historical P&L calculations.
- The Trailing Stop in Combined mode is a virtual trailing (stored in memory). It is not placed as a server-side SL order. If the EA is removed from the chart or MT4 is closed, the trailing stop ceases to function.
- The Trailing Stop in Individual mode modifies the actual SL price on the server, so it persists even if the EA is disconnected.
