Please help to modify Target Reached

 

hi master..
could you please help me to solve my code...

i am new learn about mql4 coding...
and i had some trouble, i cant solve my EA.
i want my ea stop work in that day if condition are meet... ex. by profit or loss...in money or percent...
please kindly solve my code...and adding comment in the code...so i can learn...
very thank you...


//+------------------------------------------------------------------+
//|                                                TargetReached.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//--------------
enum ProfitMode
  {
   ModeMoney,   //  Mode Money
   ModePercent  //  Mode Percent
  };

extern ProfitMode binModeProfit       = ModePercent;// Target by Money or Percent
extern double     binDailyProfit      = 5;          // Daily Profit 
extern double     binDailyLoss        = 30;         // Daily Loss
extern int        binMagic            = 123456;     // Magic Number
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   if(getTargetReached()==false)
     {
      //DoTrading();
     }
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//|                                        Do Target Reached ::>>    |
//+------------------------------------------------------------------+
bool getTargetReached()
  {
   double getDailyP= NormalizeDouble(getProfits()+getDailyPnL(),2);
   if(binModeProfit==ModeMoney)
     {
      if(getDailyP>binDailyProfit)
        {
         //getCloseTrades();
         return(true);
        }
      //---
      if(getDailyP<binDailyLoss*-1)
        {
         //getCloseTrades();
         return(true);
        }
      else
        {
         return(false);
        }
     }
// -----------------
   if(binModeProfit==ModePercent)
     {
      double getPercentPnL=((getDailyP/AccountBalance())*100)+getDrawDown();
      if(getPercentPnL>binDailyProfit)
        {
         //getCloseTrades();
         return(true);
        }
      //---
      if(getPercentPnL<binDailyLoss*-1)
        {
         //getCloseTrades();
         return(true);
        }
      else
        {
         return(false);
        }
     }
   return(true);
  }
//--------------------------------------------------------------------
double getDailyPnL()
  {
   double _dailyPnL=0;
   for(int iPos=OrdersHistoryTotal()-1; iPos>=0; iPos--)
      if(TimeDay(OrderCloseTime())==TimeDay(TimeCurrent())
         && TimeMonth(OrderCloseTime())==TimeMonth(TimeCurrent())
         && TimeYear(OrderCloseTime())==TimeYear(TimeCurrent()))
        {
         if(OrderSelect(iPos,SELECT_BY_POS,MODE_HISTORY) && OrderSymbol()==Symbol())
            _dailyPnL+=OrderProfit()+OrderSwap()+OrderCommission();
        }
   return (_dailyPnL);
  }
//--- End of Do Target Reached

//--- 
double getDrawDown()
  {
   double bdDrawDown=0.0;
   double bdEquity=AccountBalance()+AccountProfit();
   double bdBalance=AccountBalance();
   double bdCountDrawDown=NormalizeDouble((bdEquity/bdBalance)*100,3);
   for(int x=OrdersTotal()-1; x>=0; x--)
     {
      bool SelectTicket=OrderSelect(x,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()!=Symbol() && OrderMagicNumber()!=binMagic) continue;
      //Alert("DrawDown "+binMagic);
      bdDrawDown=NormalizeDouble(bdCountDrawDown-100,3);
     }
   return(bdDrawDown);
  }
//---
double getProfits()
  {
   double PofitnLoss=0;
   for(int iPos=OrdersTotal()-1; iPos>=0; iPos--)
      if(OrderSelect(iPos,SELECT_BY_POS) && OrderSymbol()==Symbol())
         PofitnLoss+=OrderProfit()+OrderSwap()+OrderCommission();
   return (PofitnLoss);
  }
//+------------------------------------------------------------------+
Files:
 
Queensha GD:

hi master..
could you please help me to solve my code...

i am new learn about mql4 coding...
and i had some trouble, i cant solve my EA.
i want my ea stop work in that day if condition are meet... ex. by profit or loss...in money or percent...
please kindly solve my code...and adding comment in the code...so i can learn...
very thank you...


push up...