Automated risk management EA with interactive graphical panel. Applies SL/TP, Break Even, Trailing Stop, and lot size calculation by risk percentage — for any instrument, any broker.
📋 Overview
AutoRiskManage is an Expert Advisor that acts as a risk management layer on top of any manually opened position. It does not generate trading signals — instead it protects and manages positions that are already open, applying the rules you configure through its graphical panel.
SL / TP Assignment
Automatically assigns Stop Loss and Take Profit to any new position that is opened without them.
Break Even
Moves the SL to breakeven (+ protection points) when the position reaches a configurable profit distance.
Trailing Stop
Follows the price dynamically, keeping the SL at a fixed distance once a profit threshold is reached.
Risk-Based Lot Calc
Calculates the exact lot size to risk a given % of the account balance, based on the SL distance and instrument tick value.
Graphical Panel
All parameters are editable directly on the chart — no need to reload the EA to change values.
Persistent Settings
Parameters survive timeframe changes, chart reloads, and MT4/MT5 restarts via GlobalVariables.
ℹ The EA only manages positions with Magic Number = 0 (manual trades). Positions opened by other EAs are automatically ignored.
⚙ Installation
MetaTrader 5
- Copy AutoRiskManage_v2.mq5 to MQL5/Experts/
- Open MetaEditor → compile the file (F7)
- In MT5, drag the EA from the Navigator onto any chart
- Set initial parameters in the Inputs tab → click OK
- Ensure AutoTrading is enabled in the toolbar
MetaTrader 4
- Copy AutoRiskManage_v2.mq4 to MQL4/Experts/
- Open MetaEditor → compile the file (F7)
- In MT4, drag the EA from the Navigator onto any chart
- Set initial parameters → click OK
- Ensure AutoTrading and Allow live trading are enabled
✓ The EA automatically detects the symbol from the chart it is attached to — no need to configure the symbol manually.
⚠ To use BUY / SELL buttons on a live account, the broker must allow automated trading through EAs. Always test on a demo account first.
⚡ Input Parameters
These are the initial values set when attaching the EA. After the first load, all parameters can be changed from the panel without reloading.
General
| Parameter | Default | Description |
| InpMagicNumber | 1 | Magic number used as a filter. The EA only manages positions with Magic Number = 0 (manual trades). This value identifies the EA's own orders (BUY/SELL from panel). |
| InpPrintLog | false | Enables verbose logging to the MT4/MT5 Journal. Useful for debugging. Keep disabled in production to avoid noise. |
SL / TP
| Parameter | Default | Description |
| InpLotSize | 1.0 | Fixed lot size used when Risk% = 0. Ignored when Risk% > 0. |
| InpRiskPct | 0 | Percentage of account balance to risk per trade. Set to 0 to use fixed lot size instead. Example: 1.0 = risk 1% of balance. |
| InpSLPoints | 50 | Stop Loss distance in real trader points. Enter intuitive values: 50 = 50 DAX points, 50 = 50 pips on Forex. The EA normalizes automatically per instrument. |
| InpTPPoints | 30 | Take Profit distance in real trader points. Same normalization as SL. |
Break Even
| Parameter | Default | Description |
| InpUseBreakEven | true | Enables the Break Even feature. |
| InpBEPoints | 30 | Price distance in points that must be reached to trigger Break Even. Measured from entry price. |
| InpBEPlusPoints | 5 | Points of protection added above (BUY) or below (SELL) the entry price when moving to breakeven. Ensures a small guaranteed profit. |
Trailing Stop
| Parameter | Default | Description |
| InpUseTrailing | true | Enables the Trailing Stop feature. |
| InpTSStartPoints | 20 | Minimum profit distance (in points) required to activate the trailing stop. |
| InpTSStepPoints | 10 | Distance (in points) the trailing SL maintains from the current price. |
Panel
| Parameter | Default | Description |
| InpPanelX | 10 | Horizontal position of the panel in pixels from the left edge of the chart. |
| InpPanelY | 30 | Vertical position of the panel in pixels from the top edge of the chart. |
💰 Risk-Based Lot Calculation
When Risk% > 0, the EA calculates the exact lot size to risk a fixed percentage of the account balance on each trade, using the broker's tick value for the instrument.
The result is normalized to the broker's minimum lot step and clamped between the minimum and maximum allowed lot size.
Example
GER40.cash (DAX) — 1% risk
| Account Balance | $10,000 |
| Risk % | 1.0% |
| Risk Money | $100 |
| SL Points | 50 pts |
| SL Price Distance | 50 × 1.0 = 50.0 |
| Tick Value (1 lot) | ~$10.00 |
| SL Ticks | 50 / 0.01 = 5000 |
| Lot Size | $100 / (5000 × $10) = 0.20 |
✓ After clicking Calculate Lot by Risk%, the button shows the calculated lot and the dollar amount at risk (e.g. Lot: 0.20 ($100.00)) for a few seconds before resetting.
📊 Instrument Compatibility
The EA uses GetPipSize() to normalize point values automatically. You always enter intuitive real-price points regardless of broker or instrument. The function detects the instrument type by its decimal digits:
| Digits | Instrument type | Examples | 1 pt = | "50 pts" in price |
| 5 | Forex (standard) | EURUSD, GBPUSD | 0.00010 | 0.00500 |
| 3 | Forex JPY | USDJPY, EURJPY | 0.010 | 0.500 |
| 4 | Forex (legacy 4-digit) | Some brokers | 0.0001 | 0.0050 |
| 2 | Indices & Metals | DAX, Gold, SP500 | 1.00 | 50.00 |
| 1 | Some indices | NAS100 (some brokers) | 1.0 | 50.0 |
| 0 | Crypto / integers | BTCUSD | 1 | 50 |
ℹ The panel shows "1 pt = X.XX | digits: N" after clicking Apply — use this to confirm the EA has detected your instrument correctly.
AutoRiskManage v2.3 · Copyright 2025–2026 Time Space Technology · MetaTrader 4 & 5