@l-andorrà thanks for that
but for example:
if i have 5 open orders
buy EURUSD magic number 1001
buy GBPUSD magic number 1001
buy EURCHF magic number 1001
buy GBPJPY magic number 1001
sell EURUSD magic number 1005
how can use the variables as you mentioned to detect and close the 4 "1001" orders on profit ?