This Letter presents a search for heavy charged long-lived particles produced in proton–proton collisions at s=13TeV at the LHC using a data sample corresponding to an integrated luminosity of 36.1fb−1 collected by the ATLAS experiment in 2015 and 2016. These particles are expected to travel with a velocity significantly below the speed of light, and therefore have a specific ionisation higher than any high-momentum Standard Model particle of unit charge. The pixel subsystem of the ATLAS detector is used in this search to measure the ionisation energy loss of all reconstructed charged particles which traverse the pixel detector. Results are interpreted assuming the pair production of R-hadrons as composite colourless states of a long-lived gluino and Standard Model partons. No significant deviation from Standard Model background expectations is observed, and lifetime-dependent upper limits on R-hadron production cross-sections and gluino masses are set, assuming the gluino always decays to two quarks and a 100 GeV stable neutralino. R-hadrons with lifetimes above 1.0 ns are excluded at the 95% confidence level, with lower limits on the gluino mass ranging between 1290 GeV and 2060 GeV. In the case of stable R-hadrons, the lower limit on the gluino mass at the 95% confidence level is 1890 GeV.