daily drawdown – indicator MetaTrader 5

In the lower right corner of the page, you can see the profit or loss percentage of your account.

OnInit():

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

OnDeinit:

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

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<HistoryDealsTotal(); 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 startBalnce=AccountInfoDouble(ACCOUNT_BALANCE)-historyProfit;
   string text="";
   double dd=(historyProfit+AccountInfoDouble(ACCOUNT_PROFIT))*100/startBalnce;
   text=DoubleToString(dd,2)+" %";
   ObjectSetString(0,"Daily DD V",OBJPROP_TEXT,text);
   ChartRedraw();

📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks