How to get AccountProfit of an specific time?

 

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?

 

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

 
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?
 
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
 
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?

 
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)
 
farrokhfa: where is GetHistoryOrdersByCoseTime()?
Could EA Really Live By Order_History Alone? - MQL4 forum #2
 
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
 
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.
Reason: