Closed Order

 

For exdemplo have other questions that I do not know address, I will write here and if you can help me solve:

I wanted to check the profit of the last order that closed positive;
then multiply by Percent.Lost; = PL
then verify that the value (losses) of the open order is less than PL

Example: If profit = 0.50
PL = 0.25
Loss of open order for MathAbs = (-0.20)
Close the order

Other party: does it happens automatically in the analysis?
Close only one order for each order closed with profit. And if not close when closing the older order that is open, check the second oldest open order if it fits in value to close



That closes the negative order within the 50% of the profit of the order that closed positive

extern double Percent.Llost = 50; //(%)

double PL=0;

for(int a=OrdersTotal() - 1; a >= 0; a--)
{

if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==false) break;

//---- check order type
RefreshRates ();
if(OrderType()==OP_BUY)
{
if (Bid > OrderOpenPrice())
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Blue);
}
if(OrderType()==OP_SELL)
{
if (Ask < OrderOpenPrice())
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,Red);
}

}

d=(OrdersHistoryTotal()-1);
if (OrderSelect(d,SELECT_BY_POS,MODE_HISTORY)==true){
if (OrderTakeProfit()>0)
PL=((Percent.Lost/100)*(OrderTakeProfit()));}


if (OrdersTotal()>0)
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)==true){
RefreshRates ();

if(OrderType()==OP_BUY)
{
if (((MathAbs(Bid-OrderOpenPrice())) < PL))
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,BlueViolet);
}
if(OrderType()==OP_SELL)
{
if (((MathAbs(Ask-OrderOpenPrice())) < PL))
OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),0,IndianRed);
}
}

Reason: