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
SCO
ÿþ//+------------------------------------------------------------------+

//|                                                   AlertOrder.mq4 |

//|                               Copyright © 2011, Vladimir Hlystov |

//|                                                cmillion@narod.ru |

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

#property copyright "Copyright © 2019, http://cmillion.ru"

#property link      "cmillion@narod.ru"

#property strict

#property indicator_chart_window

#property description "=48:0B>@ 2K405B 0;5@B 8 >B?@02;O5B A83=0; =0 ?>GBC ?@8 70:@KB88 8 >B:@KB88 ?>78F88. 7<5=5=88 SL TP, ?@8 >B:@KB88 8 C40;5=88 >B;>65==>3> >@45@0"



//2K1>@ > A>>1I5=8OE ?> 2A5< A45;:0< ;81> B>;L:> ?> ?> B>9 ?0@5 =0 :>B>@>9 AB>8B 8=48:0B>@. 

//A:;NG5=K 4C1;8@>20=85 A>>1I5=89 5A;8 8=48:0B>@ AB>8B =0 >4=>9 8 B>9 65 ?0@5 =5A:>;L:> @07.



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

extern bool AlertON     = true;              

extern bool MailSend    = true;           //>B?@02;OBL =0 ?>GBC

int Ord=0;

int Poz=0;

extern bool AlertOpen   = true;              //?@8 >B:@KB88 ?>78F88

extern bool AlertClose  = true;              //?@8 70:@KB88 ?>78F88

extern bool Alert_SL_TP = true;              //C254><;5=85 > <>48D8:0F88 >@45@0 (S/L & T/P)

extern bool AlertOrder  = true;              //?@8 C40;5=88 >B;>65==>3> >@45@0

extern bool AllSymbol   = true;              //A83=0; ?> 2A5< 8=AB@C<5=B0<

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

double SLo[100];

double TPo[100];

int OTo[100];

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

