Sound Alert Entry In Out

Author: Copyright © 2017-2021, Vladimir Karputov
Miscellaneous
It plays sound alerts
0 Views
0 Downloads
0 Favorites
Sound Alert Entry In Out
ÿþ//+------------------------------------------------------------------+

//|                                     Sound Alert Entry In Out.mq5 |

//|                         Copyright © 2017-2021, Vladimir Karputov |

//|                     https://www.mql5.com/ru/market/product/43516 |

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

#property copyright "Copyright © 2017-2021, Vladimir Karputov"

#property link      "https://www.mql5.com/ru/market/product/43516"

#property version   "1.002"

//---

enum ENUM_SOUNDS

  {

   alert       = 0,  // alert

   alert2      = 1,  // alert2

   connect     = 2,  // connect

   disconnect  = 3,  // disconnect

   email       = 4,  // email

   expert      = 5,  // expert

   news        = 6,  // news

   ok          = 7,  // ok

   request     = 8,  // request

   stops       = 9,  // stops

   tick        = 10, // tick

   timeout     = 11, // timeout

   wait        = 12, // wait

  };

//--- input parameters

input ENUM_SOUNDS    InpSoundIN        = alert2;   // Sound if Entry in

input ENUM_SOUNDS    InpSoundOUT       = alert2;   // Sound if Entry out

input bool           InpNotification   = false;    // Use Notification

input bool           InpIamlive        = true;     // I am live (each hour)

//---

string   m_filename_in="";

string   m_filename_out="";

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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   switch(InpSoundIN)

     {

      case 0:

         m_filename_in="alert.wav";

         break;

      case 1:

         m_filename_in="alert2.wav";

         break;

      case 2:

         m_filename_in="connect.wav";

         break;

      case 3:

         m_filename_in="disconnect.wav";

         break;

      case 4:

         m_filename_in="email.wav";

         break;

      case 5:

         m_filename_in="expert.wav";

         break;

      case 6:

         m_filename_in="news.wav";

         break;

      case 7:

         m_filename_in="ok.wav";

         break;

      case 8:

         m_filename_in="request.wav";

         break;

      case 9:

         m_filename_in="stops.wav";

         break;

      case 10:

         m_filename_in="tick.wav";

         break;

      case 11:

         m_filename_in="timeout.wav";

         break;

      case 12:

         m_filename_in="wait.wav";

         break;

     }

   Print("Start Test IN PlaySound(",m_filename_in,")");

   PlaySound(m_filename_in);

   Print("End Test IN PlaySound(",m_filename_in,")");

//---

   Sleep(2000);

   switch(InpSoundOUT)

     {

      case 0:

         m_filename_out="alert.wav";

         break;

      case 1:

         m_filename_out="alert2.wav";

         break;

      case 2:

         m_filename_out="connect.wav";

         break;

      case 3:

         m_filename_out="disconnect.wav";

         break;

      case 4:

         m_filename_out="email.wav";

         break;

      case 5:

         m_filename_out="expert.wav";

         break;

      case 6:

         m_filename_out="news.wav";

         break;

      case 7:

         m_filename_out="ok.wav";

         break;

      case 8:

         m_filename_out="request.wav";

         break;

      case 9:

         m_filename_out="stops.wav";

         break;

      case 10:

         m_filename_out="tick.wav";

         break;

      case 11:

         m_filename_out="timeout.wav";

         break;

      case 12:

         m_filename_out="wait.wav";

         break;

     }

   Print("Start Test !IN PlaySound(",m_filename_out,")");

   PlaySound(m_filename_out);

   Print("End Test IN !PlaySound(",m_filename_out,")");

//---

   if(InpIamlive)

     {

      //--- create timer

      ResetLastError();

      if(!EventSetTimer(60*60))

        {

         string text="EventSetTimer Error# "+IntegerToString(GetLastError());

         if(InpNotification)

            SendNotification(text);

         Print(text);

        }

     }

