Daily profit indicator (filter or specify a pair)

 

I found a mq4 script on the forum (iprofit) that reads the account history, and shows me a total daily profit in currency and percentage.

I'm currently trading Gold and Silver and i would like to filter/specify gold or silver in my script.

I'm currently on the level of a script kiddie where i mostly just change values and just see what happens :)

So if anyone could guide me to the right direction or have some tips that would be much appreciated.

//+------------------------------------------------------------------+
//|                                        Total Profit MF666 V1.mq4 |
//|                      Copyright © 2022, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2022, MartyMcfry666"
#property link      "https://shattereddisk.github.io/rickroll/rickroll.mp4"
#property indicator_chart_window
//+--------------------------------------------------------------------------+
//|                             Outside                                      |
//+--------------------------------------------------------------------------+
  extern int   eiPercent = 5;           // Calculation of percentage of profit on:
                                        //  0 - current balance
                                        //  1 - balance at the beginning of the day
                                        //  2 - balance at the beginning of the week
                                        //  3 - balance at the beginning of the month
                                        //  4 - balance at beginning of the quarter
                                        //  5 - balance at beginning of year
//+--------------------------------------------------------------------------+
//|                         Options positions                                |
//+--------------------------------------------------------------------------+
  extern int   eiOffsetY = 25;          // (Y) Offset text vertically
  extern int   eiStepY   = 14;          // (Y) Step displacements of the text vertically
  extern int   eiX1Row   = 180;         // (X) Coordinate of the first column
  extern int   eiX2Row   = 130;         // (X) Coordinate of the second column
  extern int   eiX3Row   = 65;          // (X) Coordinate third column
  extern int   eiX4Row   = 3;           // (X) Coordinate of the fourth column
//+--------------------------------------------------------------------------+
//|                          Color Settings                                  |
//+--------------------------------------------------------------------------+
  extern color ecText    = Orange;      // Text Color
  extern color ecProfit  = Lime;        // Color profit
  extern color ecLoss    = FireBrick;   // Color loss
  extern color warning   = DimGray;     // Warning
  extern color white     = White;       // White
//+--------------------------------------------------------------------------+
//| Custom indicator initialization function                                 |
//+--------------------------------------------------------------------------+
  void     init() {
           DeleteObjects();
  Comment  ("Total Profit MF666");    // comment in the upper left corner
  }
//+--------------------------------------------------------------------------+
//| Custom indicator deinitialization function                               |
//+--------------------------------------------------------------------------+
  void     deinit() {
           DeleteObjects();
  Comment  ("Total Profit MF666");    // comment in the upper left corner
  }
