Probably not the most efficient code, oh well..
Let me know if it's useful :)
You can use this like any other moving average following the trend based on its color or for support and resistance.
How is this useful ?
This type of moving average is very good at following the current direction of the market, either up (yellow) or down (red), staying flat means it will follow its last known direction.
By knowing the calculation of your indicator you can often tell what it is going to do before it actually happened, so you can make a plan in advance.
By looking at the marker (triangles) with in this case a 60 bars look back period, you can tell if the current movement is based on new data or old data.
The plotted prediction is always based on old data, as you can not know new price data before it has happened. Meaning if price doesn't make a new highest or lowest point since the 60 bars back (marker) the next move can be calculated and you can make your trading plan based on that data.