Trabalho concluído
![](https://c.mql5.com/i/avatar/avatar_na2.png)
Termos de Referência
Hi
I wanted to add the function into my EA.The code does a partial close on an order that has x amount of pips in the negative
void CheckNewOrderClosed()
{
for(int i=OrdersHistoryTotal()-1;i>=0;i--) // check for closed orders
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_HISTORY);
if(OrderSymbol()==Symbol()) // if order with the same symbol
{
if(OrderProfit()<0||OrderCloseTime()<LastCheckedTime)return; // if order profit is in loss or order checked before then stop
else if(GetBiggestLossOrderTicket()>0) // else proceed to close partial lot if there is order with -500 loss
{
select=OrderSelect(GetBiggestLossOrderTicket(),SELECT_BY_TICKET,MODE_TRADES); // select biggest loss order with ticket number
double partialLotToClose=0.01;
bool closePartial=OrderClose(OrderTicket(),partialLotToClose,OrderClosePrice(),3);
LastCheckedTime=TimeCurrent();
}
}
}
}
int GetBiggestLossOrderTicket() // function to get ticket number for biggest loss order
{
int ticket=0;
double pips,MaxStoredLoss;
for(int i=OrdersTotal()-1;i>=0;i--) // check for opened orders
{
bool select=OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol())
{
if(OrderType()==OP_BUY)
{
pips=(Bid-OrderOpenPrice())/point; // calculate order pips profit
}
else if(OrderType()==OP_SELL)
{
pips=(OrderOpenPrice()-Ask)/point; // calculate order pips profit
}
if(pips<=-20) //if pips less than -500 pips then store the order info
{
if(pips<MaxStoredLoss) // store there is multiple orders with loss then store max loss order
{
MaxStoredLoss=pips; // set max loss stored as the new order loss
ticket=OrderTicket(); // store order ticket
}
}
}
}
return(ticket);
The EA is attached with default setting.Place it in the strategy tester to see what it does.It basically places 8 pending order on a price level at set intervals.4 long and 4 short.
The orders have no SL only TP and then it closes all open orders when a certain profit level is reached.Please ask if unsure.
I want to have external setting for it please
Lots to be closed = ;
Distance to start partial closes = ;
Please let me know if you want to the job
Thank you for your time