//+--------------------------------------------------------------------------+
//| Custom indicator iteration function                                      |
//+--------------------------------------------------------------------------+
  void     start() {
  datetime d0, d1, d2, d3, d4, d5, d6, d7, d8;
//+--------------------------------------------------------------------------+
           d0=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
  while    (TimeDayOfWeek(d0)<1 || TimeDayOfWeek(d0)>5) d0-=24*60*60;
           d1=d0-24*60*60;
  while    (TimeDayOfWeek(d1)<1 || TimeDayOfWeek(d1)>5) d1-=24*60*60;
           d2=d1-24*60*60;
  while    (TimeDayOfWeek(d2)<1 || TimeDayOfWeek(d2)>5) d2-=24*60*60;
           d3=d2-24*60*60;
  while    (TimeDayOfWeek(d3)<1 || TimeDayOfWeek(d3)>5) d3-=24*60*60;
           d4=d3-24*60*60;
  while    (TimeDayOfWeek(d4)<1 || TimeDayOfWeek(d4)>5) d4-=24*60*60;
           d5=DateOfMonday();
           d6=StrToTime(Year()+"."+Month()+".01");
           d7=DateBeginQuarter();
           d8=StrToTime(Year()+".01.01");
//+--------------------------------------------------------------------------+
  double   tb=AccountBalance(),           tp=AccountProfit();
  double   p0=GetProfitFromDateInCurrency ("", -1, -1, d0);
  double   p1=GetProfitFromDateInCurrency ("", -1, -1, d1)-p0;
  double   p2=GetProfitFromDateInCurrency ("", -1, -1, d2)-p1-p0;
  double   p3=GetProfitFromDateInCurrency ("", -1, -1, d3)-p2-p1-p0;
  double   p4=GetProfitFromDateInCurrency ("", -1, -1, d4)-p3-p2-p1-p0;
  double   p5=GetProfitFromDateInCurrency ("", -1, -1, d5);
  double   p6=GetProfitFromDateInCurrency ("", -1, -1, d6);
  double   p7=GetProfitFromDateInCurrency ("", -1, -1, d7);
  double   p8=GetProfitFromDateInCurrency ("", -1, -1, d8);
//+--------------------------------------------------------------------------+
  string               st;
  switch                                  (eiPercent) {
    case 0 :           st="current";                         break;
    case 1 : tb-=p0;   st="at the beginning of the day";     break;
    case 2 : tb-=p5;   st="at the beginning of the week";    break;
    case 3 : tb-=p6;   st="at the beginning of the month";   break;
    case 4 : tb-=p7;   st="at the beginning of the quarter"; break;
    default: tb-=p8;   st="at beginning of year";            break;
  }
  double     tr=tp*100/tb;
  double     r0=p0*100/tb;
  double     r1=p1*100/tb;
  double     r2=p2*100/tb;
  double     r3=p3*100/tb;
  double     r4=p4*100/tb;
  double     r5=p5*100/tb;
  double     r6=p6*100/tb;
  double     r7=p7*100/tb;
  double     r8=p8*100/tb;
//+--------------------------------------------------------------------------+
//|                                   HEADERS                                |
//+--------------------------------------------------------------------------+
  SetLabel ("Profit05", "DATUM",                           ecText, eiX1Row-25,eiOffsetY);
  SetLabel ("Profit07", "PROFIT €",                        ecText, eiX3Row-2, eiOffsetY);
  SetLabel ("Profit08", "%%  %",                           ecText, eiX3Row-60,eiOffsetY);
//+--------------------------------------------------------------------------+
//|                                  separator                               |
//+--------------------------------------------------------------------------+
  SetLabel ("Profit09", "===============================",ecText, eiX4Row-1,eiOffsetY+1*eiStepY);
//+--------------------------------------------------------------------------+
//|                                   position                               |
//+--------------------------------------------------------------------------+
  SetLabel ("Profit11", "huidig",                          ecText, eiX1Row-25,   eiOffsetY+2*eiStepY);
  SetLabel ("Profit21", "vandaag",                         ecText, eiX1Row-25,   eiOffsetY+3*eiStepY);
  SetLabel ("Profit31", ""+TimeToStr(d1, TIME_DATE),       ecText, eiX1Row-25,   eiOffsetY+4*eiStepY);
  SetLabel ("Profit41", ""+TimeToStr(d2, TIME_DATE),       ecText, eiX1Row-25,   eiOffsetY+5*eiStepY);
  SetLabel ("Profit51", ""+TimeToStr(d3, TIME_DATE),       ecText, eiX1Row-25,   eiOffsetY+6*eiStepY);
  SetLabel ("Profit61", ""+TimeToStr(d4, TIME_DATE),       ecText, eiX1Row-25,   eiOffsetY+7*eiStepY);
  SetLabel ("Profit71", "week",                            ecText, eiX1Row-25,   eiOffsetY+8*eiStepY);
  SetLabel ("Profit81", "maand",                           ecText, eiX1Row-25,   eiOffsetY+9*eiStepY);
  SetLabel ("Profit91", "kwartaal",                        ecText, eiX1Row-25,   eiOffsetY+10*eiStepY);
  SetLabel ("Profit01", "jaar",                            ecText, eiX1Row-25,   eiOffsetY+11*eiStepY);
//+--------------------------------------------------------------------------+
//|                                      MONEY                               |
//+--------------------------------------------------------------------------+
  SetLabel ("Profit13", DoubleToStr (tp, 2),      ColorOnSign(tp), eiX3Row,   eiOffsetY+2*eiStepY);
  SetLabel ("Profit23", DoubleToStr (p0, 2),      ColorOnSign(p0), eiX3Row,   eiOffsetY+3*eiStepY);
  SetLabel ("Profit33", DoubleToStr (p1, 2),      ColorOnSign(p1), eiX3Row,   eiOffsetY+4*eiStepY);
  SetLabel ("Profit43", DoubleToStr (p2, 2),      ColorOnSign(p2), eiX3Row,   eiOffsetY+5*eiStepY);
  SetLabel ("Profit53", DoubleToStr (p3, 2),      ColorOnSign(p3), eiX3Row,   eiOffsetY+6*eiStepY);
  SetLabel ("Profit63", DoubleToStr (p4, 2),      ColorOnSign(p4), eiX3Row,   eiOffsetY+7*eiStepY);
  SetLabel ("Profit73", DoubleToStr (p5, 2),      ColorOnSign(p5), eiX3Row,   eiOffsetY+8*eiStepY);
  SetLabel ("Profit83", DoubleToStr (p6, 2),      ColorOnSign(p6), eiX3Row,   eiOffsetY+9*eiStepY);
  SetLabel ("Profit93", DoubleToStr (p7, 2),      ColorOnSign(p7), eiX3Row,   eiOffsetY+10*eiStepY);
  SetLabel ("Profit03", DoubleToStr (p8, 2),      ColorOnSign(p8), eiX3Row,   eiOffsetY+11*eiStepY);
//+--------------------------------------------------------------------------+
//|                                     INTEREST                             |
//+--------------------------------------------------------------------------+
  SetLabel ("Profit14", DoubleToStr (tr, 2)+"  %", ColorOnSign(tr), eiX4Row,   eiOffsetY+2*eiStepY);
  SetLabel ("Profit24", DoubleToStr (r0, 2)+"  %", ColorOnSign(r0), eiX4Row,   eiOffsetY+3*eiStepY);
  SetLabel ("Profit34", DoubleToStr (r1, 2)+"  %", ColorOnSign(r1), eiX4Row,   eiOffsetY+4*eiStepY);
  SetLabel ("Profit44", DoubleToStr (r2, 2)+"  %", ColorOnSign(r2), eiX4Row,   eiOffsetY+5*eiStepY);
  SetLabel ("Profit54", DoubleToStr (r3, 2)+"  %", ColorOnSign(r3), eiX4Row,   eiOffsetY+6*eiStepY);
  SetLabel ("Profit64", DoubleToStr (r4, 2)+"  %", ColorOnSign(r4), eiX4Row,   eiOffsetY+7*eiStepY);
  SetLabel ("Profit74", DoubleToStr (r5, 2)+"  %", ColorOnSign(r5), eiX4Row,   eiOffsetY+8*eiStepY);
  SetLabel ("Profit84", DoubleToStr (r6, 2)+"  %", ColorOnSign(r6), eiX4Row,   eiOffsetY+9*eiStepY);
  SetLabel ("Profit94", DoubleToStr (r7, 2)+"  %", ColorOnSign(r7), eiX4Row,   eiOffsetY+10*eiStepY);
  SetLabel ("Profit04", DoubleToStr (r8, 2)+"  %", ColorOnSign(r8), eiX4Row,   eiOffsetY+11*eiStepY);
//+--------------------------------------------------------------------------+
//|                                  separator                               |
//+--------------------------------------------------------------------------+
  SetLabel ("Profit15",  "===============================",ecText, eiX4Row-1,eiOffsetY+12*eiStepY);
  SetLabel ("Profit99",  "De indicator leest de ingestelde",warning, eiX4Row-1,eiOffsetY+13*eiStepY);
  SetLabel ("Profit100", "tijdsperiode op de account history",warning, eiX4Row+1,eiOffsetY+14*eiStepY);
  SetLabel ("Profit101", "DUBBELCHECKEN!!!",warning, eiX4Row+1,eiOffsetY+15*eiStepY);

  }
