Remote CSV Fetcher
The naive version of "read a CSV from a URL" either re-downloads it on every call - wasteful, and fragile the instant the host briefly rate-limits, is slow, or the terminal loses network for a minute - or caches it once and never checks again, silently serving data that is hours or days out of date. RcfFetch() takes an explicit maxAgeSec staleness policy: if the cache file on disk is younger than that, it is served unchanged with no network call at all. If it is older, a re-download is attempted - and if that attempt itself fails for any reason (host not whitelisted, timeout, a 4xx/5xx response), the function does not simply fail: it falls back to whatever is in the cache, however old, and sets result.servedStale = true so the caller can decide whether stale data is acceptable for its purpose rather than having that decision made for it silently. The cache file is self-describing - a single file with its own UTC fetch timestamp as the first line - so there is no separate sidecar metadata file that can fall out of sync with the data it describes. RcfParseCsv() parses the downloaded (or cached) text into rows, correctly handling double-quoted fields that themselves contain the delimiter or an escaped "" quote - the two cases a plain StringSplit(line, ",") gets wrong and that show up constantly in real-world CSV (a field like "majors, tight spread" containing a comma). Notes and limitations - WebRequest() only reaches hosts the terminal has explicitly whitelisted; a re-fetch attempt against an unwhitelisted host fails with error 4060, which RcfFetch treats the same as any other transport failure - it falls back to the stale cache if one exists. - If no cache file exists yet AND the first fetch attempt fails, RcfFetch has nothing to fall back to and reports result.ok = false - the caller must handle "no data available at all" as a real outcome, not assume RcfFetch always returns something. - RcfRow caps a row at RCF_MAX_COLUMNS (32) fields, chosen so RcfRow stays a fixed-size value type that can be assigned into an array element directly; a genuinely wider CSV silently drops columns beyond the 32nd rather than failing. - The CSV parser handles RFC 4180-style double-quoted fields and the "" escaped-quote convention; it does not attempt to handle every vendor-specific CSV dialect beyond that.
Script · MT5 · v1.0 · Free
About Remote CSV Fetcher
Remote CSV Fetcher is a script for MetaTrader 5. It is set up for gold (XAUUSD). It has 1 setting, such as Live test url. MQL source code included.
Files in the download: RemoteCsvFetcher.mq5.mqh, RemoteCsvFetcher.txt, RemoteCsvFetcherDemo.ex5, RemoteCsvFetcherDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Live test url | paste a whitelisted CSV URL to test a real download (leave blank to skip) |
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: Gold (XAUUSD) · MT5 Script · MQL5 Source Code