Position Correlation Report
Two positions on correlated symbols are not two positions - they are one position at double size, with double the drawdown when it goes wrong. This script measures that directly from price history: for every pair of symbols with an open position it computes the Pearson correlation of close-to-close log returns over an adjustable window (default 50 bars of H1), and prints the pairs strongest first. The part most correlation tools get wrong is direction. Raw correlation describes the symbols; risk lives in the positions. Long EURUSD plus short USDCHF, with a raw correlation near -0.9, looks like opposites and is in fact the same dollar bet twice - both legs profit from the same move. So next to the raw figure the report prints an ADJUSTED correlation, sign-flipped when the two positions point opposite ways. Adjusted above the threshold (default +0.70) is flagged DOUBLED BET; below -0.70 is flagged HEDGE, meaning the two positions largely cancel and are mostly paying spread. The second trap is bar alignment. Brokers skip bars differently per symbol - a thin cross misses hours a major does not - and correlating by bar index alone quietly compares Tuesday on one symbol with Wednesday on the other. This script matches the two series on identical bar open times and drops the bars only one side has, so every return pair spans the same clock interval. When a symbol simply lacks enough shared history at the chosen timeframe, the pair is reported as "n/a (bars)" with the count that was actually available. No number is ever fabricated from a short series. The script only reads. It opens nothing, closes nothing, modifies nothing. Notes and limitations - Correlation is measured over the chosen window and nothing else. Pairs that are correlated on H1 can be uncorrelated on D1 and vice versa; check the timeframe that matches your holding period. - Correlation is historical, not guaranteed. Correlated pairs decouple, usually at the worst possible moment; a HEDGE flag is a description of the last N bars, not a promise. - Position sizes are not weighed. A 0.01 lot position flags against a 5 lot position the same way; the report tells you the bets overlap, not how much money is at stake in the overlap. - The forming bar is excluded on both platforms, so the newest return ends at the last completed bar. - With many symbols the pair count grows quadratically; ten symbols is 45 rows, which is still perfectly readable. First run may pause while history downloads for symbols you never chart.
Script · MT4 · v1.0 · Free
About Position Correlation Report
Position Correlation Report is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Bars, Timeframe and Threshold. MQL source code included.
Files in the download: PositionCorrelation.ex4, PositionCorrelation.mq4, PositionCorrelation.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Bars | 50 | Correlation period, in bars |
| Timeframe | PERIOD_H1 | Timeframe of the return series |
| Threshold | 0.70 | Flag threshold for adjusted correlation |
| Save csv | false | Also write the report to a CSV file |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Hedging · Alerts · MT4 Script · MQL4 Source Code