Loading…

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 · MT5 · v1.0 · Free

About Triangular Deviation Watcher

Triangular Deviation Watcher is an expert advisor (trading robot) for MetaTrader 5. 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.ex5, TriangularDeviationWatcher.mq5, TriangularDeviationWatcher.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Leg aEURUSDFirst leg of the triangle
Leg bUSDJPYSecond leg of the triangle
Leg cEURJPYThird leg - checked against LegA * LegB
Deviation alert points15.0Deviation (in LegC points) at/above which an alert prints
Deviation log points3.0Deviation at/above which a line is written to the CSV log
Allow demo executionfalseOnly meaningful on a demo account - see the honesty note above
Demo probe lots0.01Lot size for the demo-only three-leg probe
Demo trigger points20.0Deviation required before the demo probe fires
Magic number20260905Magic number for demo probe positions
Slippage pips2Slippage tolerance requested on each probe leg
Max retries3Attempts per probe leg before giving up
Retry wait ms300Pause between attempts, milliseconds
Timer interval sec1How often the triangle is checked, independent of tick arrival

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 → Experts.
  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 expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Arbitrage · EURUSD · USDJPY · Multi-Currency · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria