Synthetic Cross Rate Builder
Most brokers quote the majors and a handful of crosses, not every pair a strategy might want to analyse or hedge. If two quoted legs share a currency, the missing cross is recoverable by combining them - EURGBP from EURUSD and GBPUSD is the textbook example - but two parts of that are easy to get quietly wrong. The first is the operation. Whether the legs should be multiplied or divided depends on WHERE the shared currency sits in each pair, not just that it is shared - EUR/USD times GBP/USD gives EUR/GBP inverted, not EUR/GBP itself. This header reads each symbol's first six characters as two 3-letter ISO currency codes and works the correct relationship out from the four possible shared-currency shapes, rather than assuming one. The second, more commonly missed trap is bid/ask combination. Multiplying the two bids and the two asks together is correct for the multiply case - lowest times lowest, highest times highest, so the combined spread only widens. But for the divide case, dividing bid by bid and ask by ask produces a synthetic spread that is NARROWER than reality, a price nobody could actually deal at. The correct combination divides by the opposing side - bidA/askB for the synthetic bid, askA/bidB for the synthetic ask - which this header does by default, not as an option. A historical series builder is included alongside the live quote function, walking both legs' close prices bar-for-bar to produce a synthetic close series for backtesting or charting a symbol the broker has never quoted at all. It leans on CopyRates/MqlRates, which have the identical signature and struct layout on both platforms, so that half of the header needed no behavioural change to port. Notes and limitations - Currency codes are read from the first six characters of the symbol name. Brokers that PREFIX the pair instead of suffixing it (rare, but it exists) will not decompose correctly - check DecomposeCurrencyPair's output before relying on it for an unfamiliar broker. True on both platforms. - BuildSyntheticSeries assumes both legs share the same broker and timeframe and lines their bars up by trimming to the shorter history and reading from the same end - it does not match by timestamp. If the two legs keep different trading hours, align them with a series aligner first and feed it matched closes instead. - GetSyntheticQuote returns false when either leg's live quote is unavailable (the platform's quote read returns 0), which happens for a symbol not currently subscribed in Market Watch. - The synthetic spread is a lower bound on real trading cost, not an exact one - it does not include the slippage or commission either leg would actually incur when traded. - No thread or state concerns: every function is pure, reading only current broker data. Identical on both platforms.
Script · MT5 · v1.0 · Free
About Synthetic Cross Rate Builder
Synthetic Cross Rate Builder is a script for MetaTrader 5. It has 2 settings, such as Leg b and Bars. MQL source code included.
Files in the download: SyntheticCrossRate.mq5.mqh, SyntheticCrossRate.txt, SyntheticCrossRateDemo.ex5, SyntheticCrossRateDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Leg b | Second leg symbol, blank = auto-search Market Watch | |
| Bars | 15 | Bars for the historical synthetic series table |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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 · EURUSD · GBPUSD · MT5 Script · MQL5 Source Code