Logic behind HalfTrend Indicator

 
I am trying to understand the logic behind the half-trend indicator so I can port it to python. But since I don't know much about MQL4 , it's a bit difficult to understand how this indicator works. Can somebody explain it to me please ? Thanks
Dateien:
Grund der Beschwerde: