The version I learnt was the same as that above but the story I was told was that it was written by a jewish girl/boy confined in one of the safe houses in Holland. The treasure was other Jews escaping from Holland and the Pirates were the Germans who all too often caught them.
I was taught it at the same time as Donna Donna another song about the persecution of the Jews but I have no idea if it is true or not.