Understanding Daily Drawdown Indicator for MetaTrader 5

Mike 2022.11.07 16:26 20 0 0
Attachments

As traders, keeping an eye on our account's performance is essential. In the lower right corner of your MetaTrader 5 platform, you can easily view the profit or loss percentage of your account. This is where the Daily Drawdown (DD) indicator comes into play!


Setting Up the Daily Drawdown Indicator

To get started, let’s explore how to set up the Daily Drawdown indicator using a bit of code. Here’s a simple example:

OnInit():
   CreateEdit("Daily DD", 200, 68, 98, 30, "Daily DD", clrWhite, clrBlack, 12);
   CreateEdit("Daily DD V", 100, 68, 98, 30, "", clrWhite, clrBlack, 12);

In this snippet, we’re creating two editable objects for our Daily DD indicator. It helps to visualize the daily drawdown effectively!

Managing the Indicator

Now, when you want to clean things up, here’s how to remove the indicator:

OnDeinit:
   ObjectDelete(0, "Daily DD");
   ObjectDelete(0, "Daily DD V");

It’s always good practice to remove any indicators that you no longer need to keep your workspace tidy.

Calculating Daily Drawdown

Now, let’s dig into how to calculate your daily drawdown:

OnCalculate:
   MqlDateTime w;
   TimeToStruct(TimeCurrent(), w);
   string md=IntegerToString(w.year) + "." + IntegerToString(w.mon) + ".01";
   double historyProfit=0, deposit=0;
   HistorySelect(0, TimeCurrent());
   ulong ticket_history_deal=0;
   for(int i=0; i     if((ticket_history_deal=HistoryDealGetTicket(i))>0)
       {
         datetime timeeee=(datetime)HistoryDealGetInteger(ticket_history_deal, DEAL_TIME);
         if(timeeee>StringToTime(TimeToString(TimeCurrent(), TIME_DATE)))
          if(HistoryDealGetInteger(ticket_history_deal, DEAL_TYPE)==DEAL_TYPE_BUY || HistoryDealGetInteger(ticket_history_deal, DEAL_TYPE)==DEAL_TYPE_SELL)
             historyProfit+=HistoryDealGetDouble(ticket_history_deal, DEAL_PROFIT) + HistoryDealGetDouble(ticket_history_deal, DEAL_COMMISSION) + HistoryDealGetDouble(ticket_history_deal, DEAL_SWAP);
             else
               deposit+=HistoryDealGetDouble(ticket_history_deal, DEAL_PROFIT);
    }
   double startBalance=AccountInfoDouble(ACCOUNT_BALANCE)-historyProfit;
   string text="";
   double dd=(historyProfit + AccountInfoDouble(ACCOUNT_PROFIT)) * 100 / startBalance;
   text=DoubleToString(dd, 2) + " %";
   ObjectSetString(0, "Daily DD V", OBJPROP_TEXT, text);
   ChartRedraw();

This code calculates your daily drawdown by comparing your account's current profit to your starting balance, giving you a clear picture of your performance.

Conclusion

Incorporating the Daily Drawdown indicator into your trading strategy can provide invaluable insights into your trading performance. It helps you manage risk and stay disciplined. So, why not give it a shot and see how it can enhance your trading experience?

List
Comments 0