Do you mean something like this?

(I did not test the code below, it could have edge cases, it's just an outline for now.)

int getTimestamp(int tf, int bar){
//when I call this function I don't know which TimeFrame I will use right that moment
//so store it to restore later
int pre_tf = TimeFrame;
TimeFrame = tf;
int result = 0;
for(int i = (bar-1)*tf; i <= bar*tf && result == 0; i++){
if (frame(i)){
result = i;
}
}
int resultTimestamp = utm(wdate(result));
TimeFrame = pre_tf; //restore the original TimeFrame
return resultTimestamp;
}

It could work, but there is another problem.

From the documentation:

When a value > 30000 is used for offset, it is assumed a day number in DATE format, and the corresponding year, month, or day is returned.

I am working with multiple timeframes and long lookback periods: I store the H4 bar prices, and it's size is more than 200.

So there could be a point where I want to check something like this: "which was the exact time of the 200th H4 bar"?

In that case my function call would look like this:

This case the variable inside my function called "result" will be between 47760 and 48000, therefore the wdate wil return a wrong date, because the input value > 30000.

So how should I make this int getTimestamp(int tf, int bar) function?