[question] script create tag from all history tag with all the difference of one hour

Hello so I want to make a timed gateway script that create a tag from all stored tags if they doesn’t exist

and make difference of it every hours like TagValueNow=20 TagValue1HourBefore=10 tagValueDiff=10
how should i do ?