Series Compression Codec
"Compression" is an easy word to attach to a file format without doing anything that actually shrinks the data. This library does the real mechanical work: a price series is first converted to an integer tick count (price divided by the instrument's point size, rounded), so consecutive values differ by small integers rather than long floating- point mantissas. Each difference is then mapped through a zig-zag transform - which sends small negative numbers to small unsigned numbers instead of a huge two's-complement bit pattern - and written as a LEB128-style variable-length integer: 1 byte for most ordinary single- step price moves, growing only as far as an individual jump actually requires. The result is that a series of small, similar-sized moves - the normal case for a real price series - collapses to mostly single-byte deltas, which is genuinely where the size reduction comes from, not from any post-hoc trick applied after the fact. The demo encodes a 100-value synthetic price series (with one deliberate large gap and one deliberate reversal, so it is not an unrealistically smooth best case) and prints the encoded size as a percentage of the naive 8-bytes-per-double size directly in the Experts log. Notes and limitations - Lossy only in the sense that a price is rounded to the nearest whole tick of the configured point size before encoding - with the correct point size for the instrument, this loses nothing a normalised price did not already discard. Set the wrong point size and prices will round to the wrong grid; always read SYMBOL_POINT from the actual instrument rather than assuming a fixed digit count. - A single delta larger than fits in a normal move (a multi-day gap after a weekend, or feeding two unrelated series back to back) still encodes correctly - it simply costs more bytes for that one value, it does not corrupt anything after it. - DecodePriceSeries()/DecodeLongSeries() return -1 for a stream that ends mid-varint (a genuinely truncated buffer). They do not detect every possible corruption - e.g. a byte flipped inside an otherwise well-formed varint decodes to a wrong-but-plausible number silently. Pair this codec with a checksum (see AppendOnlyJournal.mqh, a separate library in this catalogue) if integrity against arbitrary corruption matters, not just truncation. - This encodes OHLC/volume series data, not order or account state.
Script · MT5 · v1.0 · Free
About Series Compression Codec
Series Compression Codec is a script for MetaTrader 5. MQL source code included.
Files in the download: SeriesCompressionCodec.mq5.mqh, SeriesCompressionCodec.txt, SeriesCompressionCodecDemo.ex5, SeriesCompressionCodecDemo.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: Volume · MT5 Script · MQL5 Source Code