Currency Conversion For Profit
MQL4 has no built-in cross-rate function and no direct way to ask "what currency is this symbol's profit booked in". A profit figure in EUR has to be converted to the account currency by hand, and the pair needed to do that is not guaranteed to exist in Market Watch at all - many brokers do not quote AUDCHF directly, for instance, even though both AUDUSD and USDCHF exist. This header tries three routes in order. First, the direct symbol (ccyFrom+ccyTo). Second, its inverse (ccyTo+ccyFrom), inverting the rate. Third, a one-hop triangulation through each of USD, EUR and GBP in turn - the three currencies most likely to have a quoted pair against any given currency. If none of those routes exist on the broker's symbol list, the function returns false rather than a plausible-looking number. That distinction matters: a caller that cannot value a position must know it cannot value the position, not silently treat a failed lookup as "worth zero" or "unchanged". CcSymbolExists calls SymbolSelect(symbol, true) before checking the quote, because a symbol the broker offers but the terminal has not subscribed to reads back a Bid of 0 - identical to a symbol that does not exist at all. Without that call, a legitimate route can be missed simply because nothing had put the pair in Market Watch yet. Base and quote currency are decoded from the symbol name by taking the first and second groups of three characters, which is the standard ISO convention almost every forex broker follows for an undecorated symbol name. A broker that adds a prefix or suffix (EURUSD.m, #EURUSD) needs that trimmed before calling CcBaseCurrency / CcQuoteCurrency - this header does not guess at broker-specific decoration. Notes and limitations - Uses Bid only, not a Bid/Ask midpoint or a spread-aware rate. Fine for reporting and risk sizing; not precise enough for anything that needs the exact executable rate. - Triangulation is exactly one hop. Two currencies that share no direct, inverse, or single-bridge route (rare, but possible on a broker with a narrow symbol list) will fail to convert even though a longer chain might exist. - Currency decoding assumes an undecorated 6-letter symbol name. Strip any broker prefix or suffix before passing a symbol to CcBaseCurrency or CcQuoteCurrency, or pass ISO currency codes directly to CcConvert instead. - No caching. Each call re-checks SymbolSelect and re-reads MarketInfo; for a hot loop converting the same pair repeatedly, cache the rate locally or use alongside a caching header such as SymbolCache.
Script · MT5 · v1.0 · Free
About Currency Conversion For Profit
Currency Conversion For Profit is a script for MetaTrader 5. It has 1 setting, such as Sample profit. MQL source code included.
Files in the download: CurrencyConvert.mq5.mqh, CurrencyConvert.txt, CurrencyConvertDemo.ex5, CurrencyConvertDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Sample profit | 137.50 | Sample profit figure for the worked example |
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: MT5 Script · MQL5 Source Code