Please friends I need help in this code

 
Hello Frends >>>>>>>>>> pleasae i need help in this code

i just want to close all sell and buy orders in the profit target >=10

this codes below close only sell orders or only buy orders if the profit target >=10 ...... i need to close all orders when the all orders be >= 10 in profit target

i changed the magice numbers to same numbers and not working the expert will open only buy or only sell order !!

please help

for(cnt=0;cnt<OrdersTotal();cnt++){
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol() && OrderMagicNumber () == MagicBuy){
ticketbuy = OrderTicket();OrderSelect(ticketbuy,SELECT_BY_TICKET, MODE_TRADES);profitbuy = profitbuy+OrderProfit() ; // هذا ايخص
openpricebuy = OrderOpenPrice();
}
}

tpb = (OrdersTotalMagicBuy(MagicBuy)*AutomatedTPFactor*Point)+openpricebuy;
double bid = MarketInfo(Symbol(),MODE_BID);
if(UseAutomatedTP==true&&Profit_Target>=10){
if(Bid>=tpb) orderclosebuy(ticketbuy);
}
for(cnt=0;cnt<OrdersTotal();cnt++){
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicSell){
ticketsell = OrderTicket();OrderSelect(ticketsell,SELECT_BY_TICKET, MODE_TRADES);profitsell = profitsell+OrderProfit();
openpricesell = OrderOpenPrice();
}
}
tps = openpricesell-(OrdersTotalMagicSell(MagicSell)*AutomatedTPFactor*Point);
double ask = MarketInfo(Symbol(),MODE_ASK);
if(UseAutomatedTP==true&&Profit_Target>=10){
if(Ask<=tps)orderclosesell(ticketsell);
}
 
Your topic has been moved to the section: MQL4 and MetaTrader 4
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

Please EDIT your post and use the CODE button (Alt-S) when inserting code.

Code button in editor

Hover your mouse over your post and select "edit" ... 

 
ticketbuy = OrderTicket();OrderSelect(ticketbuy,SELECT_BY_TICKET, MODE_TRADES);profitbuy = profitbuy+OrderProfit() ; // هذا ايخص
You already selected an order and retrieve the ticket number. Why are you selecting it again?