# Risk Calculator Trade Panel for MT5

> On-chart BUY, SELL and CLOSE ALL panel that works out the lot from your risk % and stop in points and sets an R-multiple target.

## At a glance

- What it is: A free Expert Advisor for MetaTrader 5, written in MQL5.
- What it does: On-chart BUY, SELL and CLOSE ALL panel that works out the lot from your risk % and stop in points and sets an R-multiple target.
- Shared by: Alex
- Licence: MIT
- Version: 1.0 (1 Dec 2026)
- Settings: 12 inputs
- Lab check: Compiled with MetaEditor build 6333 for MT5 on 1 Dec 2026: 0 errors, 0 warnings.
- Price: Free to download
- Page: https://hub.fxnook.com/risk-calculator-trade-panel-for-mt5
- Download (compiled): https://hub.fxnook.com/download/90c86611-8b33-46e7-9198-d92a731911cc/compiled
- Download (source): https://hub.fxnook.com/download/90c86611-8b33-46e7-9198-d92a731911cc/source

## About

A small trading panel that does the position-size maths for you. Type your risk in percent of balance and your stop in points, then press BUY or SELL: the panel works out the lot size, places a market order with that stop loss and a take profit at the R multiple you chose. A CLOSE ALL button closes the chosen positions on the symbol.

## How it works

**Lot size.**
- Risk money = balance x risk % / 100.
- Loss per lot = stop points x point / tick size x tick value.
- Lot = risk money / loss per lot, rounded down to the lot step and capped at the maximum lot.
- If even the minimum lot would risk more than you set, the panel refuses the order and shows what the minimum lot would risk. It never rounds up.

**Order.** Before sending it checks that algo trading is allowed, the spread is not above `Max spread`, the stop is at least the broker stop level plus the spread, and there is enough free margin. Then it sends a market order with:
- stop = entry -/+ stop points,
- target = entry +/- stop points x R (no target when R is 0).
On MT4 a requote is retried up to 3 times. The result or the reason for a refusal shows on the panel's status line and in the Experts log.

**Panel.** Built from chart objects (buttons, edit fields and labels) with the prefix `FXNRTP_`. The lot preview, money at risk and spread refresh every second. Typed values are checked when you leave a field; a wrong value is replaced by the last good one. Removing the EA removes the panel.

**CLOSE ALL** closes positions on the chart's symbol that match `Positions that CLOSE ALL closes` (the panel's magic number by default), after a yes/no question if confirmation is on. It does not delete pending orders.

## Inputs

| Input | Default | What it does |
|---|---|---|
| Magic number | 730001 | Magic number given to the panel's orders |
| Starting risk % | 1.0 | Risk shown in the panel when it starts |
| Highest risk % | 5.0 | The panel refuses higher values |
| Starting stop | 300 | Stop loss in points shown when it starts |
| Starting target R | 2.0 | Target as a multiple of the stop (0 = none) |
| Slippage | 10 | Maximum slippage in points |
| Max spread | 50 | Refuse orders above this spread in points (0 = off) |
| Order comment | FXN panel | Comment on each order |
| Positions that CLOSE ALL closes | Panel's magic | All on this symbol, the panel's magic, or manual trades |
| Ask before CLOSE ALL | true | Shows a yes/no question first |
| Panel X / Y | 12 / 30 | Position from the top-left corner in pixels |

## How to use it

1. Copy `FXN_RiskTradePanel.mq4` to `MQL4/Experts` (MT4) or `FXN_RiskTradePanel.mq5` to `MQL5/Experts` (MT5). In the terminal use **File > Open Data Folder** to find these folders.
2. Restart the terminal or right-click **Expert Advisors > Refresh** in the Navigator.
3. Drag it onto a chart of the symbol you trade, set the inputs and allow algo trading (AutoTrading button on MT4, Algo Trading on MT5).
4. Start with 0.5-1% risk and a stop that fits the chart, for example 300 points on a 5-digit pair. Check the lot preview before every click.

## Good to know

- The lot uses balance, not equity, and the broker's tick value. On some CFDs and crypto symbols tick value is approximate; compare the preview with a demo trade first.
- On MT5 netting accounts an order is added to the one position on the symbol, and the new stop and target replace the position's.
- It is a manual tool: buttons cannot be clicked in the Strategy Tester.
- One order per click; no automatic entries.

Trading carries risk. Test on a demo account first; past results do not predict future results.

## Settings (inputs)

| Input | Type | Default | Note |
|---|---|---|---|
| InpMagic | long | 730001 | Magic number for orders placed by the panel |
| InpRiskPercent | double | 1.0 | Starting risk per trade in % of balance |
| InpMaxRisk | double | 5.0 | Highest risk % the panel accepts |
| InpStopPoints | int | 300 | Starting stop loss distance in points |
| InpRMultiple | double | 2.0 | Starting target in R (2 = twice the stop; 0 = no target) |
| InpSlippage | int | 10 | Maximum slippage in points |
| InpMaxSpread | int | 50 | Refuse orders when the spread is above this many points (0 = off) |
| InpComment | string | FXN panel | Order comment |
| InpCloseScope | ENUM_FXN_SCOPE | SCOPE_MAGIC | Positions that CLOSE ALL closes (this symbol) |
| InpConfirmClose | bool | true | Ask for confirmation before CLOSE ALL |
| InpX | int | 12 | Distance from the left edge in pixels |
| InpY | int | 30 | Distance from the top edge in pixels |

Tags: trade panel, lot size calculator, risk calculator, position size, one click trading, risk management

Shared code is the author's work, not financial advice. Test on a demo account first.
