# Progressive lot size issue

27

Hello,

English isn't my native language, but I'll try to get by..

I'm a little bit new to mql4, but have been trying to get everything going, I was testing an idea, then I needed to test a progressive lot size, my EA opens one trade at a time, so I wanted to check if the previous closed trades hit tp or not, if they hit take profit, then I start the next trade using 1 lot. If the closed trades didn't hit take profit target I increase the lot of the next trade by a pre-defined lot step.

I got it going, but sometimes the EA doesn't increase the lot size, it repeats the lot size for the next trade, but increase it in the following trade.

I'm a little bit furious because I can't find where is the issue.

I coded 2 functions, the 1st one to count the closed losses and the other function to calculate the lotsize based on the count of those closed trades.

Note: lot, lotstep and progressivelot are extern variables

Help would be much appreciated.

Thank you all!

```int PrevClosed()
{
int count=0;

for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
continue;
if(OrderSymbol()==Symbol()&& OrderMagicNumber()==magic)
{
if(OrderTakeProfit()!=OrderClosePrice())
{
count++;
}
}
}
Print(count);
return(count);
}
//////////////////////////
double LotSize()
{
double lots;

if(progressivelot==true)
{
lots=lot+(prevclosed*lotstep);

}
else
{
lots=lot;

}
Print(lots);

return(lots);
} ```
Basic Principles - Trading Operations - MetaTrader 5