English

## Martingale EA calculation problems

 3 FX90903 2015.03.09 11:42 #   Hello,if i understand it right, this could be a solution for PnL per day```double Sum_PnL; for(int G=0; G<=OrdersHistoryTotal()-1; G++)    {    if(OrderSelect(G,SELECT_BY_POS,MODE_HISTORY))     if(OrderMagicNumber()== MagicNumber)       if(OrderOpenTime() >= (TimeCurrent()-(Hour()*60*60+Minute()*60)))       Sum_PnL = Sum_PnL + OrderProfit();       }```
13116
WHRoeder 2015.03.09 14:15 #

1.  Play video Please edit your post. For large amounts of code, attach it.

2. Martingale will blow your account. Why do you want to loose all your money? If you want to double your risk but are trading 12 pairs, shouldn't you increase each by 2/12?
3. History list is not sorted. Make a sorted list Could EA Really Live By Order_History Alone? - MQL4 forum
4. Then you can loop through the list and make your sums easily
Just typed, Not compiled.
```    int     tickets[],      nTickets = GetHistoryOrderByCloseTime(tickets);

#define MAX_DAY 5
double PnL[MAX_DAY]; int iDay=-1; datetime when=0;
for(int iTicket = 0; iTicket < nTickets; iTicket++) if (
OrderSelect(tickets[iTicket], SELECT_BY_TICKET)
&&  OrderType() <= OP_SELL // ignore deleted pending/transfers.
){
datetime oct = OrderCloseTime();
datetime day = DateOfDay(oct);
if(when != day){ when = day; if(++iDay == MAX_DAY) break;
double profit = OrderProfit() + OrderSwap() + OrderCommission();
PnL[iDay] += profit;
}
/////////////////////////////////////////////////////////////////////
static int HR2400 = PERIOD_D1 * 60; // 86400 = 24 * 3600
int      TimeOfDay(datetime when=0){
return (when == 0 ? TimeCurrent() : when) % HR2400 );            }
datetime DateOfDay(datetime when=0){
return (when == 0 ? TimeCurrent() : when) - TimeOfDay(when) );   }
datetime Tomorrow( datetime when=0){
return DateOfDay(when == 0 ? TimeCurrent() : when) + HR2400);    }
datetime today = DateOfDay(when == 0 ? TimeCurrent() : when);
int      iD1   = iBarShift(NULL, PERIOD_D1,  today - 1);
return iTime(NULL, PERIOD_D1, iD1); }
ResetLastError(); (void) iOpen(_Symbol,aPeriod,0);
if(_LastError != 0){
if(_LastError != ERR_HISTORY_WILL_UPDATED){ Print(_LastError); return;
Sleep(15000); RefreshRates();
}  }
```
Just typed, Not compiled.
5. Check your return codes (OrderSelect) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
6. Filter by magic number.

 3 huatboyz 2015.03.10 09:11 #   Thanks for all the replies ! Greatly appreciated. I will take a look and let you guys know. Cheers.