I want to get the barindex of the current bar according to the hourly timeframe, from a script that runs on the 1m timeframe. When I apply timeframeset and timeframeexpand (like in the following code), it doesn't work. It returns the barindex based off the 1m timeframe itself, but not the hourly timeframe.
To get the bar indexes that corresponds to a different interval you can employ alternative methods, without invoking TimeFrame functions.
In this forum, there are multiple posts (like this) to detect a new day, a new week, month, etc.
You could use similar logic to detect when a bar is the first one in an Hour and then use the ValueWhen() function to get the corresponding BarIndex().