If the OrderSelect() fails you then try to use OrderType() . . . how exactly does that make logical sense ? if the OrderSelect() works you do noting . . . just return netprofit which you haven't changed from it's initial value of 0.0.
OMG you are right! Stupid mistake =P Thanks a lot! This is the final function if someone is interested:
double GetWeekProfits() { int type, netprofit = 0; datetime starttime = iTime(Symbol(), PERIOD_W1, 0); for(int i = 0; i < OrdersHistoryTotal(); i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) { type = OrderType(); if(OrderOpenTime() >= starttime && OrderMagicNumber() == MagicNumber) { if(type == OP_BUY) { netprofit += (OrderClosePrice() - OrderOpenPrice()) / DecimalPip; } else if(type == OP_SELL) { netprofit += (OrderOpenPrice() - OrderClosePrice()) / DecimalPip; } } } } return(netprofit); }
Thanks a lot raptor!
OMG you are right! Stupid mistake =P Thanks a lot! This is the final function if someone is interested:
Thanks a lot raptor!
Would you be so kind to help me out? I want to display in COMMENT(); the following:
Trade Statistics
------------------------
Today's Trading : <TT_number_of_trades_made> / <TT_profit_or_loss> - <TT_gain_in_percentage> %
This Month's Trade : <TM_number_of_trades_made> / <TM_profit_or_loss> - <TM_gain_in_percentage> %
Last Month's Trade : <LM_number_of_trades_made> / <LM_profit_or_loss> - <LM_gain_in_percentage> %
------------------------
Any ideas on how to borrow your code above to achieve it? Thanks!
- 2010.10.22
- www.mql5.com
If the OrderSelect() fails you then try to use OrderType() . . . how exactly does that make logical sense ? if the OrderSelect() works you do noting . . . just return netprofit which you haven't changed from it's initial value of 0.0.
double GetWeekProfits()
{
int type, netprofit = 0;
datetime starttime = iTime(Symbol(), PERIOD_W1, 0);
for(int i = 0; i < OrdersHistoryTotal(); i++)
{
if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{
type = OrderType();
if(OrderOpenTime() >= starttime && OrderMagicNumber() == MagicNumber)
{
if(type == OP_BUY||type==OP_SELL)
{
netprofit = netprofit+OrderProfit() + OrderCommission() + OrderSwap(); // DecimalPip;
}
}
}
}
return(netprofit);
}
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good afternoon everyone,
I am trying to calculate the net profit/net loss of an expert advisor for the current week. For some reason, this function always returns 0 during backtesting.
I'll be most grateful if anyone could spot where the error is :-) Thanks in advance!