Please edit your post to use "Preformatted text" formatting for the code you pasted. It's the button in the comment editor that looks like this: </>
We can't see your indentation, and it matters.
On what @pturmel 's point it seems like you have 8 spaces indented on your line on your first indented if statement but it should be 4 spaces or 1 tab. Try fixing your indentation first and then see if you're still experiencing an issue (and open up console and see if it's spitting out an errors).
The first step when something doesn't work is to open the console and see if there are errors there.
Maybe nothing happens because something is broken. The console will tell you that.
The event must be on the root container, not the window, if you are monitoring a root container property. Putting the event on the window will only catch changes to the window's own properties.
I don't understand, if I want a window to close when a counter (customProperty) is equal to 5 (that's what I want to do). I have the custom created inside the root container of the PopupWindow and it is that custom that I am trying to interact with the closing of the window.
A property change event is only sent to the component that has the property. The root container of a window is not the window. Move your event script to the root container.