Discussing the article: "Risk Manager for Trading Robots (Part I): Risk Control Include File for Expert Advisors"

 

Check out the new article: Risk Manager for Trading Robots (Part I): Risk Control Include File for Expert Advisors.

Trading is characterized by high demands on risk management discipline. The article presents an analysis of the main reasons for traders' failures and proposes a technical solution in the form of the CEnhancedRiskManager class for the MQL5 platform. It includes practical testing on an aggressive grid EA.

Experience shows that trading accounts without a well-thought-out risk management system tend to have a short life cycle.

There are three classic psychological traps that almost every beginning trader falls into. The first is euphoria after a series of profitable trades. After a few successful market entries, you get the feeling that you have figured out the market, unlocked its secrets. Your inner voice whispers, "I am in the black, I can afford to take more risk!", and the trader increases the lot, ignores stop losses, and opens more positions simultaneously. The result is predictable: in one day the trader loses what took weeks to earn.

The second trap is hoping for a market reversal. The position goes further into loss, the red numbers on the screen become larger, but the trader continues to hold the trade. "It is about to reverse," "It is just a correction," "The market cannot fall forever" — thousands of traders repeat these mantras until a margin call puts an end to their trading careers.

The third trap is the most insidious — ignoring your own rules. A trader creates a trading system, sets clear entry and exit rules, and sets risk limits. But at some point the thought appears: "What could possibly go wrong? It is okay to break my own rules once". Stop losses are disabled, the maximum lot is exceeded, and trades are opened against the trend. This is the path to inevitable collapse, and the trader understands this perfectly well, but cannot stop.

Risk Manager for Trading Robots (Part I): Risk Control Include File for Expert Advisors


Author: Yevgeniy Koshtenko

 
Thank you for sharing your ideas and code; I’ll use them as you wish
 
Is there a version for MQL4?
 

Hello, thank you for your work!

However, I would like to see the class code corresponding to the one described in the article, for example

In the article:

enum ENUM_RISK_CALC_TYPE {
    RISK_CALC_BALANCE_ONLY,   // Calculation based on balance only
    RISK_CALC_EQUITY_ONLY,    // Calculation based on equity only
    RISK_CALC_COMBINED,       // Combined calculation
    RISK_CALC_ADAPTIVE        // Adaptive calculation
};

In the attached file:

enum ENUM_RISK_CALC_TYPE {
    RISK_CALC_BALANCE_ONLY,   // Only Balance
    RISK_CALC_EQUITY_ONLY,    // Only Equity
    RISK_CALC_BALANCE_EQUITY, // Balance/Equity (US Prop Style)
    RISK_CALC_PROP_STANDARD   // Standard Prop Company Rules
};

The ‘adaptive calculation’ mentioned in the article is not reflected in the attached class code at all.

Furthermore, there is an error in the code that prevents the expert advisor from compiling:

// Trading Object
    CTrade              m_trade;

It should be in the public section:

Please check this.

 
My compilation isn’t working either; it gets stuck on line 124: 123 // Setting the magic number for the trading object
124 g_RiskManager.m_trade.SetExpertMagicNumber(InpMagicNumber);
 
Борис Ворона #:
My compilation isn’t working either; it gets stuck on line 124: 123 // Set the magic number for the trading object
124 g_RiskManager.m_trade.SetExpertMagicNumber(InpMagicNumber);
In the EnhancedPropRiskManager.mqh class definition file, move the line "CTrade m_trade;" from the private section to the public section:
 
Thanks, it’s compiling now. But the responsive version won’t compile.
 

I applied the risk manager to my live Martingale-based expert advisor

Here are the results of the 2025 backtest without the risk manager:

And here are the results with the risk manager’s optimal settings:

As you can see, the maximum drawdown has been halved, whilst profits have quadrupled.