I want to know the mistake that I have made in my code

Please tell me the mistake I have made in this code
double LotsOptemized()
{
double Lot=Lots;
double Profit, PrevLots;
// for(int i=OrdersHistoryTotal(); i>=0; i–)
for(int i=0; i<OrdersHistoryTotal(); i++)
{
if(CheckOpenOrders()== false)
{
OrderSelect(i, SELECT_BY_POS, MODE_HISTORY);
if(OrderSymbol() == _Symbol)
{
Profit=OrderProfit();
PrevLots=OrderLots();
OrderNo = i;
if(Profit>=(PrevLots x TakeProfit-100))
{
Lot=NormalizeDouble(Lots,1);
return(Lot);
}
if(Profit<=(0-(PrevLots x StopLoss-100)))
{
Lot=NormalizeDouble(PrevLots*2,1);
return(Lot);
}
else
{
Lot=NormalizeDouble(PrevLots,1);
return(Lot);
}
break;
}
}
}
return(Lot);
}

Maybe an else if, maybe not. I don’t understand why you need to optimize the lot amount.

if(Profit<=(0-(PrevLots x StopLoss-100)))

versus

else if(Profit<=(0-(PrevLots x StopLoss-100)))

1 Like

Thank you very much for helping, because it is working.