if a first sentence is in the past perfect and a second is in the same time with a first should a first be in past perfect too or in past simple? E.g: Alex said he had been there when that happened or Alex said he had been there when that had happened
In native English you will hear both, simply depending the personal preference of the speaker and on the context.
I suspect most speakers would omit the second had for the sake of brevity and because its omission makes no difference to the meaning.
So an army officer might say that he had been there when the victory had been secured, especially if it was a long time ago.
Here you might argue that the use of the past perfect gives listeners a sense of the period. But was secured is equally correct.
And a witness might say that she had been there when the bus overturned, preferring the simple past, especially if it's a recent event and if the bus is still lying on its side.
In short, this isn't a question of correctness but of choice.