Loading…

Basket Correlation Early Warning

Holding many symbols is not the same as being diversified. What actually matters is how correlated those symbols' MOVES have been lately - and that changes over time, often exactly when it matters most, as broad risk-on/risk-off regimes pull unrelated instruments into lockstep. A basket that was genuinely diversified last month can quietly stop being diversified this week with no change to which symbols are held. This indicator computes the Pearson correlation of simple period returns (not raw price levels, which would pick up spurious co-trending between unrelated instruments) for every pair in InpWatchlist, over a common trailing window of InpReturnWindow closed bars, and plots the AVERAGE of all those pairwise readings. A panel shows the current figure in plain text, and an optional alert fires once when the average crosses InpWarnThreshold from below - the moment a "diversified" basket starts concentrating into one effective bet. Correlation is deliberately computed on returns rather than prices: two instruments that have both simply trended upward over the window can show a high price-level correlation while their day-to-day moves are barely related, which would make the warning fire on ordinary bull markets rather than on genuine risk concentration. Notes and limitations The symbol cap (12) bounds the pair count (66 at the cap) so the per-bar cost stays predictable; a longer watchlist needs a second instance with a different subset rather than a higher cap. Any pair missing history for the full InpReturnWindow (a thin feed, a newly listed symbol) is simply excluded from that bar's average rather than blocking the whole calculation, so the reading can be built from fewer than the full pair count without warning of it beyond the Experts-log line printed at attach time. This measures historical co-movement only - a correlation reading of 0.70 describes what already happened over the window, not a forecast of what happens next.

Indicator · MT5 · v1.0 · Free

About Basket Correlation Early Warning

Basket Correlation Early Warning is an indicator for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 9 settings, such as Watchlist, Symbol suffix and Return window. MQL source code included.

Files in the download: BasketCorrelationWarning.ex5, BasketCorrelationWarning.mq5, BasketCorrelationWarning.txt.

Settings

SettingDefaultWhat it does
WatchlistEURUSD,GBPUSD,AUDUSD,NZDUSD,USDCADComma-separated symbols in the basket
Symbol suffixBroker suffix appended to every symbol, leave blank if none
Return window30Trailing closed bars the return correlation is measured over
Warn threshold0.70Alert when the average pairwise correlation reaches or exceeds this
AlertstrueAlert once per closed bar when the threshold is crossed upward
CornerCORNER_LEFT_UPPERPanel corner
X distance10Panel horizontal offset, pixels
Y distance20Panel vertical offset, pixels
Font size10Panel font size

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Alerts · MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria