# How to take only one action on lots per condition???

227

hi

i would like to divide the Order Lots (Praticl close)when the Profit  reaches certain level but the problem that it continues to divide , need help to know how to break the loop and don't repeat itself

//-------------------------------------------------

void PartialClose()

{

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

if( Magic == OrderMagicNumber() )

{

int Tk=100;

if(Bid > OrderOpenPrice()+(Tk*Point)){

OrderClose(OrderTicket(), OrderLots()/2, Bid, 3, Red);

}

}

if(OrderType() == OP_SELL){

}

}

}

}

15925

micoul81: i would like to divide the Order Lots (Praticl close)when the Profit  reaches certain level but the problem that it continues to divide , need help to know how to break the loop and don't repeat itself
1.  Play video Please edit your post. For large amounts of code, attach it.

2. You can't use OrderLots()/2 because that is not a multiple of LotStep, and you can't close or have remaining less than MinLot. See my code
3. You are only checking if price may trigger a partial close. You aren't checking if you have already done it.
• Set a flag in persistent storage (files, global variables w/ flush)
• I move SL to BE+1 before the partial close. That way I know that I already did it.
• Open two orders.
227

Sorry for number 1

2 and 3 still complicated for me

What's the meaning of BE+1

can't handle it

1399

Q: What's the meaning of BE+1 ?

A: Breakeven + 1

227

thanks deysmacro

227

it continue to divide lots
227

```  void PartialClose()
{
double Lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
int x = 0; if(Lotstep == 0.01) x = 2; else x = 1;

for(int i = OrdersTotal()-1; i >= 0; i--){
if( Magic == OrderMagicNumber() )
{
int Tk=100;
double LOTS = OrderLots();
double Dividelot = NormalizeDouble(LOTS * 0.5, x);

if(Bid > OrderOpenPrice()+(Tk*Point)){
OrderClose(OrderTicket(), Dividelot*2, Bid, 3, Red);
}
}
if(OrderType() == OP_SELL){
}
}
}
}

}
```
227

any help please to solve this problem , still can't handle it

Moderator
10651

You need to do something like this as suggested by WHRoeder

```         if(OrderType() == OP_BUY && OrderStopLoss()<OrderOpenPrice()){
if(Bid > OrderOpenPrice()+(Tk*Point)){
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+Point,OrderTakeProfit(),0,clrNONE );
OrderClose(OrderTicket(), Dividelot*2, Bid, 3, Red);
}
}
}```

Not tested and checking success of OrderModify and OrderClose required

227

GumRai:

You need to do something like this as suggested by WHRoeder

Not tested and checking siccess of OrderModify and OrderClose required

```  void PartialClose()
{
double Lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
int x = 0; if(Lotstep == 0.01) x = 2; else x = 1;

for(int i = OrdersTotal()-1; i >= 0; i--){
if( Magic == OrderMagicNumber() )
{
int Tk=100;
double LOTS = OrderLots();
double Dividelot = NormalizeDouble(LOTS * 0.5, x);

if(Bid > OrderOpenPrice()+(Tk*Point)){
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()+50*Point,0,0,clrNONE );
OrderClose(OrderTicket(), Dividelot*2, Bid, 3, Red);
}
}
if(OrderType() == OP_SELL&& OrderStopLoss()>OrderOpenPrice()){

OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss()-50*Point,0,0,clrNONE );
}
}
}
}

}
```
Moderator
10651

micoul81:

What do you mean "it still doesn't work"?

What doesn't work?