Loading…

Hidden Hedge Detector

Seven different symbols can add up to almost no net exposure to anything, while the account still shows a normal-looking floating profit and loss and pays full spread, and ongoing swap, on every one of those seven tickets. It happens gradually - a position opened for one reason, another opened later for an unrelated one - and it is invisible from the terminal's own trade list, because nothing there sums exposure by currency. This script decomposes every open position into its base and quote currency legs using the broker's own declared currency metadata, then nets those legs per currency across the whole book. A currency is flagged when its net exposure is small relative to the gross exposure crossing it - two large opposing legs and a small net looks nothing like one clean directional bet, even though it can be built from ordinary-looking individual positions. For every flagged currency the script lists exactly which tickets are contributing to it, and totals the spread cost already paid to open those positions plus their running swap, counted once per position even if it touches two flagged currencies. That total is the real, current cost of carrying exposure that is - at least on that currency - cancelling itself out. Notes and limitations - Currency legs are resolved from the broker's declared symbol metadata, never by parsing the symbol name, so non-standard symbols and broker suffixes are handled correctly. A symbol with no declared currency metadata, or with base equal to quote, is reported as unclassified rather than guessed at. - Exposure is valued at the current price of each symbol, so the flagged currencies reflect the book right now, not at the time each position was opened. - Being flagged is not automatically a mistake. Some hedges are intentional - the script surfaces the fact and its cost; it does not assume the positions should be closed. - Swap shown is the amount already charged and currently accruing on the open position, read directly from the terminal, not projected forward. - Pending orders carry no exposure until filled and are not included.

Script · MT5 · v1.0 · Free

About Hidden Hedge Detector

Hidden Hedge Detector is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 2 settings, such as Min hedge ratio and Min positions. MQL source code included.

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

Settings

SettingDefaultWhat it does
Min hedge ratio0.50Flag a currency when 1 - net/gross reaches this (0.50 = half offset)
Min positions2Minimum positions touching a currency before it can be flagged

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Hedging · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria