int wonTrades=0;
int lostTrades=0;
double profitToday=0;
double profitYesterday=0;
double profitWeek=0.0;
double profitMonth=0.0;
double profitTotal=0;
double totalLotsTraded=0;
double maxLotsizeUsed=0;
double profitFactor=-1;
double totalAmountWon=0;
double totalAmountLost=0;
for(int l=OrdersHistoryTotal();l>=0;l--)
{
if(OrderSelect(l,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol())
{
if(OrderMagicNumber()==magicbuy || OrderMagicNumber()==magicsell)
{
totalLotsTraded += OrderLots();
maxLotsizeUsed = MathMax(maxLotsizeUsed, OrderLots());
if(OrderProfit()>0) wonTrades++;
else lostTrades++;
double orderProfit=(OrderProfit()+OrderSwap()+OrderCommission());
if(orderProfit<0) totalAmountLost+=orderProfit;
else totalAmountWon+=orderProfit;
profitTotal+=orderProfit;
if(OrderCloseTime()>=iTime(_Symbol,PERIOD_D1,0) && OrderCloseTime()<iTime(_Symbol,PERIOD_D1,0)+86400) profitToday+=orderProfit;
if(OrderCloseTime()>=iTime(_Symbol,PERIOD_D1,1) && OrderCloseTime()<iTime(_Symbol,PERIOD_D1,0)) profitYesterday+=orderProfit;
if(OrderCloseTime()>iTime(_Symbol,PERIOD_D1,7) && OrderCloseTime()<iTime(_Symbol,PERIOD_D1,0)+86400) profitWeek+=orderProfit;
if(OrderCloseTime()>iTime(_Symbol,PERIOD_D1,30) && OrderCloseTime()<iTime(_Symbol,PERIOD_D1,0)+86400) profitMonth+=orderProfit;
}
}
}
}