Forex Blog

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

Archives

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.

Leave a Reply

required
required (will not be published)
optional