This one is for the “purists”
The way how the code example provided with metatrader 5 calculates ATR (Average True Range) is, for the sake of speed of execution, using the approximation of what should be a simple moving average (SMA) of TR (True Range). While it produces results very, very similar to simple moving averages, it is still not it. This version is doing that (calculating without an approximation) and it is doing it without slowing down either – the speed of execution will be the same for any period calculated. And it does not require any additional buffer allocation