# Thread: Martingale after X Losses

1. ## Martingale after X Losses

hy
can somebody help
how to add value to martingale like this:

act martingale not after first lose but after X loses ?

int MartingaleFactor()
{
int histotal=OrdersHistoryTotal();
if (histotal>0)
{
for(int cnt=histotal-1;cnt>=0;cnt--)
{
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderProfit()<0)
{
LotsFactor=LotsFactor*Multiplier;
return(LotsFactor);
}
else
{
LotsFactor=InitialLotsFactor;
if(LotsFactor<=0)
{
LotsFactor=1;
}
return(LotsFactor);
}
}
}
}
}
return (LotsFactor);
}

2. Hi przem81621,

Try this :

Code:
```int MartingaleFactor()
{
int counter=0;
int histotal=OrdersHistoryTotal();
if(histotal>0 && OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
for(int cnt=X;cnt>=1;cnt--)
{
if(OrderSelect(histotal-cnt,SELECT_BY_POS,MODE_HISTORY) && OrderProfit()>=0)continue;
if(OrderSelect(histotal-cnt,SELECT_BY_POS,MODE_HISTORY) && OrderProfit()<0)counter++;
}
}
if(counter==X)LotsFactor=LotsFactor*Multiplier;else LotsFactor=InitialLotsFactor;
if(LotsFactor<=0)
{
LotsFactor=1;
}
return(LotsFactor);
}```

3. thank you very much needed this