Portfolio Allocator for Expert Advisors
- Утилиты
-
Mohamed-amine Baddir
Я создаю Expert Advisors для MetaTrader 5 и тщательно тестирую их перед тем, как вы начнёте ими торговать.
Что я делаю:
- Превращаю вашу торговую стратегию, скрипт TradingView или письменные правила в чистый Expert Advisor для MT5 - Версия: 1.10
- Обновлено: 20 октября 2026
- Активации: 5
Portfolio Allocator tells you how many lots each Expert Advisor of a portfolio should trade. It reads one saved Strategy Tester report per Expert Advisor, or the history of an account that runs several of them (one strategy per magic number), and computes the allocation with eight methods: from equal risk and risk parity to hierarchical risk parity, maximum diversification, maximum Sharpe and minimum tail loss. Then it scales the whole portfolio to the drawdown you accept, and shows with a walk-forward test whether the chosen method would really have done better than the lots you tested with.
How To Use
- Save one Strategy Tester report per Expert Advisor as HTML into MQL5\Files\PortfolioAllocator (File > Open Data Folder): right click on the Backtest tab > Report > HTML. Test them over the same period.
- Attach Portfolio Allocator to any chart and set the capital of the portfolio. For a live account, choose the history of the account instead: each magic number becomes one strategy.
- Open MQL5\Files\PortfolioAllocator\PortfolioAllocator.html in any browser. Everything is computed in the page: change the method, the risk target, the capital or the strategies and it recomputes at once.
The Allocation
- For each strategy: the multiplier of its tested lots and the size to trade, its share of the risk, its contribution to the risk of the portfolio, how stable that share is (5% to 95% of the shares fitted on 100 resampled histories), and how much it adds to the Sharpe ratio of the portfolio.
- Risk target: the drawdown exceeded in 1 year out of 20 (Monte Carlo), the drawdown of the history, or the volatility per year, as a percent of the capital.
- Sizes rounded to the lot step of your broker, with the drawdown of the rounded sizes, and the peak margin the open trades would have held at once (margin per lot read from your terminal).
- Untick a strategy to leave it out. Download the allocation as CSV.
Eight Methods
- As tested: the lots of the reports, only scaled.
- Equal risk: the same volatility for each strategy.
- Risk parity: each strategy contributes the same share of the variance of the portfolio.
- Hierarchical risk parity: the risk is split down a tree of the correlations (Lopez de Prado).
- Maximum diversification: the highest ratio of the strategies' own volatility to that of the mix.
- Maximum Sharpe: the tangency mix, with the expected results shrunk towards their common mean (Bayes-Stein), because averages of past results are noisy.
- Minimum tail loss: the lowest average of the worst 5% of days (CVaR, Rockafellar-Uryasev), solved exactly.
- Maximum profit / drawdown.
- Optional limit on the share of one strategy; risk estimated from the sample, shrunk towards zero correlation (Ledoit-Wolf), or weighted to recent months.
Walk-Forward Test
- Each month (or quarter) every method is fitted on the previous 6, 12 or 24 months, or the whole past, and trades the next month with those sizes. The page joins these unseen months into one curve per method.
- For each method: result per year, Sharpe ratio, drawdown, months better than the tested lots, and the chance that its difference to the tested lots is luck (Jobson-Korkie test with Memmel's correction).
- A method that looks best on the full history often loses on unseen months. This test shows it before your money does.
Also On The Page
- All eight methods compared at the same risk: result per year, Sharpe ratio, drawdowns, worst day, diversification ratio, number of independent risk sources.
- The equity of the chosen allocation against the tested lots at the same risk.
- The Monte Carlo distribution of the drawdown over one year (blocks of days drawn together, so days on which the strategies lost together stay together).
- The correlation map of the strategies, daily and weekly, ordered by a clustering tree, and the number of strategies that really behave independently.
- The share of the variance and of the tail loss of each strategy.
Checked
- Every method was checked against independent Python libraries (SciPy, scikit-learn) on the same data: allocations, Ledoit-Wolf shrinkage, the clustering tree, the minimum tail loss against an exact linear programme, the walk-forward at every refit.
- The lots of the first screenshot were run together in one real Strategy Tester backtest of the nine example strategies: the drawdown of that backtest was 7.32% of the capital, against 7.3% shown on the page, and the net result was within 0.5% of the prediction.
Inputs
- Strategies: saved Strategy Tester reports, one per strategy, or the history of this account, one strategy per magic number
- Folder in MQL5\Files with the saved reports; or the report files
- Split each report or magic number by symbol
- Folder in the common Files folder of all terminals
- Account history: from, magic numbers, symbol
- Capital of the portfolio (0 = the balance, or the deposit of the reports)
- Page title
Good To Know
- Results are the closed trades added up by day over the period common to all the strategies; floating losses inside open trades are not modelled. The peak margin uses the margin per lot of your terminal today and counts hedged positions in full. A size below the minimal lot is marked, never rounded up.
- Expert Advisors whose lots follow the balance are detected; their results are taken as a percent of the balance, and the multiplier applies to their risk setting.
- The demo runs in the Strategy Tester: put saved reports into the common folder Files\PortfolioAllocator (File > Open Common Data Folder); the page is written when the test ends.
- The screenshots use nine textbook example strategies (moving average cross, RSI, breakout, Bollinger bands) on forex, gold, an index and bitcoin. They show the page, not results to expect.
- The utility reads files and history only. It does not trade and does not change any setting.
