Please help me to close order once the target profit has been made for the manual trade for orders more than 1

 

I manually place order for the hedging pairs EURUSD & USDCHF at buy at the same time.

I would like to use the ea or Experts>Script to close order once there is profit made at my target profit.

Can someone pls guide me.

I am a newbie in writing ea.. hope there is someone can guide me..

Thanks

 
FES:

I manually place order for the hedging pairs EURUSD & USDCHF at buy at the same time.

I would like to use the ea or Experts>Script to close order once there is profit made at my target profit.

Can someone pls guide me.

I am a newbie in writing ea.. hope there is someone can guide me..

Thanks

if(AccountProfit()>=MinProfit)
   {
   int total=OrdersTotal();
   for (int cnt=total-1;cnt>=0;cnt--)
   {
    if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
    {
      {
         if (OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),1);
         if (OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),1);
      }
    }
   }
   }
Cheers
 

int total=OrdersTotal();

for (int cnt=total-1;cnt>=0;cnt--)

{

if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))

{

if (OrderProfit()>=MinProfit &&OrderType()==OP_BUY)

{

OrderClose(OrderTicket(),OrderLots(),Bid,1);

}

if (OrderProfit()>=MinProfit &&OrderType()==OP_SELL)

{

OrderClose(OrderTicket(),OrderLots(),Ask,1);

}

}

}

Reason: