sc.Index is an array called once per bar.

if (sc.GetBarHasClosedStatus(sc.Index) == BHCS_BAR_HAS_CLOSED) is just making sure the actual bar is closed, since SC offers many different bars.

More simple pine script from tradingview:

xPSY = sum(close > close[1],Length) / Length * 100


Actually the indicator is so simple, but really great for trend determination, so if someone could help out would be awesome (I don't expect JCL to do so, since I assume he has his hands full with things to do).

But thank you a lot.