Reference Data Registry
Reading digits, point size, contract size, tick value and lot limits straight from MarketInfo() on every use is correct but repetitive, and gives no clean place to hang a local adjustment when one is genuinely needed - a synthetic instrument the broker reports oddly, a deliberately different display precision, a workaround for a specific broker quirk. This header is a small reference-data cache for exactly that combination: EnsureLoaded(symbol) fetches the seven core fields from MarketInfo() once per symbol and keeps them, and a completely separate override table lets a caller force one specific field to a chosen value per symbol. The two tables are kept genuinely separate on purpose. GetContractSize() and the other GetXxx() accessors always check the override table first and fall back to the cached broker value only if nothing is overridden - the broker-reported base value itself is never touched by SetOverride(), so ClearOverride() reliably reverts to exactly what MarketInfo() actually reported, not to some earlier overwritten copy of it. This also means an override can be pre-staged for a symbol before EnsureLoaded() has ever been called on it. Contract size, tick value and the other numeric fields are always read live from MarketInfo() (never hardcoded) precisely because gold, indices and JPY crosses all report genuinely different values here - hardcoding any of them for "the" instrument is a broker-reality trap this header exists to avoid, not to reproduce. Notes and limitations - Only the seven fields listed above are tracked. Anything else MarketInfo() can report (spread, swap rates, trading session times, etc.) is out of scope for this header - it is a small, fixed reference-data set, not a general MarketInfo() wrapper. - Overrides are stored as strings and parsed back with StrToDouble() at read time, so GetDigits() truncates a fractional override value via the normal double-to-int cast rather than rejecting it outright - pass a clean integer string for RDR_FIELD_DIGITS. - EnsureLoaded()/GetXxx() lookups are linear scans over the cached symbol list and the override list. Fine for the handful to a few dozen symbols one EA or indicator realistically tracks; not intended as a whole-Market-Watch reference table for hundreds of symbols. - Nothing here is persisted to disk - both tables are pure in-memory and empty again on every restart. A caller wanting overrides to survive a restart must save/restore SetOverride() calls itself (e.g. from an input string or a file), this header only manages the in-session table. - Not thread-safe - one CReferenceDataRegistry instance is meant to be owned by one EA/indicator instance, not shared across chart windows.
Script · MT5 · v1.0 · Free
About Reference Data Registry
Reference Data Registry is a script for MetaTrader 5. MQL source code included.
Files in the download: ReferenceDataRegistry.mq5.mqh, ReferenceDataRegistry.txt, ReferenceDataRegistryDemo.ex5, ReferenceDataRegistryDemo.mq5.
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