//---

   if(InpNotification)

     {

      string text="INIT_SUCCEEDED";

      SendNotification(text);

     }

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   if(InpNotification)

     {

      string text="";

      switch(reason)

        {

         case  REASON_PROGRAM:

            text="REASON_PROGRAM";

            break;

         case  REASON_REMOVE:

            text="REASON_REMOVE";

            break;

         case  REASON_RECOMPILE:

            text="REASON_RECOMPILE";

            break;

         case  REASON_CHARTCHANGE:

            text="REASON_CHARTCHANGE";

            break;

         case  REASON_CHARTCLOSE:

            text="REASON_CHARTCLOSE";

            break;

         case  REASON_PARAMETERS:

            text="REASON_PARAMETERS";

            break;

         case  REASON_ACCOUNT:

            text="REASON_ACCOUNT";

            break;

         case  REASON_TEMPLATE:

            text="REASON_TEMPLATE";

            break;

         case  REASON_INITFAILED:

            text="REASON_INITFAILED";

            break;

         case  REASON_CLOSE:

            text="REASON_CLOSE";

            break;

         default:

            text="NON REASON";

            break;

        }

      SendNotification(text);

     }

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---

  }

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

//| Timer function                                                   |

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

void OnTimer()

  {

//---

   if(InpNotification)

     {

      string text=TimeToString(TimeCurrent())+": I am live";

      SendNotification(text);

     }

  }

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

//| TradeTransaction function                                        |

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

void OnTradeTransaction(const MqlTradeTransaction &trans,

                        const MqlTradeRequest &request,

                        const MqlTradeResult &result)

  {

//--- get transaction type as enumeration value

   ENUM_TRADE_TRANSACTION_TYPE type=trans.type;

//--- if transaction is result of addition of the transaction in history

   if(type==TRADE_TRANSACTION_DEAL_ADD)

     {

      long     deal_type=0;

      long     deal_entry=0;

      double   deal_volume=0.0;

      double   deal_commission=0.0;

      double   deal_swap=0.0;

      double   deal_profit=0.0;

      string   deal_symbol="NON";

      if(HistoryDealSelect(trans.deal))

        {

         deal_type      = HistoryDealGetInteger(trans.deal,DEAL_TYPE);

         deal_entry     = HistoryDealGetInteger(trans.deal,DEAL_ENTRY);

         deal_volume    = HistoryDealGetDouble(trans.deal,DEAL_VOLUME);

         deal_commission= HistoryDealGetDouble(trans.deal,DEAL_COMMISSION);

         deal_swap      = HistoryDealGetDouble(trans.deal,DEAL_SWAP);

         deal_profit    = HistoryDealGetDouble(trans.deal,DEAL_PROFIT);

         deal_symbol    = HistoryDealGetString(trans.deal,DEAL_SYMBOL);

        }

      else

        {

         Print("ERROR HistoryDealSelect");

         return;

        }

      //---

      if(deal_entry==DEAL_ENTRY_IN)

        {

         if(InpNotification)

           {

            string text="IN: deal #"+IntegerToString(trans.deal);

            string str_type="NON";

            if(deal_type==DEAL_TYPE_BUY)

               str_type=" buy ";

            else

               if(deal_type==DEAL_TYPE_SELL)

                  str_type=" sell ";

            text=text+str_type+DoubleToString(deal_volume,2)+" "+deal_symbol+

                 ", commission: "+DoubleToString(deal_commission,2)+

                 ", swap: "+DoubleToString(deal_swap,2);

            SendNotification(text);

           }

        }

      if(deal_entry!=DEAL_ENTRY_IN)

        {

         if(InpNotification)

           {

            string text="OUT: deal #"+IntegerToString(trans.deal);

            string str_type="NON";

            if(deal_type==DEAL_TYPE_BUY)

               str_type=" buy ";

            else

               if(deal_type==DEAL_TYPE_SELL)

                  str_type=" sell ";

            text=text+str_type+DoubleToString(deal_volume,2)+" "+deal_symbol+

                 ", commission: "+DoubleToString(deal_commission,2)+

                 ", swap: "+DoubleToString(deal_swap,2)+

                 ", profit: "+DoubleToString(deal_profit,2)+" "+AccountInfoString(ACCOUNT_CURRENCY);

            SendNotification(text);

           }

        }

     }

  }

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

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---