Review my Notification EA

 

I just started using MQL5 today on MetaTrader 4.

I use the app exclusively so I have developed a EA which will push notification to my device when an order changes from a profit to a loss or vice versa.

Please let me know what you think, any advice is appreciated!

//+------------------------------------------------------------------+
//|                                                first_advisor.mq4 |
//|                                                   ViridianIsland |
//|                                                   www.google.com |
//+------------------------------------------------------------------+
#property copyright "ViridianIsland"
#property link      "www.google.com"
#property version   "1.00"
#property strict

#define PROFIT      1
#define LOSS        2

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- create timer
   EventSetTimer(10);
   SendNotification("First Advisor Code Running!");
      
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
int Count=0;
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
      
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
  }
  
 bool nofityOnProfitChange(double dHysteresis)   {
   int iIndex;
   int iTotalNumberOfOrders = OrdersTotal();
   string sSymbol;
   string sDifference;
   string sNotification;
  
  
   //generate array of booleans to indicate change in profit
   int bProfitChange[];
   if(ArrayResize(bProfitChange, iTotalNumberOfOrders) == -1)  {
      return false;
   }
   ArrayFill(bProfitChange, 0, iTotalNumberOfOrders, 0);
   
   if(!iTotalNumberOfOrders)  {
      return false;
     }
   double dOpenPrice;
   double dDifference;
   
   for(iIndex = iTotalNumberOfOrders - 1; iIndex >= 0; iIndex--)  {
      if(!OrderSelect(iIndex, SELECT_BY_POS, MODE_TRADES))   {
         Print("OrderSelect for order ", iIndex, " failed error : ", GetLastError());
         continue;
      }
      
      sSymbol = OrderSymbol();
      dOpenPrice = OrderOpenPrice();
      
      //for longs
      if(OrderType() == OP_BUY) {
         //profit for long
         if(dOpenPrice < Ask) {
            dDifference = Ask - dOpenPrice;
            if(bProfitChange[iIndex] == LOSS) {
               //build string for notification
               sDifference = DoubleToStr(dDifference, 5);
               sNotification = StringConcatenate("Change to PROFIT ", sSymbol, " : ", sDifference);
               SendNotification(sNotification);
            }
             bProfitChange[iIndex] = PROFIT;
         }
         //loss for long
         if(dOpenPrice < Ask) {
            dDifference = dOpenPrice - Ask;
            if(bProfitChange[iIndex] == PROFIT) {
               //build string for notification
               sDifference = DoubleToStr(dDifference, 5);
               sNotification = StringConcatenate("Change to LOSS ", sSymbol, " : ", sDifference);
               SendNotification(sNotification);
            }
            bProfitChange[iIndex] = LOSS;
         }
      }
      
      //for shorts
      if(OrderType() == OP_SELL) {
         //profit for short
         if(dOpenPrice > Bid) {
            dDifference = dOpenPrice - Bid;
            if(bProfitChange[iIndex] == LOSS) {
               //build string for notification
               sDifference = DoubleToStr(dDifference, 5);
               sNotification = StringConcatenate("Change to PROFIT ", sSymbol, " : ", sDifference);
               SendNotification(sNotification);
            }
             bProfitChange[iIndex] = PROFIT;
         }
         //loss for short
         if(dOpenPrice < Bid) {
            dDifference = Bid - dOpenPrice;
            if(bProfitChange[iIndex] == PROFIT) {
               //build string for notification
               sDifference = DoubleToStr(dDifference, 5);
               sNotification = StringConcatenate("Change to LOSS ", sSymbol, " : ", sDifference);
               SendNotification(sNotification);
            }
            bProfitChange[iIndex] = LOSS;
         }
      } 
      
      Sleep(6001);
      
           
   }
   return true;
}
  
  
  
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   bool returnValue = nofityOnProfitChange(0);
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---

//---
   return(ret);
  }
//+------------------------------------------------------------------+

Reason: