

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(); } 



Hi All MQL experts,
I have been trying to code an Martingale EA based on past history P&L, however, my programming skills is just not up to mark, I am lacking an auto computation algorithm for the past few days, on a daily basis. It's difficult to segregate/differentiate orders and then calculate p&l based on each trading day, because I could have 3 trade losses on one day and 5 trade losses on another day, (especially month end differentiation would be another problem).
Basically the idea is this, if the past trading day is a loss, I would need to double up on my lots on the next trading day, if the previous 2 days was losses, means I would need to double up twice, so on and so forth. If the third day is a win, we would revert back to original lots.
How to calculate P&L for each trading day? Because I attached my EA for 12 pairs, I could have maximum 12 trades a day, I would need to calculate P&L for each trading day, for e.g. my total losses (1 loss on AUDUSD and 1 loss on NZDUSD) would be both added up together for ONE trading day.
I have managed to program for last 5 trades (based on trade open date) for previous trading day and if losses occur, we will double up, if profit, we will stick to the original lots.
Would really appreciate if anyone could help me out. Please and God bless you.
I know using "FOR" loops would be useful, however, I tried, and it doesn't seem to call out the correct values. I am ignoring open trades though, so don't have to calculate p&l for open trades, just closed out trades.
My code are as below:
double lotsize;
double lots = 0.1;
int total1; int cnt1; int tradedate [5];
double profit[5];
total1 = OrdersHistoryTotal ();
OrderSelect(total11, SELECT_BY_POS, MODE_HISTORY);
{tradedate [0] = TimeDay(OrderOpenTime());
profit [0] = OrderProfit ();}
OrderSelect(total12, SELECT_BY_POS, MODE_HISTORY);
{tradedate [1] = TimeDay(OrderOpenTime());
profit [1] = OrderProfit ();}
OrderSelect(total13, SELECT_BY_POS, MODE_HISTORY);
{tradedate [2] = TimeDay(OrderOpenTime());
profit [2] = OrderProfit ();}
OrderSelect(total14, SELECT_BY_POS, MODE_HISTORY);
{tradedate [3] = TimeDay(OrderOpenTime());
profit [3] = OrderProfit ();}
OrderSelect(total15, SELECT_BY_POS, MODE_HISTORY);
{tradedate [4] = TimeDay(OrderOpenTime());
profit [4] = OrderProfit ();}
/* Check PNL for prev day */
double pnl;
if (tradedate[0] == tradedate[1])
pnl = profit[0] + profit[1];
if (tradedate[0] == tradedate[2])
pnl = pnl + profit[2];
if (tradedate[0] == tradedate[3])
pnl = pnl + profit[3];
if (tradedate[0] == tradedate[4])
pnl = pnl + profit[4];
if (pnl < 0);
loss = true;
if (loss = true) lots = lots *2;