As you know, Garmin's internal GRADE metric is not exposed to us.
I've toyed with several algorithms and am pretty happy now. I run a 12 second rolling linear average. It causes a lag in reporting gradient changes, but better than the noise of the value bouncing around a lot. Recording Elevation and Distance and simply doing 100*deltaElev/deltaDist. I added some logic to fast start the calc when I detect 3 consecutive elevation points in the opposite direction of the trend. And I reset the rolling avg when speed drops below 1mph (walking slow or stopped).
That seems to finally give me a decent stable and reasonable gradient metric that I combine with Vertical rate (feet or meters) when grade > 2.5%.
Anyway, I was considering getting a bit more sophisticated and implementing a 20 point exponentially weighted moving average (EWMA). What that does is count the more recent points more than the older points (say from 10 or 15 seconds ago), and in theory would respond quicker to a change in the road's grade, but also tame the noise compared with just looking at the last few seconds. But depending on the decay rate of the weights, that could just make things noisy again.
Curious if anyone has tried EWMA for grade? I know - #nerdAlert But that's what happens when an engineer rides a bike ;-)