Automated Position Sizing
Calculate precise lot sizes from account balance or equity and stop loss distance, avoiding manual calculation errors before execution.
MetaTrader 4 & 5 automation guide
Forex trade management software is an automation utility or Expert Advisor (EA) running inside MetaTrader 4 or MetaTrader 5 that executes position sizing, automated stop loss and take profit placement, break-even shifts, trailing stops, and multi-stage partial exits.
Covering MT4 trade managers, MT5 trade managers, and custom trade management EAs.
Core capabilities
Effective trade management separates entry strategy from capital preservation. A dedicated trade manager enforces disciplined risk rules consistently across every trade.
Calculate precise lot sizes from account balance or equity and stop loss distance, avoiding manual calculation errors before execution.
Move stop loss to break-even after reaching a target profit distance, and trail price using fixed steps, ATR volatility, or swing points.
Close predefined percentages of a position at successive profit targets (such as 50% at 1R, 25% at 2R) while letting the remainder run.
Enforce account-level protection with maximum daily loss limits, spread filters, max open exposure gates, and emergency close-all triggers.
Execution architecture
Whether operating in MT4 or MT5, a trade manager utility consists of distinct functional modules that coordinate order entry, ticket tracking, and position modification.
A core function of forex trade manager software is converting a defined risk percentage (such as 0.5%, 1%, or 2%) into an exact lot volume. The calculation dynamically incorporates currency tick value, exchange rate, and stop loss distance in points, preventing over-leveraged orders on high-volatility pairs.
Trade management panels place visual drag-and-drop lines on MetaTrader charts for entry, stop loss, and take profit. Traders can preview risk amounts in account currency before clicking Buy or Sell, with the trade manager applying predefined risk limits instantly upon execution.
Once a position is active, the software manages the lifecycle: locking in profits by shifting stop loss to entry plus spread (break-even), scaling out partial lots at predetermined risk-to-reward ratios, and trailing the remaining position behind dynamic market structures.
For multi-pair or grid traders, a trade manager monitors aggregate open profit and loss across all tickets. It can trigger a global profit target exit, close all open trades if a daily loss threshold is reached, or delete pending orders upon market close.
Software comparison
Evaluate trade management options by code transparency, customization, execution latency, and licensing boundaries.
| Dimension | Commercial Trade Manager | Custom MQL4 / MQL5 Trade Manager | Manual Trade Execution |
|---|---|---|---|
| Source code access | Closed binary (.ex4/.ex5 only) | Full editable .mq4 or .mq5 source code | No code involved |
| License & account locks | Tied to specific accounts or monthly subscriptions | Zero account locks, run on any broker or account | No license required |
| Custom rule adaptation | Restricted to developer-defined settings and options | Fully adaptable to unique risk formulas and indicators | Dependent on manual calculation speed |
| Execution latency | Varies; potential third-party license server delay | Direct local execution inside MetaTrader terminal | Slow; manual order entry and calculation lag |
| External dependencies | Often requires custom DLLs or external installers | Pure native MQL4 or MQL5 with no external DLLs | None |
| Multi-target partial closes | Included in selected commercial utility panels | Programmable to exact lot step and scale-out ratios | Requires manual order modification while active |
The underlying trading engine differs between MetaTrader 4 and MetaTrader 5. Understanding how orders and positions are tracked is essential when designing a trade manager.
MT4 treats each entry as an independent order ticket. A trade manager selects tickets using OrderSelect(), checks the Magic Number and symbol, modifies price levels with OrderModify(), and executes partial exits using OrderClose() with fractional lot sizes.
MT5 separates orders, deals, and positions. In hedging mode, each position has a unique identifier. The standard CTrade class simplifies trade operations via PositionModify() and PositionClosePartial(), supporting both netting and hedging accounts.
// Risk % to Lot Calculation (MQL5 Example)
double CalculateLotSize(double riskPercent, double slPoints) {
double balance = AccountInfoDouble(ACCOUNT_BALANCE);
double riskAmount = balance * (riskPercent / 100.0);
double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
double point = SymbolInfoDouble(_Symbol, SYMBOL_POINT);
if(tickSize == 0 || slPoints == 0) return 0.01;
double pointsPerTick = tickSize / point;
double moneyPerLot = (slPoints / pointsPerTick) * tickValue;
double lots = riskAmount / moneyPerLot;
double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
double maxLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
double lotStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
lots = MathFloor(lots / lotStep) * lotStep;
return MathMax(minLot, MathMin(maxLot, lots));
}Production code must handle broker minimum volume steps, normalization, and account margin requirements.
Implementation workflow
Follow this five-step engineering process to design, generate, verify, and execute your own trade management software on MetaTrader.
Define position sizing basis (equity vs balance), risk percentage, break-even trigger distance, trailing stop type (fixed points, ATR, or bar highs/lows), and partial close milestones.
Use Pineify AI Coding Agent to generate a clean, single-file Expert Advisor (.mq4 for MT4 or .mq5 for MT5) containing your exact trade management routines.
Open MetaEditor (shortcut F4 in MetaTrader), paste the generated code, and compile (shortcut F7). Review diagnostics to confirm zero errors and zero warnings.
Attach the compiled trade manager to a demo chart or test execution mechanics in the MetaTrader Strategy Tester to verify lot calculation, trailing stops, and scale-outs.
Attach the EA to your trading chart with AutoTrading enabled. Optionally deploy on a low-latency VPS to maintain continuous trade management around the clock.
Pineify AI Coding Agents
Build single-file, editable MQL4 and MQL5 trade manager EAs tailored to your exact risk rules. No proprietary binary locks, no external DLLs, and no monthly licensing fees.
Why Traders Choose Native MQL Code Generation
Generate and revise editable MQL5 Expert Advisors, indicators, and trade scripts.
Create single-file MT4 Expert Advisors and indicators from plain English prompts.
Learn how to open, write, compile, and debug MQL4 and MQL5 code in MetaEditor.
Explore automated strategy creation and trade execution workflows in MetaTrader 4.
Configure position sizing, stop loss limits, and drawdown management in MT5.
Track trade execution metrics, risk-reward performance, and psychological discipline.
This page provides technical software engineering information, not financial or investment advice. Trading foreign exchange on margin carries significant risk of loss. Always test trade management algorithms on a demo account before applying real capital.