The tradition of trick-or-treating goes back almost 1,200 years to a European tradition called "souling". On All Soul's Day.
A soul cake is a small round cake which is traditionally made for All Saints Day or All Souls' Day to celebrate the dead. The cakes, often simply referred to as souls, were given out to soulers (mainly consisting of children and the poor) who would go from door to door on Halloween singing and saying prayers for the dead. Each cake eaten would represent a soul being freed from Purgatory. The practice of giving and eating soul cakes is often seen as the origin of modern trick-or-treating. In Lancashire and in the North-east of England they were also known as Harcakes.
Halloween is a celebration observed on 31 October, primarily in regions of the Western world; the traditions and importance of the celebration vary significantly between geographical areas. Halloween is a time of celebration and superstition. It is thought to have originated with the ancient Celtic festival of Samhain, when people would light bonfires and wear costumes to ward off roaming ghosts.