Yes sir, you can detect the first candle of a new day by comparing the current bar’s day with the previous bar’s day.
A simple way is to use dayofmonth:
Here, ta.change(dayofmonth) checks whether the day has changed compared with the previous candle.
When the day changes:
-> newDay becomes true
-> The current candle is treated as the first candle of the new day
-> Your required logic can be executed only when newDay is true
For example:
You can use this for tasks such as:
-Resetting daily variables
-Capturing the first candle’s high and low
-Calculating daily opening levels
-Starting a new daily trading cycle
-Resetting strategy conditions
So the main idea is to detect the change from the previous day’s value rather than checking every candle individually.