Discussing the article: "MQL5 Wizard Techniques you should know (Part 99): Using a KD-Tree and an Echo State Network in a Custom Money Management Class"

 

Check out the new article: MQL5 Wizard Techniques you should know (Part 99): Using a KD-Tree and an Echo State Network in a Custom Money Management Class.

This article lays out 'CMoneyKDTreeESN' custom money management class usable with the MQL5 Wizard, that combines the KD-Tree algorithm and the Echo State Network. We use the KD-Tree on log returns and ATR to give us a risk score, while the ESN tracks recent flow to give us a bounded lot size multiplier. Our class is usable in a variety of Wizard assembled Expert Advisors as shown here with the Envelopes and RSI signals, with a broad objective of modulating exposure in high-volatility and tail-risk environments.

If one were to consider a situation where a trading strategy spots an excellent long entry from standard indicator signals, usually the money management logic would determine the position size based on a fixed risk percentage of the available free margin. Nonetheless, if the broader market is rapidly getting to a "crash profile" -  signs of this can include unnatural contractions in price followed by a spike in the ATR, one can make the case that this standard lot size is no longer optimized for risk. It is effectively blind to a potential structural collapse.

Regular models usually treat all trades as a separate event. They do not properly consider the 'geography' of a given price action. If the market makes a move into a zone of high volatility, linear models usually maintain a high leverage at a time when exposure ought to be dialed down. And this could stem from these models having no "spatial memory". The inability to contextualize the current price action with similar historical patterns that led to liquidity droughts, is our core problem.

This is where the need for position sizing that is dynamic would come to the fore. We thus seek a method that acts as a circuit breaker, doing a pre-flight check on all the open signals. Since we map current market coordinates onto historical failure nodes, we can on paper force a reduction in position size prior to trades being dispatched to the broker. This should allow our strategy to survive systemic tail risk events that are always poised to drain an account's margin.

Author: Stephen Njuki