Skip to content

Multi-Currency Correlation Analysis for “AXIS Neural” and “LINK Neural EA” EAs for MT5

    The development of trading systems such as AXIS Neural EA and LINK Neural EA for MetaTrader 5 often raises questions about the correlation between currency pairs, especially when several of them are linked to the United States Dollar (USD).

    In order to determine to what extent such correlation might affect overall risk, we created an MQL5 script that analyzes numerous symbols, measures their correlations, and selects the combination (or subset) that minimizes the average internal correlation.

    This article describes in detail how that script works, as well as an illustrative example (using a short period), which does not necessarily correspond to the training interval used in AXIS Neural and LINK Neural EAs, but that helps to understand the methodology.

    In doing so, we aim to demonstrate the robustness and diversification we seek to achieve by including multiple currency pairs.

    1. Background and Justification

    Many users or traders perceive a possible “excessive dependence” when pairs such as EURUSD, GBPUSD, USDCAD, USDCHF, etc. are included. As the USD varies globally, it is believed that all of them could move in the same direction, thereby triggering a drawdown risk.

    Our objective was to analyze this with real data and, if necessary, implement measures of decorrelation in the currency portfolio. During the research phase for the AXIS Neural and LINK EAs, this script emerged as a support tool to help make decisions and design the basket of symbols. Since these are multi-currency EAs, statistical correlation became one of the key factors in preventing excessive risks.

    2. Detailed Functionality of the Script

    The script is written in MQL5 (MetaQuotes Language 5), the native language of MetaTrader 5. Below, the main phases of its execution are described:

    2.1. Data Reading and Preparation

    1) List of symbols: A set of currency pairs (in our example, 17 pairs) to be analyzed is defined. These include crosses involving USD, EUR, GBP, AUD, NZD, CAD, CHF, among others.

    2) Configuration of bars and history: It is specified how many candles (for example, 200) will be copied for a given timeframe (H1, H4, D1, etc.). For this purpose, the script uses the MQL5 function CopyRates to obtain the price history of each symbol.

    3) Storage in arrays: The closing price data is stored in global arrays structured so that each symbol has its own vector of closing prices. This allows for direct comparisons later.

    2.2. Construction of the Correlation Matrix

    Once the closing prices for all symbols have been collected, the script builds an N×N matrix, where N is the number of symbols analyzed. Each entry (i, j) in this matrix stores the Pearson correlation between symbol i and symbol j.

    The Pearson correlation is calculated using the formula:

    rho = [ Σ(x[i]*y[i]) – (Σx[i]*Σy[i] / n) ] / √((Σx[i]^2 – (Σx[i])^2 / n) * (Σy[i]^2 – (Σy[i])^2 / n))

    In this formula, x[i] and y[i] represent the closing prices of the two symbols, and n is the number of sampled data points (candles). A correlation close to +1 indicates highly synchronized movements; near -1, inverse movements; and around 0, independent behavior.

    2.3. Generation of Combinations (Subsets)

    The core of the script lies in its ability to search for which set of K symbols (for example, K=8) exhibits the lowest internal correlation. To achieve this, a recursive algorithm is applied that:

    1. Generates all possible combinations of the N symbols taken K at a time. In our example, for 17 symbols, 24,310 combinations are generated.
    2. For each combination, extracts from the correlation matrix all the correlations corresponding to the pairs within that subset (in total, binomial(K, 2) relationships) and calculates the average of their absolute values.
    3. Records the combination that obtains the lowest average correlation.

    This backtracking approach ensures that the global interdependence of the set of symbols is evaluated, rather than just individual pairwise relationships.

    2.4. Calculation of the Score and Final Result

    Finally, the “score” of each subset is the average of the absolute correlations of its pairs. A lower score indicates that, on average, the symbols in the subset move less synchronously, which translates into greater decorrelation. The script displays the optimal combination along with the obtained score in the MetaTrader 5 “Experts” window.

    3. Example Results

    As a demonstrative example of the process, a set of 17 symbols was analyzed over 200 candles in H1 (~8 days of data). From this, 24,310 combinations of 8 symbols were generated, and the combination with an average correlation of 0.3610 was identified.

    The resulting subset (for illustrative purposes only) was:

    • AUDNZD
    • AUDUSD
    • EURNZD
    • EURUSD
    • GBPUSD
    • GBPNZD
    • USDCAD
    • EURGBP

    (Average correlation: 0.3610)

    Although at first glance it may seem surprising that EURUSD, GBPUSD and EURGBP appear together, the script is based on the global minimization of the correlation within the entire set. In other words, while some pairs might appear highly correlated, the inclusion of other symbols (for example, those involving AUD or NZD) compensates, resulting in a lower overall average.

    Important: This example is provided solely to illustrate the methodology of the script over a short period (200 candles in H1). It does not correspond to the period used during the training of the neural networks for AXIS Neural EA or LINK Neural EA, where more extensive historical data and additional validations were employed.

    4. Applications in AXIS Neural EA and LINK Neural EA

    Thanks to this correlation analysis:

    • We validated the selection of currency pairs for each EA by empirically verifying that the overall correlation remains moderate under various market conditions.
    • We reduced the risk of simultaneous drawdowns across all pairs, as the exposure is diversified through the inclusion of less correlated crosses.
    • We incorporated “unconventional” crosses (for example, EURAUD or GBPNZD) to counterbalance the predominant exposure to USD or EUR.

    5. Final Recommendations and Clarifications

    If a developer or trader wishes to customize the basket of symbols for their own EAs or conduct similar correlation studies, it is recommended to:

    1. Use extensive data periods: for example, 1000 or 2000 candles across multiple timeframes to capture variations in correlations over time.
    2. Include “walk-forward” validations: compare results over different market phases (bullish, bearish, sideways) to ensure consistency of the selected subset.
    3. Add filters or thresholds: for instance, exclude combinations in which any pair’s correlation exceeds a specific threshold, which can enhance system robustness.

    These measures help achieve greater robustness and diversification, minimizing the impact of global movements that affect all pairs simultaneously.

    In summary, this multi-currency correlation analysis serves as a scientific and statistical foundation for constructing trading systems such as AXIS Neural EA and LINK Neural EA, reinforcing the idea that not all USD-denominated pairs move in unison. The explained methodology enables the selection of more balanced and resilient baskets of symbols in the face of abrupt market changes.

    www.mql5.com (Article Sourced Website)

    #MultiCurrency #Correlation #Analysis #AXIS #Neural #LINK #Neural #EAs #MT5