Loading…

Duration And Size Humaniser

A raw seconds or byte count is exactly correct and completely unreadable at a glance - nobody scans a panel and instantly parses "273125" as three days, four hours and twelve minutes, or "2516582" as two and a half megabytes. This header does the two conversions a trading tool needs constantly: a duration into either a compact unit-dropping string ("3d 4h", skipping any leading unit that is zero) or a fixed-width clock string ("3:04:12:05"), and a byte count into the binary 1024-based KB/MB/GB/TB ladder that matches what Windows Explorer itself shows for a file size, rather than the 1000-based SI convention some tools use, so a reported figure agrees with what the trader sees when they open the Files folder themselves. DshFormatDuration takes a maxUnits cap so a status panel can show only the two largest non-zero units ("3d 4h") instead of the full four-unit breakdown when space is tight. Negative durations (an overdue countdown, a stale-by value) are handled with a leading minus sign rather than wrapping into nonsense. Notes and limitations DshFormatDuration and DshFormatDurationClock both take whole seconds - there is no sub-second precision, since none of this header's intended uses (elapsed time, countdowns, file age) need it. The byte formatter stops at TB and does not attempt PB/EB - no realistic MQL4 file or buffer size in this catalogue's use cases approaches that range. DshFormatBytes rounds sub-KB values to a whole number of bytes with no decimals, matching Explorer's own display convention for small files, and formatting is StringLen/character based only, no locale- specific thousands separators or translated unit labels are produced.

Script · MT4 · v1.0 · Free

About Duration And Size Humaniser

Duration And Size Humaniser is a script for MetaTrader 4. It has 2 settings, such as Sample seconds and Sample bytes. MQL source code included.

Files in the download: DurationSizeHumaniser.mqh, DurationSizeHumaniser.txt, DurationSizeHumaniserDemo.mq4.

Settings

SettingDefaultWhat it does
Sample seconds273125extra duration (seconds) to format
Sample bytes2516582extra size (bytes) to format

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria