Hi guys, anyone can tell me where my code is wrong.
So i want make a function to close all open orders(regardless of order type) after reach target profit, but somehow, the EA only close buy or only close sell after reaching target profit.
Here's the code:
So i want make a function to close all open orders(regardless of order type) after reach target profit, but somehow, the EA only close buy or only close sell after reaching target profit.
Here's the code:
Inserted Code
void close(bool accumulation, double target){ if (accumulation == true){ double orderProfit = 0; for (int i=0; i<OrdersTotal(); i++){ if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true){ orderProfit += OrderProfit(); if (orderProfit >= target){ for (int ic=0; ic<OrdersTotal(); ic++){ if (OrderSelect(ic, SELECT_BY_POS) == true){ if (OrderType() == 0){ bool tutup = OrderClose(OrderTicket(), OrderLots(), Bid, 0, clrGreen); komen("Close ALL karena TARGET", "255, 255, 255"); } if (OrderType() == 1){ bool tutup = OrderClose(OrderTicket(), OrderLots(), Ask, 0, clrGreen); komen("Close ALL karena TARGET", "255, 255, 255"); } } } } } } } }