Thanks for helping out @CraigWeb @phildunlap @Jared-Wiltshire ,
I couldn't get it to work with a Persistent TCP data on central server, so set up on an ES on Site and it seems to be tracking good. All the 4's and 1's are lining up where I expect them.
Thanks Again.
I got this to work:
var prevVal = p709.lastValue(2);
var thisVal = p709.lastValue(1);
var nextVal = p709.lastValue();
if (thisVal >= prevVal && thisVal >= nextVal) {
// peak
return 4;
} else if (thisVal >= prevVal && thisVal < nextVal) {
// still climbing
return 3;
} else if (thisVal < prevVal && thisVal < nextVal) {
// trough
return 1;
} else {
// falling
return 2;
}