It is a US imported marketing ploy like Black Friday and is solely for the benefit of retailers. We don't do it at all.

@PercyKirke
It's an old, old Scottish and Irish tradition that made its way to North America hundreds of years ago with emigrants from Ireland and Scotland, and came back to mischievously annoy the pants off certain sections of English society.
I've always thought "trick or treat" is a strange custom to teach children. It's basically extortion.

In the part of Ireland where my mother and all her ancestors come from trick or treating while disguised is called Vizzarding. A vizzard is a mask. Maybe it comes from the French 'visage' (= face). Vizzarding groups would recite a rhyme or a song and would be rewarded with food or money.
I grew up in Dublin where Hallowe'en (translation: the eve of All Hallows, or All Saints) was a big traditional Irish thing. We prepared for a full on celebration in fine pagan form (in a Catholic convent school no less) by making and decorating masks. The following day was and still is All Saints Day, a holy day of obligation (to go to Mass).
In ancient times, Hallowe'en ('Samhain') was a night on which the boundary between life and death became blurred, a liminal time, when the seasonal cycle of growth and harvest was finished and the period of darkness arrived. Cattle were brought down from mountain pastures. Animals were slaughtered for winter food. People left out food for passing souls and ancient beings such as the SÃ; guising and turnip carving echoed the link with grotesque nature spirits and the dead. There were and still are rituals involving bonfires, divination using symbolic objects baked into barm breac and seasonal fruits and nuts - as a child, my friends and I used to go from house to house asking for apples and nuts, very typically associated with Hallowe'en customs.
www.thejournal.ie/readme/only-for-halloween-surviving-in-america-it-probably-would-have-died-out-here-3667762-Oct2017/
As the mother of American children I have fond memories and much photographic evidence of evenings of great fun trick or treating, and the lingering sweet smell of pillowslips full of candy which the DCs emptied out onto the sittingroom floor when they got home to swap favourites among themselves.