eSignalForEvents20191227

Orders Execution
Checks for the total of open ordersChecks for the total of closed orders
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
eSignalForEvents20191227
ÿþ//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

#define     NAME        "eSignalForEvents"

#define     RELIZ       "20191227"

#property   copyright   "Copyright 2019,SergeyGulyaev"

#property   link        "https://www.mql5.com"

#property   script_show_inputs

#property   strict

//---

int lines_all = 0;              // :>;8G5AB2> ;8=89 =0 3@0D8:5

int num_market_orders = 0;

int num_pending_orders = 0;

int num_profit_and_loss_lines = 0;

int previos_num_market_orders = 0;

int previos_num_pending_orders = 0;

int previos_num_profit_and_loss_lines = 0;





//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

   EventSetTimer(1);

   lines_all = CountLines();

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//+--

//+--

//+------------------------------------------------------------------+

//| Expert deinitialization function                                 |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

  {

   Comment("");

   EventKillTimer();

  }

//+------------------------------------------------------------------+

//+--

//---

void OnTick()

  {

   

  }

//---

//+--

//+------------------------------------------------------------------+

//| Expert tick function                                             |

//+------------------------------------------------------------------+

void OnTimer()

  {

//---

   Comment(NAME,RELIZ,"\n",selection_sound(),"\n;8=89 ",lines_all);

//---

   switch(CheckCountLines())

   {

      case 0:

         return;

      break;

      case 1:

         profit_or_loss();

      break;

      case 2:

         PlaySound(selection_sound());

         break;   

   }

//---

  }

//+------------------------------------------------------------------+

//+--

//+--

//+------------------------------------------------------------------+

// 2>72@0I05B :>;8G5AB2> B>@3>2KE ;8=89 4;O @K=>G=KE 8 >B;>65==KE >@45@>2

// =0 3@0D8:5 CG8BK20O ;8=88 TakeProfit 8 StopLoss

//+------------------------------------------------------------------+

int CountLines()

  {

//---

   int _lines=0;

   num_market_orders = 0;

   num_pending_orders = 0;

   num_profit_and_loss_lines = 0;

   int _total;

   _total = OrdersTotal();

   for(int i=0; i<_total; i++)

   {

      if(!OrderSelect(i, SELECT_BY_POS, MODE_TRADES))continue;

      if(OrderType()==OP_BUY||OrderType()==OP_SELL) num_market_orders++;

      if(OrderType()==OP_BUYLIMIT||OrderType()==OP_BUYSTOP||OrderType()==OP_SELLLIMIT||OrderType()==OP_SELLSTOP) num_pending_orders++;

      if(OrderStopLoss()!=0) num_profit_and_loss_lines++;

      if(OrderTakeProfit()!=0) num_profit_and_loss_lines++;

    }

      _lines=num_market_orders+num_pending_orders+num_profit_and_loss_lines;

//---

   return(_lines);

  }

//+------------------------------------------------------------------+

//+--

//+--

//+------------------------------------------------------------------+

int CheckCountLines()

//+------------------------------------------------------------------+

//5A;8 :>;8G5AB2> B>@3>2KE ;8=89 87<5=8;>AL - true, 8=0G5 - false;

//+------------------------------------------------------------------+

  {

//---

   if(CountLines() == lines_all) return(0);

   else

   {  

      if(num_market_orders < previos_num_market_orders)

      {  

         previos_num_market_orders = num_market_orders;

         previos_num_pending_orders = num_pending_orders;

         previos_num_profit_and_loss_lines = num_profit_and_loss_lines;

         lines_all = CountLines();

         return(1);

      }

      if( previos_num_pending_orders != num_pending_orders

        ||previos_num_profit_and_loss_lines != num_profit_and_loss_lines

        ||num_market_orders > previos_num_market_orders

        ) 

      {  

         previos_num_market_orders = num_market_orders;

         previos_num_pending_orders = num_pending_orders;

         previos_num_profit_and_loss_lines = num_profit_and_loss_lines;

         lines_all = CountLines();

         return(2);

      }

   }

   return(0);

//---

  }

//+------------------------------------------------------------------+

//+--

//+--

//+------------------------------------------------------------------+

void profit_or_loss()

  {

   datetime time_close=0;

   int ticket=0;



   for(int i=0; i<OrdersHistoryTotal(); i++)

   {

      if(OrderSelect(i,SELECT_BY_POS, MODE_HISTORY))

      {

         if(OrderCloseTime()>0)

         {

            if(i==0)

            {

               time_close = OrderCloseTime();

               ticket = OrderTicket();

            }

            else

            {

               if(OrderCloseTime()> time_close)

               {

                  time_close = OrderCloseTime();

                  ticket = OrderTicket();

               }

            }

         }

      }

   }

   if(OrderSelect(ticket,SELECT_BY_TICKET))

   {

      if(OrderProfit()>0)PlaySound("profit.wav");

      if(OrderProfit()<0)PlaySound("sliv.wav");

      if(OrderProfit()==0)PlaySound(selection_sound());

   }

   return;

  }

//+------------------------------------------------------------------+

//+--

//---

//+------------------------------------------------------------------+

//--- sounds---

enum sounds

  {

   a,    // "8:

   b,    // 8=L

   c,    // !8@5=0

   d,    // -:A?5@B

   e,    // 0?;O

   f,    // !;82

   h,    // @>D8B

   i,    // >AA

   k,    // $0=D0@K

   l     // 5B

  };

//--- input parameters

input sounds NumSound = k;

string selection_sound()

  {

   switch(NumSound)

     {

      case 0:

         return("tick.wav");

      case 1:

         return("din.wav");

      case 2:

         return("siren.wav");

      case 3:

         return("expert.wav");

      case 4:

         return("drop.wav");

      case 5:

         return("sliv.wav");

      case 6:

         return("profit.wav");

      case 7:

         return("loss.wav");

      case 8:

         return("fanfari ta-dam.wav");

      case 9:

         return("");

      default:

         return("din.wav");

     }

  }

//+------------------------------------------------------------------+

//---

Comments