Forex Risk Calculator
Risk Calculator (MetaTrader indicator) — calculates the risk in form of a potential maximum loss that can be induced by the currently open positions and the active pending orders. The results are displayed as the money and percentage risk per currency pair and as the overall total risk in the separate chart window. You can regulate the work of the Risk Calculator by turning on or off swaps, spreads, and commission calculation. You can also tune the visual display parameters. Additionally, maximum potential reward can be calculated. Moreover, you can choose to calculate risk/reward separately for open positions and for pending orders. The indicator is available for both MT4 and MT5.
Unlike the simple risk calculation procedure implemented as the module of the Position Sizer, this indicator will calculate proper risk values even in complex situations involving hedged trades, pending orders with intersecting stop-loss and take-profit levels, and even MT5's special stop-limit orders. The algorithm implements a brute force maximum potential loss search with some heuristic techniques to speed up the process. Therefore, traders will get fast calculation results on normal number of orders (up to about 20), but the execution speed will become unsatisfactory as the number of trades will increase. Nevertheless, the Risk Calculator indicator is a useful tool for assessing the exposure of the worst-case scenario when dealing with a complex portfolio of orders.
Input parameters:
Main
- CalculateSpreads (default = true) — if true, then potential loss due to spreads will become a part of the potential maximum loss.
- CalculateSwaps (default = false) — if true, then accrued swaps will become a part of the potential maximum loss.
- CommissionPerLot (default = 0) — your broker's commission per lot charged in account currency. Enter the value charged for one side of the trade, not round-turn.
- UseEquityInsteadOfBalance (default = false) — if true, then account equity is used instead of balance in calculations.
- SeparatePendingOpenCalculation (default = false) — if true, then risk and reward will be calculated separately for open trades and for pending orders.
Fonts
- cpFontColor (default = clrAzure) — font color for the currency pair names.
- mnFontColor (default = clrPaleGoldenrod) — font color for the risk in money form.
- pcFontColor (default = clrLimeGreen) — font color for the risk in percentage form.
- hdFontColor (default = clrLightBlue) — font color for headers.
- FontFace (default = "Courier") — font face of the displayed text.
- FontSize (default = 8) — font size of the displayed text.
Spacing
- scaleY (default = 15) — number of pixels per line of output.
- offsetX (default = 20) — horizontal offset for output.
- offsetY (default = 20) — vertical offset for output.
Reward
- CalculateReward (default = false) — if true, maximum potential reward will be calculated and displayed.
- ShowRiskRewardRatio (default = false) — if true, risk-to-reward ratio will be calculated and displayed. Works only if CalculateReward is set to true.
Screenshots
Example of multiple pending orders and one position (limited loss risk)
Example of unprotected buy position (nearly unlimited loss risk)
Example of unprotected sell position (unlimited loss risk)
Example of reward calculation
Example of separate calculation for positions and pending orders
Example of risk-to-reward ratio calculations
Known problems
Despite being coded and tested to work in multiple scenarios, the Forex Risk Calculator has some limitations, restrictions and a potential for errors. Here is the list of the known issues with this indicator:
- When the account currency differs from the quote currency of the pair, for which the orders are placed and the risk is calculated, the results may be inaccurate due to unpredictable fluctuations of the conversion rate. For example, if your account is in JPY and you are trading EUR/USD, then the actual risk will also depend on the future USD/JPY rate. The Risk Calculator will not attempt to predict it.
- If trader creates too many pending orders with stop-loss and take-profit levels, the indicator may become too slow in its calculation or even stop functioning at all.
- If your broker offers variable spreads, the calculations will be somewhat inaccurate as the indicator assumes constant spreads on each tick.
- The indicator does not take into account the price slippage of pending orders' execution.
- The indicator ignores the lack of margin for order execution. It means that if you set up a pending order that will require more free margin than your account can provide, the Risk Calculator will still consider the possibility of that order's execution.
- The indicator does not take into account the correlation between different currency pairs. Risk value is calculated for each trading instrument separately. For example, if you buy EUR/USD and sell GBP/USD as a hedge, the indicator will calculate the risk of each position separately.
- The indicator does not take into account the triangular arbitrage and other forms of arbitrage with several currency pairs. For example, if you go long EUR/USD, long USD/JPY and short EUR/JPY, the Risk Calculator will treat those positions as three separate trades with their own risks.
Download (ver. 1.14, 2023-08-21)
Risk Calculator is also developed via a dedicated GitHub repository. You can take part in its development by submitting your own code modifications via pull-requests and by reviewing existing suggestions, changes, fixes, and so on.
Risk Calculator for MetaTrader 4 Risk Calculator for MetaTrader 5
Discussion
Warning! If you do not know how to install this indicator, please read the MetaTrader Indicators Tutorial.
Do you have any suggestions or questions regarding this indicator? You can always discuss Risk Calculator with the other traders and MQL programmers on the indicators forums.
Changelog
1.14 — 2023-08-21
- Added an option to calculate risk-to-reward ratios.
- Changed the default color for headers for better visibility on a black background.
- Fixed a calculation error that resulted in counting spreads in risk and reward calculations for pending orders.
- Removed indicator's objects from the chart's list of objects.
1.13 — 2022-07-09
- Minor improvements of risk calculation.
1.12 — 2020-11-19
- Tick value calculation update.
1.11 — 2020-07-22
- Added option to calculate risk based on positions and based on pending orders separately.
- Minor performance improvements.
1.10 — 2020-06-24
- Further improvements for unit cost calculation in MT4.
1.09 — 2020-05-30
- Fixed a bug in MT5 version that caused incorrect pip value calculation in some cases.
1.08 — 2020-05-17
- Improved tick value calculation for risk/reward.
- Added recalculation on timer for cases when the indicator is attached to a chart without new data (a Forex pair on weekend for example) while other trading symbols are getting updated (cryptocurrency pairs for example).
1.07 — 2020-04-10
- Fixed an error in MT4 version's code that prevented indicator compilation.
1.06 — 2020-03-22
- Added optional Reward calculation.
- Fixed a major calculation bug in the MT4 version of the indicator.
1.05 — 2019-10-05
- Fixed compilation errors in MT5 Build 2170 (and newer versions).
1.04 - 2019-07-01
- Fixed a bug in MT5 version, which prevented compilation in newer MetaTrader 5 builds.
1.03 - 2017-07-22
- Added support for MetaTrader 5 Hedging mode.
- Fixed a bug with two or more positions with the same stop-loss or take-profit levels.
1.02 - 2016-11-11
- Fixed a compilation bug with pointer casting.
1.01 - 2015-05-01
- Fixed minor bugs.
1.00 - 2015-04-24
- First version of Risk Calculator indicator released.