You cannot use TIME as a variable, since it’s a system constant that cannot be altered.
Use MyTime, instead.
Your idea is fine, it will do.
Selecting the first candle of the month can be done, provided there are no more than 253 candles from then on, si it would be impossible on a TF lower than 4 hours. You’ll need to scan backwards till you find the month’s first day.