AlertCloseOpenOrder

Orders Execution
Checks for the total of open ordersChecks for the total of closed orders
Miscellaneous
It issuies visual alerts to the screenIt sends emails
0 Views
0 Downloads
0 Favorites
AlertCloseOpenOrder
//+------------------------------------------------------------------+
//|                                                   AlertOrder.mq4 |
//|                               Copyright © 2011, Vladimir Hlystov |
//|                                                cmillion@narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, http://cmillion.narod.ru"
#property link      "cmillion@narod.ru"
#property indicator_chart_window
extern bool MailSend    = true;//îòïðàâëÿòü íà ïî÷òó
int Orders;
//+------------------------------------------------------------------+
int init()
  {
   Orders=OrdersTotal();
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int O=OrdersTotal();
   string txt;
   if (Orders!=O) 
   {
      if (Orders>O) txt = HistoryOrder();
      if (Orders<O) txt = Order();
      Alert(txt);
      if (MailSend) SendMail("Òîðãîâûé ñ÷åò "+AccountNumber(),txt);
   }
   Orders=O;
   return(0);
  }
//+------------------------------------------------------------------+
string HistoryOrder()
{
   string txt,txt1;
   double OCP;
   int tip;
   int i=OrdersHistoryTotal()-1;
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
   {                                     
      tip=OrderType();
      OCP=OrderClosePrice();
      if (OCP==OrderStopLoss()  ) txt1="SL";
      if (OCP==OrderTakeProfit()) txt1="TP";
      if (tip==OP_BUY) txt="BUY";
      if (tip==OP_SELL) txt="SELL";
      if (tip==OP_BUYSTOP) txt="BUYSTOP";
      if (tip==OP_SELLSTOP) txt="SELLSTOP";
      if (tip==OP_BUYLIMIT) txt="BUYLIMIT";
      if (tip==OP_SELLLIMIT) txt="SELLLIMIT";
      txt=StringConcatenate("Çàêðûò îðäåð ",txt,"  ",Symbol(),"  ",OrderTicket()," ïî ",txt1,"  ",
      DoubleToStr(OCP,Digits),"\n ïðèáûëü ",DoubleToStr(OrderProfit()+OrderSwap()+OrderCommission(),2),"    Áàëàíñ = ",DoubleToStr(AccountBalance(),2));
      return(txt);
   }  
}
//+------------------------------------------------------------------+
string Order()
{
   string txt;
   int tip;
   int i=OrdersTotal()-1;
   if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
   {                                     
      tip=OrderType();
      if (tip==OP_BUY) txt="BUY";
      if (tip==OP_SELL) txt="SELL";
      if (tip==OP_BUYSTOP) txt="BUYSTOP";
      if (tip==OP_SELLSTOP) txt="SELLSTOP";
      if (tip==OP_BUYLIMIT) txt="BUYLIMIT";
      if (tip==OP_SELLLIMIT) txt="SELLLIMIT";
      txt=StringConcatenate("Îòêðûò îðäåð ",txt,"  ",Symbol(),"  N ",OrderTicket(),"\nïî öåíå ",
      DoubleToStr(OrderOpenPrice(),Digits)," ëîò ",DoubleToStr(OrderLots(),2)," SL = ",DoubleToStr(OrderStopLoss(),2)," TP = ",DoubleToStr(OrderTakeProfit(),2));
      return(txt);
   }  
}
//+------------------------------------------------------------------+

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 ---