Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
When you use OrderHistoryTotal() remeber that the history is loaded from the MT4 platfrom, so if you are looking for last week history but in MT4 history you have set "Last day", in OrdersHistoryTotal() there will be only trades closed on last day.
Do it, to make su to load all history.
PS. You are not couting OrderSwap() in your function. And remember that, due to the fact that OrderSwap() and OrderCommision() are negative value you need to add them, not subtract them.
When you use OrderHistoryTotal() remeber that the history is loaded from the MT4 platfrom, so if you are looking for last week history but in MT4 history you have set "Last day", in OrdersHistoryTotal() there will be only trades closed on last day.
Do it, to make su to load all history.
I did that, even then the weekly result from function is $ -92
Where as the real from history is $ 574.51
What I am doing wrong?
You are not couting OrderSwap() in your function. Remember that, due to the fact that OrderSwap() and OrderCommision() are negative value you need to add them, not subtract them.
And remeber to exclude OrdeType()>1 (pending closed, deposits and withdrawals)
You are not couting OrderSwap() in your function. Remember that, due to the fact that OrderSwap() and OrderCommision() are negative value you need to add them, not subtract them.
And remeber to exclude OrdeType()>1 (pending closed, deposits and withdrawals)
double AccountWeekProfit()
{
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(type == OP_BUY || type == OP_SELL)
if(OrderCloseTime() >= starttime )
{
netprofit += (OrderProfit() +OrderSwap()+ OrderCommission());
}
}
}
return(netprofit);
}
After this also the week profit is -78
where as last week profit is -565.20
dont know where is the mistake
double AccountWeekProfit()
{
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(type == OP_BUY || type == OP_SELL)
if(OrderCloseTime() >= starttime )
{
netprofit += (OrderProfit() +OrderSwap()+ OrderCommission());
}
}
}
return(netprofit);
}
After this also the week profit is -78
where as last week profit is -565.20
dont know where is the mistake
Firstly, the mistake is that you refuse to follow moderators suggestion, like posting the code in the right way.
You are using an INT variable to store a double value.
{ double netprofit = 0; datetime starttime = iTime(Symbol(), PERIOD_W1, 0); for(int i = 0; i < OrdersHistoryTotal(); i++) { if( !OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) || OrderType()>1 || OrderCloseTime()<starttime) continue; netprofit += OrderProfit() +OrderSwap()+ OrderCommission(); } return(netprofit); }
Firstly, the mistake is that you refuse to follow moderators suggestion, like posting the code in the right way.
You are using an INT variable to store a double value.
Perfect. Good Work. Thanks
Perfect. Good Work. Thanks
<Deleted>
<Deleted>
How many times have you been told to use the code button when pasting code?
When you post code please use the CODE button (Alt-S)!
How many times have you been told to use the code button when pasting code?
When you post code please use the CODE button (Alt-S)!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
}
This function returns $ 4.00 where as my last week profit is (-502.06 Loss ),
Could not figure out what is going wrong. Guys kindly help