How to calculate moving-window values

Consider scripting a FIFO of timestamps and values. Hold the FIFO in a list in your python script module for efficiency. On script reloads, preload your FIFO from the DB. Otherwise, when the tag changes or on some timer event, append to the FIFO list (timestamp and new value), and compute against the oldest entry. Remove the oldest from the list if it falls before your sliding window.

If you don't want to script it, this post has a similar operation done with expression tags and functions from my free add-on module: