Pluggable Quote Source Interface
MQL4 has no polymorphism and no function pointers, so there is no way to write a real abstract "quote source" base class with interchangeable implementations the way a language with virtual dispatch would. This library does the only thing MQL4 actually allows: a single QsQuoteSource struct carries a mode flag (QS_MODE_LIVE / QS_MODE_FILE / QS_MODE_SYNTHETIC) plus the fields each mode needs, and every accessor function switches on that mode internally. The interface boundary this gives a caller is real even though there is no virtual dispatch behind it - write against QsGetBar()/QsGetClose()/QsGetBarCount() exactly once, and only the single QsInit* call at setup changes depending on which mode is active. QS_MODE_LIVE reads straight from the broker feed via iTime/iOpen/iHigh/ iLow/iClose/iTickVolume - the normal case for a deployed tool. QS_MODE_FILE loads a CSV bar-history file (the common MT4 export layout: date/time, open, high, low, close, volume, oldest row first) once and serves cached data afterward, letting a tool be demonstrated or debugged against a fixed, shareable recording. QS_MODE_SYNTHETIC needs no file or feed at all: each bar's price is computed directly from its step index via a deterministic hash-based pseudo-random function plus two sine waves, so the same seed always reproduces the exact same series - useful for automated testing or a screenshot that needs to look the same on every run, without shipping a recorded data file. Shift 0 means "the newest available bar" identically across all three modes, matching MQL4's own iTime/iClose convention, so code written against one mode reads naturally against the other two as well. Notes and limitations - This is a struct-plus-mode-flag pattern, not real polymorphism - MQL4 has neither abstract classes with virtual methods nor function pointers, so QsGetBar's internal switch is the actual mechanism behind every call, not an implementation detail hidden by dispatch. Adding a fourth mode means editing this header's switch statements directly, not registering a new implementation externally. - The synthetic generator is a plausible-looking, fully reproducible wave- plus-jitter function, not a statistically calibrated price model. It makes no claim about matching real return distributions, volatility clustering, or any other statistical property of genuine price data - it exists purely to exercise chart-consuming code with deterministic, file-free input, not to backtest a strategy's real-world performance. - QS_MODE_FILE assumes the CSV is sorted oldest-first (the standard MT4 export order) and maps shift 0 to the LAST row on that assumption - a file sorted the other way will read backwards silently. - QS_MODE_FILE loads the whole file into memory on first access and caches it in the QsQuoteSource struct itself; very large history files will use memory proportional to their row count. - QsGetBarCount for QS_MODE_SYNTHETIC returns a large nominal bound (there is no real "total bars" concept for a series generated on demand) - treat it as "effectively unbounded", not a count to iterate over in full.
Script · MT5 · v1.0 · Free
About Pluggable Quote Source Interface
Pluggable Quote Source Interface is a script for MetaTrader 5. It has 1 setting, such as Bars to show. MQL source code included.
Files in the download: PluggableQuoteSource.mq5.mqh, PluggableQuoteSource.txt, PluggableQuoteSourceDemo.ex5, PluggableQuoteSourceDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Bars to show | 5 | how many recent bars each mode prints |
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