I need to determin the BarIndex of the first trading day of january current year within a screener. How do I manage?
You are lucky because no more than 254 bars have elapsed (max. lookback for ProScreener):
MyBar = 0
FOR i = 0 to 253
IF date[i] < 20180101 THEN
MyBar = i - 1
break
ENDIF
NEXT
SCREENER [MyBar] (MyBar as "MyBar")
You cannot write “= 20180101” because that day could not be a trading day, so once you have found the first day BEFORE that date, you know the bar AFTER that one is the first trading day of this year, it can be different according to instruments that have, since then, accumulated less trading days.