Opening and closing an order on a different pair from which the EA is placed on

Hi, wondering if anyone can help. I have an EA that I place on a chart (lets say the EURUSD) and it opens 2 trade on two different pairs (GBPUSD and AUDUSD) using the code:

ticket = ordersend (“AUDUSD”, OP_BUY, Lot, MarketInfo (“AUDUSD”, MODE_ASK), Orderslippage, 0, 0, EA_Comment, Magic, 0, Red);
ticket = ordersend (“GBPUSD”, OP_BUY, Lot, MarketInfo (“GBPUSD”, MODE_ASK), Orderslippage, 0, 0, EA_Comment, Magic, 0, Red);

First of all, this works, but is there a more efficient way to write it rather than 2 tickets?

And secondly, how do you go about closing the trades - the current methods I have tried don’t close the trades. I don’t want to close all trades in case I am trading manually as well, just the specific ticket numbers that were opened.

I would be grateful for any help.

You code for OrderSend() is correct. Presumably you check the error status after each call. Wouldn’t you second order be dependent on the success of the first?

I’m not sure why you having problems closing orders. Never been that difficult to find the EA magic number (you do use magic numbers??) with OrderSelect(). But again one ticket at a time.

Thanks for the reply. There’s no problem opening the tickets, just I was figuring a way to close them.

So if the magic number was 1, then would I would use (on the EURUSD chart):

OrderSelect (OR,SELECT_BY_POS,MODE_TRADES);
if (OrderSymbol ()==GBPUSD()&&OrderMagicNumber()==1)

to propagate the closing?

I think you are right, but sometimes psuedo code can be misunderstood and with coding some minor detail can cause untold grief.

You need to write proper code, test it and then describe what is happening.