int OnInit()

  {

   GV_Send=WindowExpertName();

   ArrayInitialize(SLo,0);ArrayInitialize(TPo,0);ArrayInitialize(OTo,0);

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

   {    

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      { 

         if (OrderSymbol()==Symbol() || AllSymbol)

         { 

            if (OrderType()>1) {Ord++;continue;}

            OTo[Poz] = OrderTicket();

            SLo[Poz] = NormalizeDouble(OrderStopLoss(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            TPo[Poz] = NormalizeDouble(OrderTakeProfit(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            Poz++;

         }

      }

   } 

   return(INIT_SUCCEEDED);

  }

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

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

   int ord=0;

   int poz=0;

   double SL[100];ArrayInitialize(SL,0);

   double TP[100];ArrayInitialize(TP,0);

   int OT[100];ArrayInitialize(OT,-1);

   int OTi[100];ArrayInitialize(OTi,0);

   string OS[100];

   int i;

   for (i=0; i<OrdersTotal(); i++)

   {    

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      { 

         if (OrderSymbol()==Symbol() || AllSymbol)

         { 

            if (OrderType()>1) {ord++;continue;}

            OS[poz] = OrderSymbol();

            OTi[poz] = OrderTicket();

            OT[poz] = OrderType();

            SL[poz] = NormalizeDouble(OrderStopLoss(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            TP[poz] = NormalizeDouble(OrderTakeProfit(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            poz++;

         }

      }

   } 

   string txt="";

   if (AlertClose && Poz>poz) txt = HistoryPozishion();//70:@KB0 7>78F8O

   if (AlertOpen && Poz<poz) txt = Pozishion();//>B:@KB0 ?>78F8O

   if (AlertOrder && Ord>ord && txt=="") txt = HistoryOrder();

   if (AlertOrder && Ord<ord && txt=="") txt = Order();

   

   if (txt!="")

   {

      _Send(txt);

   }

   else

   {

      if (Alert_SL_TP)

      {

         for (i=0; i<poz; i++)

         {    

            txt="";

            if (SLo[i] != SL[i]) txt=OS[i]+" 7<5=8;AO SL ?>78F88 "+OTYPE(OT[i])+" "+(string)OTi[i]+" SL "+DoubleToStr(SLo[i],(int)MarketInfo(OrderSymbol(),MODE_DIGITS))+" -> "+DoubleToStr(SL[i],(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            if (txt!="")

            {

               _Send(txt);

            }

            txt="";

            if (TPo[i] != TP[i]) 

            txt=OS[i]+" 7<5=8;AO TP ?>78F88 "+OTYPE(OT[i])+" "+(string)OTi[i]+" TP "+DoubleToStr(TPo[i],(int)MarketInfo(OrderSymbol(),MODE_DIGITS))+" -> "+DoubleToStr(TP[i],(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            if (txt!="")

            {

               _Send(txt);

            }

         }

      } 

   }

   ArrayInitialize(SLo,0);ArrayInitialize(TPo,0);ArrayInitialize(OTo,0);

   Poz=0;Ord=0;

   for (i=0; i<OrdersTotal(); i++)

   {    

      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

      { 

         if (OrderSymbol()==Symbol() || AllSymbol)

         { 

            if (OrderType()>1) {Ord++;continue;}

            OTo[Poz] = OrderTicket();

            SLo[Poz] = NormalizeDouble(OrderStopLoss(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            TPo[Poz] = NormalizeDouble(OrderTakeProfit(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS));

            Poz++;

         }

      }

   } 



   //Ord=ord;

   //Poz=poz;

   return(rates_total);

}

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

string HistoryOrder()

{

   for (int i=OrdersHistoryTotal()-1; i>=0; i--)

   {    

      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

      {                                     

         if (OrderType()<2) continue;

         if (OrderSymbol()==Symbol() || AllSymbol)

         { 

            return(StringConcatenate("0:@KB >B;>65==K9 >@45@ ",OTYPE(OrderType()),OrderTicket()," ",OrderSymbol()));

         }  

      }

   }

   return(NULL);

}

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

string HistoryPozishion()

{

   string txt=NULL;

   double OCP;

   for (int i=OrdersHistoryTotal()-1; i>=0; i--)

   {    

      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))

      {                                     

         if (OrderSymbol()==Symbol() || AllSymbol)

         { 

            OCP=OrderClosePrice();

            if (OCP==OrderStopLoss()  ) txt="SL";

            if (OCP==OrderTakeProfit()) txt="TP";

            txt=StringConcatenate("0:@KB0 ?>78F8O ",OTYPE(OrderType()),OrderTicket()," ",OrderSymbol()," ?> ",txt," ",

            DoubleToStr(OCP,(int)MarketInfo(OrderSymbol(),MODE_DIGITS))," ?@81K;L ",DoubleToStr(OrderProfit()+OrderSwap()+OrderCommission(),2),

                                    " 0;0=A = ",DoubleToStr(AccountBalance(),2));

            return(txt);

         }  

      }

   }

   return(txt);

}

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

string Order()

{

   string txt=NULL;

   int tip;

   for (int i=OrdersTotal()-1; i>=0; i--)

   {    

      if(OrderSelect(i,SELECT_BY_POS))

      {                                     

         if (OrderSymbol()==Symbol() || AllSymbol)

         { 

            tip=OrderType();

            if (tip<2) continue;

            txt=StringConcatenate("B:@KB >@45@ ",OTYPE(tip)," ",OrderTicket()," ",OrderSymbol()," ?> F5=5 ",

            DoubleToStr(OrderOpenPrice(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS))," ;>B ",DoubleToStr(OrderLots(),2),

                                                 " SL = ",DoubleToStr(OrderStopLoss(),2),

                                                 " TP = ",DoubleToStr(OrderTakeProfit(),2));

            return(txt);

         }  

      }

   }

   return(txt);

}

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

string Pozishion()

{

   string txt=NULL;

   int tip;

   for (int i=OrdersTotal()-1; i>=0; i--)

   {    

      if(OrderSelect(i,SELECT_BY_POS))

      {                                     

         if (OrderSymbol()==Symbol() || AllSymbol)

         { 

            tip=OrderType();

            if (tip>1) continue;

            txt=StringConcatenate("B:@K0 ?>78F8O ",OTYPE(tip)," ",OrderTicket()," ",OrderSymbol()," ?> F5=5 ",

            DoubleToStr(OrderOpenPrice(),(int)MarketInfo(OrderSymbol(),MODE_DIGITS))," ;>B ",DoubleToStr(OrderLots(),2),

                                                 " SL = ",DoubleToStr(OrderStopLoss(),2),

                                                 " TP = ",DoubleToStr(OrderTakeProfit(),2));

            return(txt);

         }  

      }

   }

   return(txt);

}

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

string OTYPE(int tip)

{

   if (tip==OP_BUY) return("BUY");

   if (tip==OP_SELL) return("SELL");

   if (tip==OP_BUYSTOP) return("BUYSTOP");

   if (tip==OP_SELLSTOP) return("SELLSTOP");

   if (tip==OP_BUYLIMIT) return("BUYLIMIT");

   if (tip==OP_SELLLIMIT) return("SELLLIMIT");

   return("");

}

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

string GV_Send;

void _Send(string txt2)

{

   uchar array[];

   int i,n=0,j=StringToCharArray(txt2,array);

   for(i=0; i<j; i++)

   {

      n+=array[i];

   }

   if (GlobalVariableCheck(GV_Send))

   if (GlobalVariableGet(GV_Send)==n) 

   {

      //Alert(Symbol()," ?>2B>@ :><0=4K");Comment(j," ",n," ?>2B>@ :><0=4K");

      return;

   }

   GlobalVariableSet(GV_Send,n);

   if (AlertON) Alert(txt2);

   if (MailSend) SendMail(StringConcatenate("">@3>2K9 AG5B ",AccountNumber()),txt2);

}

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

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