//+--------------------------------------------------------------------------+
  color    ColorOnSign(double nu) {
  color    lcColor=white;
  if       (nu>0) lcColor=ecProfit;
  if       (nu<0) lcColor=ecLoss;
  return   (lcColor);
  }
//+--------------------------------------------------------------------------+
  datetime DateBeginQuarter(int nk=0) {
  int      ye=Year()-MathFloor(nk/4);
           nk=MathMod(nk, 4);
  int      mo=Month()-MathMod(Month()+2, 3)+3*nk;
  if       (mo<1) {
           mo+=12;
           ye--; }
  if       (mo>12) {
           mo-=12;
           ye++; }
  return   (StrToTime(ye+"."+mo+".01"));
  }
//+--------------------------------------------------------------------------+
  datetime DateOfMonday(int no=0) {
  datetime dt=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE));
  while    (TimeDayOfWeek(dt)!=1) dt-=24*60*60;
           dt+=no*7*24*60*60;
  return   (dt);
  }
//+--------------------------------------------------------------------------+
  void     DeleteObjects() {
  for(int i=ObjectsTotal()-1; i>-1; i--)
   if (StringFind(ObjectName(i),"Profit")>=0)  ObjectDelete(ObjectName(i));  
 }
//+--------------------------------------------------------------------------+
  double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dt=0)
  {
  double p=0;
  int    i, k=OrdersHistoryTotal();
  if     (sy=="0") sy=Symbol();
  for    (i=0; i<k; i++) {
  if     (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
  if     ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
  if     (OrderType()==OP_BUY || OrderType()==OP_SELL) {
  if     (mn<0 || OrderMagicNumber()==mn) {
  if     (dt<OrderCloseTime()) {
         p+=OrderProfit()+OrderCommission()+OrderSwap();
  } } } } } }
  return (p);
  }
//+--------------------------------------------------------------------------+

//+--------------------------------------------------------------------------+
//| cr - room corner bindings - (0 - upper left)                             |
//| fs - font size - (9 - default)                                           |
//+--------------------------------------------------------------------------+
  void SetLabel(string nm, string tx, color cl, int xd, int yd, int cr=1, int fs=9)
  {
  if           (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_LABEL, 0, 0,0);
  ObjectSetText(nm, tx, fs);
  ObjectSet    (nm, OBJPROP_COLOR    , cl);
  ObjectSet    (nm, OBJPROP_XDISTANCE, xd);
  ObjectSet    (nm, OBJPROP_YDISTANCE, yd);
  ObjectSet    (nm, OBJPROP_CORNER   , cr);
  ObjectSet    (nm, OBJPROP_FONTSIZE , fs);
  }
//+--------------------------------------------------------------------------+


  
int DecPts() {

 if (Digits==3 || Digits==5) 
    return(1); 
  else if (Digits==2 || Digits==4) 
    return(0); 
  else
    return(0);            
} // end funcion()