# Help With Multiplier

[Deleted]

Hi, i added the feature of multiplier in my expert, that is if the last trade is negative then the ea will open the new trade with double the lot that was opened in the previous trade. My Problem is that the multiplyer doesnt mutliply in a correct way, i think it just generates a number higher than the previous one. So here is my code:

```if (BuyProfit>=0) {LastLot=LotsNormal;}
if (SellProfit>=0) {LastLot=LotsNormal;}

double DoubleLots=LastLot;

if (B1>0.2){

{
DoubleLots=DoubleLots*Multiplier ;
OrderSend(Symbol(),OP_SELL,DoubleLots,Bid,SlipPage,Bid+StopLoss*Point,Bid-TakeProfit*Point,"Abdu EA",MagicNumberSell,0,Red);
Time0=Time[0];
GetLastError( );
}
}
```

I am sure from every thing (BuyProfit,LastLot...)

233

Abdull1996:

Hi, i added the feature of multiplier in my expert, that is if the last trade is negative then the ea will open the new trade with double the lot that was opened in the previous trade. My Problem is that the multiplyer doesnt mutliply in a correct way, i think it just generates a number higher than the previous one. So here is my code:

I am sure from every thing (BuyProfit,LastLot...)

Is your buyprofit variable calculating correctly? make sure it cycles the historical trades correctly for the most recent profit. It should do something like this:

```      void LastClosedProfit()
{

if(Martingale == false){LotSize = Lots;return;}
RecentProfit = 0;
int Tic = 0;
for (int trall=0; trall<OrdersHistoryTotal(); trall++) {
OrderSelect(trall, SELECT_BY_POS, MODE_HISTORY);
if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
{
if(OrderTicket() > Tic && OrderProfit() !=0){Tic = OrderTicket();RecentProfit = OrderProfit();}

}
}

}   ```
23782

Only problem I see with the above, is it doesn't return the profit of the last close order, it returns the profit of the last OPENED order. Not the same if there are multiple orders.
```double LastClosedProfit(){
double   RecentProfit = 0;
datetime lastClosePrev = 0;
for(int pos=0; pos < HistoryTotal(); pos++) if (
OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY)   // Only orders
&&  OrderCloseTime()    > lastClosePrev             // not yet processed,
&&  OrderMagicNumber()  == magic.number             // my magic number
&&  OrderSymbol()       == Symbol()                 // and my pair.
&&  OrderType()         <= OP_SELL){    // Avoid cr/bal forum.mql4.com/32363
lastClose = OrderCloseTime();
RecentProfit = OrderProfit();
}
return(RecentProfit);
}```