Could someone please help me with my LotsizeCalc() function.
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?
double LotsizeCalc()
{
if(OrderSelect(lastTradeTicket(),MODE_HISTORY))
if(OrderProfit()<0 && tradeNumber <=MaximumTrades)
{
if(OrderLots()==0)
martinlot = LotSize;
else
martinlot = OrderLots();
double lots = martinlot * MartingaleAmount;
martinsize = lots;
tradeNumber++;
}
else
{
double lots = LotSize;
martinsize = lots;
tradeNumber=1;
}
return(martinsize);
}
//+------------------------------------------------------------------+//| Enter trade |//+------------------------------------------------------------------+void EnterTrade(int type){
Print("Entering Trade Number 1");
tradeNumber =1;
int err=0;
double price=Bid,
sl=0,
tp=0,
lotsize = LotsizeCalc();
Comment(ScreenComment+"\nThis is trade number: "+(string)tradeNumber+"\nThe Lotsize is: "+DoubleToStr(lotsize,2));
if(type == OP_BUY)
price =Ask;
//----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);
if(OrderType()==OP_BUY){
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) );
if(err==ERR_TRADE_NOT_ALLOWED)MessageBox("You can not place a trade because \"Allow Live Trading\" is not checked in your options. Please check the \"Allow Live Trading\" Box!","Check Your Settings!");
}
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi,
Could someone please help me with my LotsizeCalc() function.
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?
Thanks in advance,
Thierry