Forex Blog

First-hand Forex trading experience and information about foreign exchange market that will be useful to traders


Calculate Maximum Potential Loss in MetaTrader

April 24, 2015 (Last updated on May 31, 2015) by

If you ever wondered what is the total cumulative risk of your currently open orders and positions, then my latest MetaTrader tool — Risk Calculator — will help you to answer that question even if you have many orders with interwoven stop-loss and take-profit levels.

Although, I am not a proponent of the grid trading systems, they seem to be quite popular. At the same time, it is nearly impossible for a human to assess their total potential risk at a given moment when multiple pending orders are set up. This is where Risk Calculator comes handy — it analyzes every trading order, its SL and TP (or the lack of), and outputs the worst-case scenario loss that you can experience shall you leave everything as is unattended. Grid strategies is just one of the examples where Risk Calculator may prove useful. Any trader utilizing multiple orders in his or her strategy will certainly benefit from a tool like this.

The indicator is kind of unique. At least I could not find anything similar for MetaTrader. I have spent several months developing this tool (yes, I have wasted a lot of time on some dead-end solutions.) In the end I had to settle with the recursive search method of finding the maximum loss that I wanted to circumvent so badly by trying various non-traditional approaches to the problem. Then, I enhanced the basic brute-force algorithm with some smart albeit pretty obvious tricks that allow the indicator to cut execution time from several seconds to just hundreds of milliseconds on a system of 10 complex orders.

The output normally looks like this. You can click on the screenshot to see the list of orders that resulted in such risk:

Risk calculated using Risk Calculator indicator

You can download the code of the MT5 and MT4 versions or read more info about this handy calculator tool.

Some final notes on the indicator:

  • MT5 version seems to work much faster than the one for MT4. Either single position is a big deal or MT5 provides faster memory allocation functions to the MQL software.
  • Unfortunately, this Risk Calculator, though powerful, is not perfect. It is necessary for you to understand its limitations before proceeding to apply this tool on a live account.
  • There are multiple files in this indicator’s archive. It is important to preserve them all and their folder structure. Otherwise, it will not compile.

If you find any bugs in this risk analysis tool or if you have some feature suggestions, please post them using the commentary form below.

2 Responses to “Calculate Maximum Potential Loss in MetaTrader”

  1. Pelham

    Well done on a great website!

    I am very new to MT4 and came across your ‘risk calculator’ when I was searching for information to better understand how I can calculate my maximum potential loss on any given trade (depending upon my SL level). Before I use it in MT4 where I am still using a Demo account, is there anything else I should read first?


    Andriy Moraru Reply:

    Yes, it is best that you read and understand how the indicator works (especially about its limitations) on its description page:


Leave a Reply

required (will not be published)