RSS Feed Parser
Reading a market-news or economic-calendar RSS feed only needs a handful of fields out of each headline - title, link, publish date - but a naive extraction with StringFind for "<title>" and "</title>" breaks the moment a real-world feed does what real feeds actually do: wrap the title in a CDATA section so an ampersand or angle bracket in the headline text does not need escaping, or use named/numeric HTML entities (", &, —) instead. Both are completely normal and both make a bare substring cut return garbled or literal-escaped text. RssParseFeed scans for the item/entry boundary tags first (<item> for RSS 2.0, <entry> for Atom, auto-detected from the document's root element), then extracts title/link/date from each block independently - one malformed item cannot corrupt the ones around it, since a failed extraction inside a block just leaves that field empty rather than throwing off the surrounding search. RssDecodeText unwraps a CDATA section if the whole field is one, and decodes the five predefined XML entities plus numeric &#NN; / &#xHH; references, so a headline like "Fed says "no rush"" comes back as the actual sentence a trader would read on-screen. Atom's link field is structurally different from RSS's - RSS puts the URL as element text (<link>https://...</link>), Atom puts it as an attribute on a self-closing tag (<link href="https://..."/>), and an Atom entry can carry several <link> tags with different rel values (self, alternate, related...). This header reads Atom links correctly - attribute, not text - and specifically prefers rel="alternate" (the one meant to be opened by a reader) when more than one is present, falling back to the first link found if none is labelled. This is deliberately NOT a general XML parser. It does not build a tree, does not resolve namespaces, and does not handle arbitrary nesting - it scans for the flat, predictable shape a headline feed always has. A document that is not recognisably RSS or Atom (no <rss> or <feed> root tag near the top) parses to zero items rather than guessing. Notes and limitations - Scope is deliberately narrow: title, link and one date field per item/entry. Other RSS/Atom fields (description, author, categories, enclosures/media) are not extracted by default - use RssExtractTag on the block yourself if you need one of them. - pubDate/updated is returned as the raw text the feed published, not parsed into a datetime - RSS's RFC-822-ish date format and Atom's ISO-8601 format both vary enough between publishers that a single parser for both was judged more likely to silently misparse an edge case than to help; convert it yourself if you need a datetime. - Not a validating parser - a malformed or truncated document (e.g. a feed cut off mid-download) simply yields fewer items than expected, with no error raised for the missing ones. - No namespace awareness. A feed using a namespaced title element (rare, but seen on some podcast feeds) will not match the plain <title> search. - WebRequest only reaches the network when the feed's domain is on the terminal's allow-list, and that list is per terminal installation - every machine this is downloaded to needs the same one-time setup.
Script · MT4 · v1.0 · Free
About RSS Feed Parser
RSS Feed Parser is a script for MetaTrader 4. It has 1 setting, such as Test feed url. MQL source code included.
Files in the download: RssFeedParser.mqh, RssFeedParser.txt, RssFeedParserDemo.mq4.
Settings
| Setting | Default | What it does |
|---|---|---|
| Test feed url | https://www.forexlive.com/feed/news | Public RSS feed to try live (needs whitelisting) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: News Trading · MT4 Script · MQL4 Source Code