ex_Sigal_GS_2010_11_03

Author: Copyright � Sergey Gulyaev. Maykop.
Orders Execution
Checks for the total of open orders
Miscellaneous
It issuies visual alerts to the screenIt plays sound alerts
0 Views
0 Downloads
0 Favorites
ex_Sigal_GS_2010_11_03
//+------------------------------------------------------------------+
//|                                                         ex_Sigal |
//+------------------------------------------------------------------+
#property copyright "Copyright © Sergey Gulyaev. Maykop."

string Name_Expert = "ex_Sigal",
       Ver = "GS_2010_11_03",
       Autor = " ©valenok2003@mail.ru";
//---------------------------
extern bool Alert_ON = true;
extern bool Sound_ON = true;
extern bool Comment_ON = true;
extern int Txt_Location = 2;
int Std_Min_Dist;
int Cnt = 0,
    Order = 0,
    Type_Order,
    All_Orders = 0;
int Arr_Tickets[200][2];
bool FLAG_ON = true,
     LOSS = false,
     PROFIT = false,
     NONE = false,
     CHECK_ORDER = false,
     DIST_INC = true,
     DIST_STD = true,     
     FLAG_ALERT = true;
string Txt_Profit,
       Name_Sound_Profit = "payment.wav",
       Name_Sound_Loss = "ERROR.WAV",
       Name_Sound_Open  = "expert.wav";
