I just noticed that the construction of your run function is entirely wrong. int bar is a standalone function. Keep it outside of run().

Zorro will call int bar for you. That's how it changes the bar type from time-based to custom bar. That's why it's called a "user-defined bar". You (the user) are defining the bar:
https://zorro-project.com/manual/en/bar.htm