After further investigation, I think this is the correct code
(not for tradestation, but it can easily get translated):
----------------------------------------------------------------------------------
if barindex >= N-1 then
Length = 0
PriceMax = highest[N](customclose)
PriceMin =...