color Txt_Dist_Color = DodgerBlue;       
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
{
//----
   CHECK_ORDER = false;
   LOSS = false;
   PROFIT = false;
   NONE = false;
   Cnt = 0;

   All_Orders = OrdersTotal();
   for(Order = OrdersTotal()-1; Order >= 0; Order--) 
   {
      OrderSelect(Order, SELECT_BY_POS, MODE_TRADES);
      if(OrderCloseTime() == 0)
      {
         Type_Order = OrderType();
         if(Type_Order == OP_BUY || Type_Order == OP_SELL ||
            Type_Order == OP_BUYSTOP || Type_Order == OP_SELLSTOP ||
            Type_Order == OP_BUYLIMIT || Type_Order == OP_SELLLIMIT)
         {
            Arr_Tickets[Cnt,0] = OrderTicket();
            Arr_Tickets[Cnt,1] = Type_Order;
            Cnt++;
         }
      }
   }
   Std_Min_Dist = MarketInfo(Symbol(),MODE_STOPLEVEL);
   if(!IsDemo())
   {
      ObjectCreate("Real", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("Real", "Ðåàëüíûé ñ÷¸ò!", 12, "Arial", Yellow);
      ObjectSet("Real", OBJPROP_CORNER, Txt_Location);
      ObjectSet("Real", OBJPROP_XDISTANCE, 20);
      ObjectSet("Real", OBJPROP_YDISTANCE, 35);     
   }
   else
   {
      ObjectCreate("Real", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("Real", "Äåìî ñ÷¸ò!", 12, "Arial", DodgerBlue);
      ObjectSet("Real", OBJPROP_CORNER, Txt_Location);
      ObjectSet("Real", OBJPROP_XDISTANCE, 20);
      ObjectSet("Real", OBJPROP_YDISTANCE, 35);     
   }   
//----
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectDelete("Real"); 
   ObjectDelete("Dist");
   for(int x=0;x<7;x++)
      for(int y=0;y<2;y++)
      {
         ObjectDelete("A_Fon"+x+y);
      }   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
//----
   int Cur_Min_Dist = MarketInfo(Symbol(),MODE_STOPLEVEL);
//--------------------------------------------------------------------
//------ ðèñóåì ïîäëîæêó ---------------------------------------------
   for(int x=0;x<7;x++)
      for(int y=0;y<2;y++)
      {
         ObjectCreate("A_Fon"+x+y,OBJ_LABEL,0,0,0,0,0);
         ObjectSet("A_Fon"+x+y, OBJPROP_CORNER, Txt_Location);
         ObjectSet("A_Fon"+x+y,OBJPROP_XDISTANCE,x*20+5);
         ObjectSet("A_Fon"+x+y,OBJPROP_YDISTANCE,y*20+7);
         ObjectSetText("A_Fon"+x+y,CharToStr(110),26,"Wingdings",Black);//Red);
      }  
//---------------------------      
//------ àëåðò îá èçìåíåíèè äèñòàíöèè --------------------------------
   if(Cur_Min_Dist != Std_Min_Dist && DIST_INC) 
   {
      Txt_Dist_Color = Red;
      if(Alert_ON) Alert("Äèñòàíöèÿ " + Cur_Min_Dist);
      DIST_INC = false;
      DIST_STD = true;
   }
   if(Cur_Min_Dist == Std_Min_Dist && DIST_STD)
   {
      if(Alert_ON) Alert("Äèñòàíöèÿ " + Cur_Min_Dist);
      Txt_Dist_Color = DodgerBlue;
      DIST_INC = true;
      DIST_STD = false;
   }
//--------------------------------------------------------------------
//------ ñîîáùåíèå î äèñòàíöèè ---------------------------------------
   ObjectCreate("Dist", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("Dist", "Äèñòàíöèÿ = " + Cur_Min_Dist, 10, "Arial", Txt_Dist_Color);
   ObjectSet("Dist", OBJPROP_CORNER, Txt_Location);
   ObjectSet("Dist", OBJPROP_XDISTANCE, 20);
   ObjectSet("Dist", OBJPROP_YDISTANCE, 20);     
//--------------------------------------------------------------------
//---------------------------
   for(Order = 0; Order < Cnt; Order++) 
   {
      string Txt_OrderType;
      OrderSelect(Arr_Tickets[Order,0], SELECT_BY_TICKET);
      switch(Arr_Tickets[Order,1])
      {
         case OP_BUY:      Txt_OrderType = "BUY";        break;
         case OP_SELL:     Txt_OrderType = "SELL";       break;
         case OP_BUYSTOP:  Txt_OrderType = "BUYSTOP";    break;
         case OP_SELLSTOP: Txt_OrderType = "SELLSTOP";   break;
         case OP_BUYLIMIT: Txt_OrderType = "BUYLIMIT";   break;
         case OP_SELLLIMIT:Txt_OrderType = "SELLLIMIT";  break;
         default: break;
      }
      if(Arr_Tickets[Order,1] != OrderType())
      {
         if(Alert_ON)Alert("Ñðàáîòàë îòëîæåííûé îðäåð " + Txt_OrderType);
         Sleep(1000);
         if(Sound_ON)PlaySound(Name_Sound_Open);
         CHECK_ORDER = true;
      }
      else if(OrderCloseTime() > 0)
      {
         if(OrderProfit() < 0) {Txt_Profit = " c ÓÁÛÒÊÎÌ!"; LOSS = true;}
         if(OrderProfit() > 0) {Txt_Profit = " c ÏÐÈÁÛËÜÞ!"; PROFIT = true;}
         if(OrderProfit() == 0){Txt_Profit = "!"; NONE = true;}
//---------------------------
         if(Alert_ON)Alert("Îðäåð " + Txt_OrderType + " çàêðûò" + Txt_Profit);
         Sleep(1000);
         if(Sound_ON)
         {
            if(LOSS) PlaySound(Name_Sound_Loss);
            if(PROFIT) PlaySound(Name_Sound_Profit);
         }
         CHECK_ORDER = true;
      }
      if(CHECK_ORDER == true) break;
   }
//---------------------------
   if(OrdersTotal() != All_Orders)
   {
      if(OrdersTotal() > All_Orders)
         if(Sound_ON)PlaySound(Name_Sound_Open);      
      CHECK_ORDER = true;
      All_Orders = OrdersTotal();
   }
//---------------------------
   if(CHECK_ORDER == true)
   {
      init();   
   }
//---------------------------
   if(Comment_ON) Comment("Îðäåðîâ âñåãî " + All_Orders);
//----
   return(0);
}
//+------------------------------------------------------------------+

Comments