# Partial Close Odd Lot

133

Hi, anyone could help me with my EA that close parial open trades when it reach a X% in profit and move SL to BE, but when lot is nod divisable by 2 like 0.03 its only moves to BE and don`t close partially.

```extern double  Percent_Break = 1;// Risk Reward to close partial
extern double  Percent_RealizacaoParcial = 50;//% of open open position ```

```double openPrice, stopPrice, BE_Pips, StpB, StpS, CalculoRP, TamanhoLot, CloseLot;

CalculoRP = 100/Percent_RealizacaoParcial;//Partial calc

int total=OrdersTotal();
for (int cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS);
int mode=OrderType();
if ( OrderSymbol()==Symbol() )
{

string Coment;
openPrice = OrderOpenPrice();
stopPrice = OrderStopLoss();
TamanhoLot = OrderLots();//Lot Size
Coment = OrderComment();
CloseLot = TamanhoLot/CalculoRP;
BE_Pips = ((openPrice - stopPrice)*Percent_Break);

if(BE_Pips<0) BE_Pips = BE_Pips*-1;

StpS = openPrice-BE_Pips;
StpB = openPrice+BE_Pips;

if(mode == OP_SELL && stopPrice > openPrice && Ask<= StpS && OrderSymbol()==Symbol())
{

if (StringFind(Coment, "from #", 0) == -1)
{

}
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),MagicNumber);
}
else
{

if(mode == OP_BUY && stopPrice < openPrice && Bid>= StpB && OrderSymbol()==Symbol() )
{
if (StringFind(Coment, "from #", 0) == -1)
{
OrderClose(OrderTicket(), CloseLot, Bid, 0);
}

OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),MagicNumber);
}
}
}
}

}
```

Thanks, i`m learning so i`m sorry for this question :D

15321

andreforex: t close parial open trades when it reach a X% in profit and move SL to BE, but when lot is nod divisable by 2 like 0.03
The amount closed and the remaining amount must both be at least min lot and a multiple of lot step; close 0.02 and keep 0.01 or visa versa. See my code
289

I found (maybe I haven't searched enouqh) that <Mt5 does not have built in function for NormalizeLotsByPercent(lots,percent) or near similar to the subject. In mt3 was, just assigning the predefined exact values, if 0.03 than close 0.01 or 0.02 than last 0.01, maybe someone made with %'s, but should be as far as I know :
```// should be selected the order in the trade-pool from previous functions
double NormalizeLotsByPercent( double c_lots, double c_percent ) {
double minLots = MarketInfo(OrderSymbol(), 23);
double stepLots = MarketInfo(OrderSymbol(), 24);
double c_lotsPart = minLots;
while(c_lotsPart < (c_lots*c_percent/100.0)) { // val nearest upper %
c_lotsPart = c_lotsPart + stepLots;
}
return c_part;
}```
In Modify instead of OrderOpenPrice() should be Ask, since it could be lower than the open price..
`OrderModify(OrderTicket(),0.0,Ask,OrderTakeProfit(),MagicNumber);`
15321

 edddim: :In Modify instead of OrderOpenPrice() should be Ask, since it could be lower than the open price.. You can not change the open price of an open order; only pending orders.
15321

You can't place the SL at Ask (or for buy, the Bid) because 1) it would be triggered immediately and 2) doesn't abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
289

( haven't checked other variables :( )

```if(mode == OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber() == MagicNumber && stopPrice > openPrice && Ask<= StpS ) {
double part_Lots = NormalizeLotsByPercent(TamanhoLot, Percent_RealizacaoParcial);
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),0);
bool close_only_part = OrderClose(OrderTicket(), part_Lots, Ask, 0);
} ```

As alternative solution.

Edit modified.