A MetaTrader 5 Expert Advisor that shows a chart panel to plan entries, stop loss, and take profit with position sizing, then confirm to send the order. It does not manage open trades; it is only for pre-trade planning and one-shot execution.
Version: 2.01 (see #property in the source file)
- MetaTrader 5
- Algo Trading enabled in the terminal toolbar
- On the EA’s Common tab: Allow Algo Trading checked
- Account must allow automated trading (not investor/read-only if your broker blocks EAs)
- Copy this folder (or place
RiskCalculator.mq5) under your terminal’s MQL5 Experts tree, for example:.../MQL5/Experts/risk_calculator/RiskCalculator.mq5
- Open
RiskCalculator.mq5in MetaEditor and compile (F7). That producesRiskCalculator.ex5next to the source (this repo’s.gitignoreexcludes*.ex5). Fix any errors if your build environment differs. - In MT5, open Navigator → Expert Advisors, drag the EA onto the chart of the symbol you want to trade.
- Adjust Inputs if needed (see below), then OK.
- Entry line — Horizontal line at the current ask when the EA starts; drag it to your desired entry.
- Optional SL / TP lines — Toggle with SL and TP on the panel. When first enabled, SL is placed about 50 pips and TP about 100 pips from entry (in the correct direction for buy/sell); you can drag them anywhere.
- Panel — Live readouts: order type, risk % or lot size, distances, risk/reward in money, R:R when both SL and TP are on, and required margin. Use ✕ to collapse the panel; click the collapsed bar to expand again.
| Input | Meaning |
|---|---|
| Magic number | Identifies orders (comment is also set to RiskCalc). |
| Default Risk % | Starting risk percent when Risk % mode is on. |
| Manual Lot Size | Starting lot size when Risk % mode is off. |
| Entry / SL / TP colors | Colors of the horizontal lines. |
| Line Width | Thicker lines are easier to grab on the chart. |
| Panel Background | Panel fill color. |
| Panel X / Y | Top-left position of the panel in pixels. |
- BUY / SELL — Sets direction. Flipping direction moves default SL/TP to the correct side of entry when those lines exist.
- RISK % ON / OFF
- ON: Lot size is calculated so that if price hits SL, loss is about Risk % of account balance. SL must be enabled and placed; turning Risk % on will turn SL on if it was off.
- OFF: You type manual lot size; the panel shows the implied risk % when SL is on.
- SL / TP — Turn each line on or off. Turning SL off while in Risk % mode switches Risk % off (risk sizing needs a stop).
- Edit Risk % or Lots in the boxes; press Enter or click outside to apply. Values are clamped to sensible ranges (e.g. risk 0.1–100%).
- Order type — If the entry line is near current ask/bid (within about 3× spread), the EA treats it as Market Buy/Sell. Otherwise it uses Buy/Sell Stop or Buy/Sell Limit depending on whether entry is above or below the market (standard pending logic).
- CONFIRM ORDER — Sends one order at the computed type, price, volume, SL, and TP. The button text turns red and explains issues (e.g. no lots, lot limits, insufficient margin).
- Toolbar: Algo Trading (green) on.
- EA: Allow Algo Trading in properties.
- Server/account: automated trading allowed (no investor-only restriction unless your broker allows EAs).
- Sufficient free margin for the shown Margin Req.
If something fails, check the Experts log and any Alert popups from the EA.
RiskCalculator.mq5— Main EA source (#property copyright/versionare set in the file; compile this in MetaEditor to build the expert).README.md— This guide.
This software is provided as-is for planning and execution assistance. Trading carries risk; past or simulated behavior does not guarantee future results. You are responsible for compliance with your broker’s rules and for testing on a demo account first.