ULP Adjust: exact tick-price restoration without NormalizeDouble()
A fast way to compress tick prices losslessly and restore them bit-for-bit:
No normalizer: decompression never calls NormalizeDouble() or a clone such as Norm() .
No extra state: no accumulator or price-cache object is kept in memory.
One mode per file: each compressed buffer uses a single price-encoding mode, either Exact division or ULP adjust. The mode is stored as one bit in the header.
The idea
A stored integer price (pips) can be turned back into a double with a single division: pips / 10^digits . For many symbols, such as USDJPY, XAUUSD and indices, that division already gives exactly the same double as the terminal's tick price.
For others, such as EURUSD and other 5-digit FX, the terminal's NormalizeDouble rounding sometimes lands one ULP (one step to the neighbouring double ) above or below the division result. The offset is never more than 1 ULP for real prices, so it fits in a 2-bit code.
Compress() decides per file:
If every price equals pips / 10^digits , it writes the file in exact-division mode, with no extra bits.
Otherwise it writes ULP-adjust mode, where each price delta carries a 2-bit code: −1, 0 or +1 ULP.
Decompress() then needs one division per price, plus one integer add in ULP mode.
Header and encoding format
//--- Price encoding (chosen per file by Compress) ---------------------// Header byte: bits 0-3 = price digits (0..8)// bit 4 = encoding mode flag//// Mode flag = 1 : Exact division// Every price in the buffer == pips / 10^digits.// Decompress(): one division per price, no extra bits.// Typical: USDJPY, XAUUSD, indices.//// Mode flag = 0 : ULP adjust// Some price != pips / 10^digits (typical: EURUSD and other 5-digit FX).// Each price delta carries a 2-bit code in its low bits:// 0 = price is one ULP below pips / 10^digits// 1 = price equals pips / 10^digits// 2 = price is one ULP above pips / 10^digits// 3 = unused (Compress() returns -1 if a price is more than 1 ULP// from pips / 10^digits: off-grid, NaN/inf, or pips >= ~1e15)// Decompress(): one division + an integer add on the bit pattern.//// Compress() tries exact division first; at the first price that fails,// it re-encodes the whole buffer in ULP-adjust mode.// Both modes restore the original MqlTick prices exactly.// Prices must be >= 0 (Compress returns -1 otherwise).//#define VLQ_HDR_DIGITS_MASK 0x0F// header bits 0-3: price digits (0..8)#define VLQ_HDR_EXACT_DIV 0x10// header bit 4: 1 = exact division, 0 = ULP adjustunion VLQ_DBITS { double d; long l; }; // view a double as its 64-bit pattern
The core function
For a non-negative double , adding 1 to its 64-bit bit pattern gives exactly the next larger double , and subtracting 1 gives the next smaller one. This holds across power-of-two boundaries too, so no floating-point arithmetic is needed to move by one ULP.
//--- x moved by (code - 1) ULPs; valid for x >= 0staticdouble UlpAdjust(constdouble x, constlong code)
{
VLQ_DBITS u;
u.d = x;
u.l += code - 1; // code 0 -> -1 ULP, 1 -> unchanged, 2 -> +1 ULPreturn u.d;
}
Price reconstruction in Decompress()
The mode is read once from the header, so each loop is free of branches that depend on the data:
if (exactDiv)
{
//--- flag = 1: every price == pips / 10^d//--- one division per price, no extra bitsfor (int i = 0; i < totalCompressedTicks; i++)
{
time += (long)ReadVLQ(buf, pos); // delta reconstruction
bid += ZigZagDecode(ReadVLQ(buf, pos));
ask += ZigZagDecode(ReadVLQ(buf, pos));
MqlTick tick = {};
tick.time_msc = time;
tick.time = (datetime)(time / 1000);
tick.bid = bid / power;
tick.ask = ask / power;
out_ticks[i] = tick;
}
}
else
{
//--- flag = 0: division + 2-bit ULP correction//--- one division + one integer add on the bit pattern per pricefor (int i = 0; i < totalCompressedTicks; i++)
{
time += (long)ReadVLQ(buf, pos);
constlong db = ZigZagDecode(ReadVLQ(buf, pos));
constlong da = ZigZagDecode(ReadVLQ(buf, pos));
constlong ub = db & 3, ua = da & 3; // 2-bit ULP codes (low bits)
bid += (db >> 2); // arithmetic shift: correct for negative deltas
ask += (da >> 2);
MqlTick tick = {};
tick.time_msc = time;
tick.time = (datetime)(time / 1000);
tick.bid = UlpAdjust(bid / power, ub);
tick.ask = UlpAdjust(ask / power, ua);
out_ticks[i] = tick;
}
}
Why it's exact
Same division on both sides. Compress() computes the 2-bit code against exactly the expression Decompress() uses ( pips / power , the same long -to- double conversion and the same divisor), so the decoder starts from the identical double .
Verified at compression time. Compress() applies UlpAdjust() itself and checks the result against the original price. Any price that can't be restored exactly (off-grid, NaN / inf , or more than 1 ULP away) makes Compress() return −1 instead of writing a wrong file.
Benchmark
Measured on the last 1M real ticks per symbol, on the same tick data in both runs.
v1.04: Norm() , a bit-exact NormalizeDouble clone, for every price.
v1.05: exact division, with ULP adjust as the fallback.
Decompression:3–9% faster on all 9 symbols (average 152.4 → 162.0 Mticks/s, +6.3%).
Exact-division symbols (USDJPY, XAUUSD, XAGUSD, XTIUSD, DE40, US500, BTCUSD) restore each price with one division.
ULP-adjust symbols (EURUSD, AUDNZD) use one division plus an integer add on the bit pattern (6.0–6.1 → 5.6 ms).
Costs:
ZIP output is 3.6–7.4% larger, on ULP-adjust symbols only. Raw size is essentially unchanged.
Compression is about 0.5–0.7 ms slower on ULP-adjust symbols, because of the per-price code check.
Correctness: every roundtrip is bit-exact.
==================================================================================================================================================================================================
SUMMARY COMPARISON MATRIX ACROSS 9 SYMBOLS (1000000 ticks each, max 63 wins) | * = best average / total
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Variant | Wins | Avg B/t | Avg ZIP | Avg Mt/s com | Avg Mt/s dec | Avg strm | Avg MB/s com | Avg MB/s dec | Avg Crit com | Avg Crit dec | Exact
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
A VLQ v1.04 | 18/63 | 3.939* | 2.216* | 146.10 | 152.41 | - | 8360 | 8721 | 2237.9 | 2335.4 | ALL OK
B Forester 4.03 [FastAccum] | 25/63 * | 4.519 | 2.285 | 200.47 | 203.87* | 500.25* | 11471 | 11665* | 2736.9* | 2802.5* | ALL OK
C TicksShort (fxsaber) | 20/63 | 6.000 | 2.445 | 254.42* | 202.23 | 270.39 | 14558* | 11572 | 2544.2 | 2022.3 | ALL OK
==================================================================================================================================================================================================
==================================================================================================================================================================================================
SUMMARY COMPARISON MATRIX ACROSS 9 SYMBOLS (1000000 ticks each, max 63 wins) | * = best average / total
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Variant | Wins | Avg B/t | Avg ZIP | Avg Mt/s com | Avg Mt/s dec | Avg strm | Avg MB/s com | Avg MB/s dec | Avg Crit com | Avg Crit dec | Exact
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
A VLQ v1.05 | 18/63 | 3.939* | 2.245* | 140.78 | 161.99 | - | 8055 | 9269 | 2158.4 | 2481.0 | ALL OK
B Forester 4.03 [FastAccum] | 26/63 * | 4.519 | 2.285 | 201.25 | 200.50 | 499.49* | 11516 | 11472 | 2749.5* | 2752.5* | ALL OK
C TicksShort (fxsaber) | 19/63 | 6.000 | 2.445 | 253.61* | 202.57* | 281.88 | 14511* | 11591* | 2536.0 | 2025.7 | ALL OK
==================================================================================================================================================================================================
Возможно разница все-таки в процессорах. У меня 12 поколение Intel. Наверно он что-то из того, что в коде NormalizePricesFastAccum умеет делать быстрее. ИИ часто упоминал (при оценке замеров разных вариантов), что целочисленные деления /1000 .. /10000 сейчас очень быстрые. Плюс конвейры, предсказатели.
Aleksey Kuznetsov # : I The AI often mentioned (when evaluating benchmarks of different options) that integer divisions /1000 .. /10000 are very fast now. Plus pipelines and predictors.
True.
On recent processors, simple integer arithmetic with no complex branches beats array / table-lookup optimizations.
Для авторизации и пользования сайтом MQL5.com необходимо разрешить использование файлов Сookie.
Пожалуйста, включите в вашем браузере данную настройку, иначе вы не сможете авторизоваться.
Вы вошли в аккаунт. Двухфакторная аутентификация отключена. Настройте её заново и отсканируйте новый QR-код или продолжите с отключённой двухфакторной аутентификацией.
Накопительная всегда быстрее (в одном случае только ~равна)
Текущая сиутация.
ИИ переделал бенчмарк в расчет рейтинга по всем инструментам в окне. Результат:
Без нормализации
TickCompressor v4.04
Кэш нормализация
Итоговый рейтинг:
Файл расчета рейтинга приложил
Итоговый рейтинг:
Наверное, так убедительнее.
Даже теоретически кеш не может уступать. Тесты (делал на золоте) это подтверждают, конечно.
ULP Adjust: exact tick-price restoration without NormalizeDouble()
A fast way to compress tick prices losslessly and restore them bit-for-bit:
The idea
A stored integer price (pips) can be turned back into a double with a single division: pips / 10^digits . For many symbols, such as USDJPY, XAUUSD and indices, that division already gives exactly the same double as the terminal's tick price.
For others, such as EURUSD and other 5-digit FX, the terminal's NormalizeDouble rounding sometimes lands one ULP (one step to the neighbouring double ) above or below the division result. The offset is never more than 1 ULP for real prices, so it fits in a 2-bit code.
Compress() decides per file:
Decompress() then needs one division per price, plus one integer add in ULP mode.
Header and encoding format
The core function
For a non-negative double , adding 1 to its 64-bit bit pattern gives exactly the next larger double , and subtracting 1 gives the next smaller one. This holds across power-of-two boundaries too, so no floating-point arithmetic is needed to move by one ULP.
Price reconstruction in Decompress()
The mode is read once from the header, so each loop is free of branches that depend on the data:
Benchmark
Measured on the last 1M real ticks per symbol, on the same tick data in both runs.
Наверное, так убедительнее.
Даже теоретически кеш не может уступать. Тесты (делал на золоте) это подтверждают, конечно.
2026.12.03 08:59:38.469 shortest pass 0:00:01.350, longest pass 0:00:01.450, average pass 0:00:01.372
NormalizePricesFastAccum
2026.12.03 09:00:14.999 shortest pass 0:00:01.079, longest pass 0:00:01.135, average pass 0:00:01.107
I The AI often mentioned (when evaluating benchmarks of different options) that integer divisions /1000 .. /10000 are very fast now. Plus pipelines and predictors.