-
Notifications
You must be signed in to change notification settings - Fork 0
/
ddmonitor.mq4
36 lines (33 loc) · 1.49 KB
/
ddmonitor.mq4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//+------------------------------------------------------------------+
//| ddmonitor.mq4 |
//| Umarzuki Mochlis |
//| |
//+------------------------------------------------------------------+
#property copyright "Umarzuki Mochlis"
#property link ""
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
double accbal;
//set to 5 percent as per MyForexFunds rule
double DDPercent = 0.05;
accbal=AccountBalance();
double DailyDD=accbal*DDPercent;
//calculations for today profit grabbed from https://www.mql5.com/en/forum/151587
double todayprofit=0;
datetime Openday= iTime(Symbol(),PERIOD_D1,0);
for(int xx=OrdersHistoryTotal()-1;xx>=0;xx--)
{ if(!OrderSelect(xx,SELECT_BY_POS,MODE_HISTORY))continue;
if(OrderCloseTime()<Openday)break;
if(OrderType()<2)todayprofit+=OrderProfit()+OrderSwap()+OrderCommission();
}
double todaybal=accbal-todayprofit;
double TodayMaxDailyDD=todaybal*DDPercent;
Comment("Max Daily DD ",DoubleToStr(TodayMaxDailyDD,2));
}
//+------------------------------------------------------------------+