Triangular Deviation Watcher
For any triangle of three related pairs (by default EURUSD, USDJPY, EURJPY), no-arbitrage pricing requires the third leg to equal the product (or the correct reciprocal, depending on quoting direction) of the other two. This EA recomputes that synthetic value every InpTimerIntervalSec seconds, compares it with the third leg's own live quote, and reports the gap in points and in percent - a genuinely useful diagnostic for spotting a stale or bad quote on one leg, independent of any trading intent. Deviations at or above InpDeviationLogPoints are appended to a CSV log (TriangularDeviationWatcher_Log.csv, MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)Common\), and deviations at or above InpDeviationAlertPoints print an alert to the Experts log. READ THIS BEFORE ENABLING InpAllowDemoExecution. A deviation large enough to be visible on a retail MT4 feed is very rarely a real, capturable arbitrage. Institutional latency-arbitrage desks operating in microseconds have almost always already closed a triangle deviation by the time a retail EA's tick arrives, computes the check, and could send three separate market orders - and even a perfect retail execution pays three spreads and three separate slippage draws across the three legs before the first order confirms, which alone is usually larger than the deviation being chased. This project is built to WATCH and LOG triangle consistency, not to sell a viable live strategy. Consistent with that, InpAllowDemoExecution only ever does anything on a confirmed demo account (checked via ACCOUNT_TRADE_MODE at start-up and re-checked before every probe) - on a live account the EA refuses to send a single order regardless of the input setting, and says so in the log. Even on demo, the "execution" is three tiny probe orders opened and immediately closed again, intended to measure realistic three-leg fill timing, not to accumulate profit. Notes and limitations - Not a viable live arbitrage strategy - read the honesty note above before assuming otherwise. It is a watcher and logger first. - The synthetic-value orientation logic assumes standard 6-letter FX symbol naming (a broker suffix after the 6 letters is fine, but a differently-formatted symbol name will fail the currency-matching checks and the EA will simply report "deviation unavailable"). - The demo-only guard checks ACCOUNT_TRADE_MODE at start-up and again before every probe attempt - it cannot be bypassed by input settings alone. - The CSV log is written to MQL4\Files\ (or MQL5\Files\ on the native MQL5 build)Common\, shared across the whole terminal, so multiple charts running this EA on different triangles append to the same file.
Expert advisor · MT4 · v1.0 · Free
About Triangular Deviation Watcher
Triangular Deviation Watcher is an expert advisor (trading robot) for MetaTrader 4. It works on several symbols at once. It has 13 settings, such as Leg a, Leg b and Leg c. MQL source code included.
Files in the download: TriangularDeviationWatcher.ex4, TriangularDeviationWatcher.mq4, TriangularDeviationWatcher.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Leg a | EURUSD | First leg of the triangle |
| Leg b | USDJPY | Second leg of the triangle |
| Leg c | EURJPY | Third leg - checked against LegA * LegB |
| Deviation alert points | 15.0 | Deviation (in LegC points) at/above which an alert prints |
| Deviation log points | 3.0 | Deviation at/above which a line is written to the CSV log |
| Allow demo execution | false | Only meaningful on a demo account - see the honesty note above |
| Demo probe lots | 0.01 | Lot size for the demo-only three-leg probe |
| Demo trigger points | 20.0 | Deviation required before the demo probe fires |
| Magic number | 20260905 | Magic number for demo probe orders |
| Slippage pips | 2 | Slippage tolerance requested on each probe leg |
| Max retries | 3 | Attempts per probe leg before giving up |
| Retry wait ms | 300 | Pause between attempts, milliseconds |
| Timer interval sec | 1 | How often the triangle is checked, independent of tick arrival |
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 → Experts.
- 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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Arbitrage · EURUSD · USDJPY · Multi-Currency · MT4 Expert Advisor · MQL4 Source Code