# Lotsize calculator error

127

Hi,

I would like to multiply my lotsize with the 'MartingaleAmount' if my last trade was a loser. If my last trade was a winner I would like to use the 'normal' lotsize. Unfortunately, when I backtest the EA I get error 4051 from the , which means "Invalid function parameter value.".

It has something to do with the lotsize, because the EA works when I try to run the EA without the "LotsizeCalc()" function.

Does anyone know why my lotsize function won't work?

Thierry

```extern int MaximumTrades = 10;
extern double StopLoss=25;
extern double TakeProfit=50;
extern double MartingaleAmount = 1.5;
input double   LotSize=0.1;

int magic;
double pips;
string ScreenComment;
double martinlot;
double martinsize;```
```double LotsizeCalc()
{

{
if(OrderLots()==0)
martinlot = LotSize;
else
martinlot = OrderLots();

double lots = martinlot * MartingaleAmount;
martinsize = lots;
}
else
{
double lots = LotSize;
martinsize = lots;
}

return(martinsize);
}

//+------------------------------------------------------------------+
//+------------------------------------------------------------------+

int err=0;
double price=Bid,
sl=0,
tp=0,
lotsize = LotsizeCalc();
//----
int ticket =  OrderSend(Symbol(),type,lotsize,price,30,0,0,"1 ",magic,0,Magenta);
if(ticket>0){
if(OrderSelect(ticket,SELECT_BY_TICKET)){
sl = OrderOpenPrice()+(StopLoss*pips);
if(StopLoss==0)sl=0;
tp = OrderOpenPrice()-(TakeProfit*pips);
sl = OrderOpenPrice()-(StopLoss*pips);
if(StopLoss==0)sl=0;
tp = OrderOpenPrice()+(TakeProfit*pips);
}
if(!OrderModify(ticket,price,sl,tp,0,Magenta)) {
err = GetLastError();
Print("Encountered an error during modification!"+(string)err+" "+ErrorDescription(err)  );
}
}
else{//in case it fails to select the order for some reason
Print("Failed to Select Order ",ticket);
err = GetLastError();
Print("Encountered an error while seleting order "+(string)ticket+" error number "+(string)err+" "+ErrorDescription(err)  );
}
}
else{//in case it fails to place the order and send us back a ticket number.
err = GetLastError();
Print("Encountered an error during order placement!"+(string)err+" "+ErrorDescription(err)  );