I need help, this is a very basic question, but...

I'm not a coder, but I'm trying to code an EA for the first time,
So, I need to know how to close all trades based on MagicNumber variable...
I want to put an order but before close all open trades of that EA. Is this possible?
Thanks!
