This library implements work with the tick storage format, which has a good performance (read/write) to size ratio.
Format.
Only the following fields ofthe original MqlTickare stored:
struct MqlTick { datetime time; // Time of last price update double bid; // Current price Bid double ask; // Current Ask price double last; // Current price of the last deal (Last) ulong volume; // Volume for the current price Last long time_msc; // Time of last price update in milliseconds uint flags; // Tick Flags double volume_real; // Volume for current price Last with increased accuracy };
Examples.
You can see the library methods in MetaEditor by hotkey ALT+M. Below are some examples of their use.
Write/Read via file.
#property script_show_inputs input datetime inFrom = D'2024.12.01'; #include <fxsaber\TicksShort\TicksShort.mqh> // Short tick storage format. void OnStart() { MqlTick Ticks[]; // For source ticks. if (CopyTicksRange(_Symbol, Ticks, COPY_TICKS_ALL,(ulong)inFrom * 1000) > 0) { FileSave("Ticks.bin", Ticks); // We saved the normal ticks so we can compare file sizes. TICKS_SHORT::Save("TicksShort.bin", Ticks); // Save the ticks in a compressed format. MqlTick Ticks2[]; // For squashed ticks. TICKS_SHORT::Load("TicksShort.bin", Ticks2); // Downloaded the ticks from a compressed format. Print("Ratio = " + DoubleToString((double)FileGetInteger("Ticks.bin", FILE_SIZE) / FileGetInteger("TicksShort.bin", FILE_SIZE), 3)); Print("Correct = " + (string)TICKS_SHORT::IsEqual(Ticks, Ticks2)); // Compared. } }
The script above saves ticks to a new format file and loads them from a file.
Result.
TicksShort_SaveLoad (EURUSD,M1) Ratio = 10.000 TicksShort_SaveLoad (EURUSD,M1) Correct = true
The output to the log shows that the compression ratio is 10 times. And when uncompressed, the ticks match the original ones.
Performance.
#property script_show_inputs input datetime inFrom = D'2024.12.01'; #include <fxsaber\TicksShort\TicksShort.mqh> // Short tick storage format. // Returns the size of the array in bytes. template <typename T> ulong GetSize( const T &Array[] ) { return((ulong)sizeof(T) * ArraySize(Array)); } // Compression format performance criterion. template <typename T1, typename T2> double Criterion( const T1 &Decompression[], const T2 &Compression[], const ulong Interval ) { const double Performance = (double)ArraySize(Decompression) / Interval; return(Performance * ((double)GetSize(Decompression) / GetSize(Compression))); } void OnStart() { MqlTick Ticks[]; // For source ticks. if (CopyTicksRange(_Symbol, Ticks, COPY_TICKS_ALL,(ulong)inFrom * 1000) > 0) { TICK_SHORT Ticks2[]; // For compressed ticks. ulong Interval = GetMicrosecondCount(); TICKS_SHORT::Compress(Ticks, Ticks2); // Squeezed. Interval = GetMicrosecondCount() - Interval; const double Performance = (double)ArraySize(Ticks) / Interval; Print("Compress performance: " + DoubleToString(Performance, 1) + " Ticks (millions)/sec."); Print("Compress performance criterion: " + DoubleToString(Criterion(Ticks, Ticks2, Interval), 1)); MqlTick Ticks3[]; // For squashed ticks. ulong Interval2 = GetMicrosecondCount(); TICKS_SHORT::Decompress(Ticks2, Ticks3); // Unclenched. Interval2 = GetMicrosecondCount() - Interval2; const double Performance2 = (double)ArraySize(Ticks3) / Interval2; Print("Decompress performance: " + DoubleToString((double)ArraySize(Ticks3) / Interval2, 1) + " Ticks (millions)/sec."); Print("Decompress performance criterion: " + DoubleToString(Criterion(Ticks3, Ticks2, Interval2), 1)); Print("Correct = " + (string)TICKS_SHORT::IsEqual(Ticks, Ticks3)); // Compared. } }
This script converts a source array of ticks into a compressed array and back. The performance/efficiency data is output.
Result.
TicksShort_Performance (EURUSD,M1) Compress performance: 67.7 Ticks (millions)/sec. TicksShort_Performance (EURUSD,M1) Compress performance criterion: 677.1 TicksShort_Performance (EURUSD,M1) Decompress performance: 42.1 Ticks (millions)/sec. TicksShort_Performance (EURUSD,M1) Decompress performance criterion: 420.9 TicksShort_Performance (EURUSD,M1) Correct = true
Writes and reads are performed while preserving the original information at speeds above 40 million ticks per second.
Alternatives.
https://www.mql5.com/en/code/30791