Skip to content
FXNook HubBeta

Alex / Risk Calculator Trade Panel for MT4

MetaTrader 4Expert AdvisorMITCompiled · build 2425
AlexFirst version.build 2425v1.06 hours ago1 version
  • FXN_RiskTradePanel.mq4First version.17 KB
  • FXN_RiskTradePanel.ex4Compiled by the Lab with MetaEditor build 242538 KB
README

Overview

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.

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

InputDefaultWhat it does
Magic number730001Magic number given to the panel's orders
Starting risk %1.0Risk shown in the panel when it starts
Highest risk %5.0The panel refuses higher values
Starting stop300Stop loss in points shown when it starts
Starting target R2.0Target as a multiple of the stop (0 = none)
Slippage10Maximum slippage in points
Max spread50Refuse orders above this spread in points (0 = off)
Order commentFXN panelComment on each order
Positions that CLOSE ALL closesPanel's magicAll on this symbol, the panel's magic, or manual trades
Ask before CLOSE ALLtrueShows a yes/no question first
Panel X / Y12 / 30Position 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.

At a glance

What it is
A free Expert Advisor for MetaTrader 4, written in MQL4.
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
15 inputs
Lab check
Compiled with MetaEditor build 2425 for MT4 on 1 Dec 2026: 0 errors, 0 warnings.
Price
Free to download

Settings read from the code

InputTypeDefaultNote
InpGroup1string=== Orders ======== Orders =====
InpMagicint730001Magic number for orders placed by the panel
InpRiskPercentdouble1.0Starting risk per trade in % of balance
InpMaxRiskdouble5.0Highest risk % the panel accepts
InpStopPointsint300Starting stop loss distance in points
InpRMultipledouble2.0Starting target in R (2 = twice the stop; 0 = no target)
InpSlippageint10Maximum slippage in points
InpMaxSpreadint50Refuse orders when the spread is above this many points (0 = off)
InpCommentstringFXN panelOrder comment
InpGroup2string=== Close all ======== Close all =====
InpCloseScopeENUM_FXN_SCOPESCOPE_MAGICTrades that CLOSE ALL closes (this symbol)
InpConfirmClosebooltrueAsk for confirmation before CLOSE ALL
InpGroup3string=== Panel ======== Panel =====
InpXint12Distance from the left edge in pixels
InpYint30Distance from the top edge in pixels

How to use it

  1. Download the compiled file (or the source and compile it in MetaEditor).
  2. Put it in MetaTrader: File → Open Data Folder → MQL4 → Experts, then refresh the Navigator.
  3. Test it on a demo account before any real money.
  4. Want changes? Open a copy in your Lab and ask for them in plain words.