Question on partial close of a position

 

Hi, i have an ea that closes 50% of the trade at a certain tp level and lets the remaining 50% run until it hits the stop or hits the second tp level and closes the trade. The problem is i have added code to the ea so it now opens trades at a % of account balance. So for example, the ea may open a trade at 1.5 lots > reach tp 1 and attempt to close 50% of the position. However my broker doesnt allow Microlots so ea will not close the 50% i want. (1.5lots /50%=0.75)

I am only a novice at code. Can anyone suggest any ideas or help me with this one.

Thanks

 

You can try closing the position as the following:

double min_lot = MarketInfo( Symbol(), MODE_MINLOT );
double lot_step = MarketInfo( Symbol(), MODE_LOTSTEP );

double CloseLot = OrderLots()*Percent/100.0;
if ( OrderLots() - CloseLot < min_lot ) { CloseLot = OrderLots(); } //we cannot leave the position that has such a small lot

CloseLot = NormalizeDouble( CloseLot/lot_step, 0 )*lot_step;

if ( CloseLot < min_lot ) { CloseLot = min_lot; } //and we cannot close such a small lot as well