Download MetaTrader 5
To add comments, please log in or register
No time to learn MQL5? The source code library is at your service!
Farrokh Faghih
316
Farrokh Faghih 2014.05.12 20:50 

How to get Account Profit of an specific time? For example I want to get profit of an account since first day of registering to yesterday.

Should I utilize AccountProfit()? How?

qjol
3243
qjol 2014.05.12 21:11  

first you have to make sure the entire history is shown

then you have to loop all the orders, select them, make sure it meets your conditions and calculate them using: OrderProfit + OrderCommission + OrderSwap

Farrokh Faghih
316
Farrokh Faghih 2014.05.12 21:57  
qjol:

first you have to make sure the entire history is shown

then you have to loop all the orders, select them, make sure it meets your conditions and calculate them using: OrderProfit + OrderCommission + OrderSwap


I don't get how to specify the date period for this loop. could you describe it more?
qjol
3243
qjol 2014.05.12 22:54  
farrokhfa:

I don't get how to specify the date period for this loop. could you describe it more?
already written above

qjol:

make sure it meets your conditions

example: (didn't checked or test)

if (OrderCloseTime() <= iTime(Symbol(), PERIOD_D1, 1)) // Order Close Time is smaller or equals to yesterday
Farrokh Faghih
316
Farrokh Faghih 2014.05.13 07:51  
qjol:
already written above

example: (didn't checked or test)




Are you sure it works? it doesn't run on my tester.

    {//++++ Compute hiBal, loBal, RRR, 
    int     tickets[],      nTickets = GetHistoryOrderByCloseTime(tickets);
    double  tradePips[];    ArrayResize(tradePips, nTickets);
    double  balances[];     ArrayResize(balances,  nTickets+1);
    double  pipsLost    = 0.,   pipsWon = 0.;
    int     nLost       = 0,    nWon    = 0;
    double  prevBal = AB;
    for(int iTicket = 0; iTicket < nTickets; iTicket++) if (
        OrderSelect(tickets[iTicket], SELECT_BY_TICKET)
    ){
        double  profit  = OrderProfit() + OrderSwap() + OrderCommission(),
                pips    = profit / OrderLots() / perPipPerLot;
        balances[iTicket]   = prevBal;  prevBal -= profit;
        tradePips[iTicket]  = pips;
        if      (pips > 0.){    pipsWon  += pips;   nWon++;             }
        else if (pips < 0.){    pipsLost -= pips;   nLost++;            }
    }
    balances[nTickets]  = prevBal;
    int     iHiBal      = LocalExtremeArray(balances, MM.Lookback, 0, +1),
            iLoBal      =      ExtremaArray(balances,    iHiBal+1, 0, -1);
    double  hiBal       = balances[iHiBal],
            loBal       = balances[iLoBal];
    if (nWon * nLost > 0){
        double  riskAve     = pipsLost / nLost,
                rewardAve   =  pipsWon / nWon;
        win.rate    = nWon; win.rate    /= nWon+nLost;  // FP divide
        RRR         = rewardAve/riskAve;
        expectancy  = (win.rate * rewardAve - (1-win.rate) * riskAve)
                    / riskAve;                                              }
    else{   win.rate=1.;        RRR     = 1.;   expectancy=0.;              }
    }//++++ Compute hiBal, loBal, RRR, makeUpPips

where is GetHistoryOrdersByCoseTime()? I want the EA print the profit of yesterday. Would you mind if you put the whole SRC code together?

qjol
3243
qjol 2014.05.13 09:05  
i'm not sure about the tester could be the tester uses order history as been made in the tester and not the real history (never checked)
try in real life (on a chart not on tester)
whroeder1
13627
whroeder1 2014.05.14 15:01  
farrokhfa: where is GetHistoryOrdersByCoseTime()?
Could EA Really Live By Order_History Alone? - MQL4 forum #2
Farrokh Faghih
316
Farrokh Faghih 2014.05.16 13:11  
qjol:
i'm not sure about the tester could be the tester uses order history as been made in the tester and not the real history (never checked)
try in real life (on a chart not on tester)

Thank you
Farrokh Faghih
316
Farrokh Faghih 2014.05.16 13:11  
whroeder1
13627
whroeder1 2014.05.16 14:18  
qjol: i'm not sure about the tester could be the tester uses order history as been made in the tester and not the real history (never checked)
Tester only has tester history.
/
To add comments, please log in or register