Download MetaTrader 5
To add comments, please log in or register
Use the Pocket to paste your content. It is convenient!
John
79
John 2014.06.24 19:05 

Hi, I'm developing an EA that besides placing orders, create Alerts for take profit.

Is there a command to create the Alerts in the terminal window ?

 

Thanks. 

Boeing747
241
Boeing747 2014.06.24 19:28  

it tells you about  all of your trade operations.


//+------------------------------------------------------------------+
//|                                                     SendMail.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#include <stdlib.mqh> 
//#property strict
#property indicator_chart_window
extern bool Ignore  = false;     // Ignore the fact of the opening of market orders and to send messages only about changing them tp and sl.
extern bool Market  = true;      // Send the notification for opened and closed orders.
extern bool Pending = true;      // Send the notification for pending and cancelled orders.

int h,g,r,t,v;
datetime DA[100],E[100],time;
double PR[100],SL[100],TP[100];
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
//----
   int L=OrdersTotal();
   int H=OrdersHistoryTotal();
   bool b=false;
   datetime date,today,expiry;
   int i,e,cmd,digits,c,f,error;
   double price,stop,take;
   string type[]={"buy","sell","buy limit","sell limit","buy stop","sell stop"};
   string symbol,q,p,sl,tp,ct,text,d,ex;

//--------------------------------------- for pending and opened orders 
   today=iTime(NULL,PERIOD_D1,0);
   ct=TimeToStr(TimeCurrent(),TIME_DATE|TIME_MINUTES|TIME_SECONDS);
   if(t==1)
     {
      for(i=0; i<v; i++)
        {
         for(e=0; e<L; e++)
           {
            if(OrderSelect(e,SELECT_BY_POS,MODE_TRADES)==true)
              {
               cmd=OrderType();
               date=OrderOpenTime();
               d=TimeToStr(date,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
               expiry=OrderExpiration();
               ex="Expiry: No";
               if(expiry>today) ex="Expiry: "+TimeToStr(expiry,TIME_DATE|TIME_MINUTES);
               symbol=OrderSymbol();
               digits=(int)MarketInfo(symbol,MODE_DIGITS);
               price=OrderOpenPrice();
               p=DoubleToStr(price,digits);
               stop=OrderStopLoss();
               sl=DoubleToStr(stop,digits);
               take=OrderTakeProfit();
               tp=DoubleToStr(take,digits);
               //----
               if(Market==true && cmd<2)
                 {
                  c++;
                  if(DA[i]==date)
                    {
                     if(SL[i]!=stop || TP[i]!=take)
                       {
                        q="Order "+type[cmd]+" changed.";
                        text=ct+"   "+type[cmd]+"   "+symbol+"   at: "+p+"   sl: "+sl+"   tp: "+tp;
                        Comment(q,"\n",text);//b=SendMail(q,text);
                        if(b==false)
                          {
                          // error=GetLastError();
                          // Alert("The notification by an order "+text+" has not been sent!\nError: "+ErrorDescription(error)+"");
                          }
                       }
                    }
                  //----
                  if(c>g)
                    {
                     if(i==0 && Ignore==false)
                       {
                        q="Order "+type[cmd]+" opened.";
                        text=d+"   "+type[cmd]+"   "+symbol+"   at: "+p+"   sl: "+sl+"   tp: "+tp;
                        Comment(q,"\n",text);//b=SendMail(q,text);
                        if(b==false)
                          {
                          // error=GetLastError();
                          // Alert("The notification by an order "+text+" has not been sent!\nError: "+ErrorDescription(error)+"");
                          }
                       }
                    }
                 }
               else
                 {
                  if(Pending==true && cmd>1 && cmd<6)
                    {
                     f++;
                     if(DA[i]==date)
                       {
                        if(PR[i]!=price || SL[i]!=stop || TP[i]!=take || E[i]!=expiry)
                          {
                           q="Order "+type[cmd]+" changed.";
                           text=ct+"   "+type[cmd]+"   "+symbol+"   at: "+p+"   sl: "+sl+"   tp: "+tp+"   "+ex;
                           Comment(q,"\n",text);//b=SendMail(q,text);
                           if(b==false)
                             {
                             // error=GetLastError();
                             // Alert("The notification by an order "+text+" has not been sent!\nError: "+ErrorDescription(error)+"");
                             }
                          }
                       }
                     //----
                     if(f>r)
                       {
                        if(i==0)
                          {
                           q="Order "+type[cmd]+" opened.";
                           text=d+"   "+type[cmd]+"   "+symbol+"   at: "+p+"   sl: "+sl+"   tp: "+tp+"   "+ex;
                           Comment(q,"\n",text);//b=SendMail(q,text);
                           if(b==false)
                             {
                             // error=GetLastError();
                             // Alert("The notification by an order "+text+" has not been sent!\nError: "+ErrorDescription(error)+"");
                             }
                          }
                       }
                    }
                 }
              }
           }
        }
     }
//----
   c=0;
   f=0;
   for(i=0; i<L; i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
        {
         DA[i]=OrderOpenTime();
         E[i]=OrderExpiration();
         PR[i]=OrderOpenPrice();
         SL[i]=OrderStopLoss();
         TP[i]=OrderTakeProfit();
         cmd=OrderType();
         if(cmd<2)
           {
            c++;
           }
         else
           {
            if(cmd>1 && cmd<6)
              {
               f++;
              }
           }
        }
     }
   g=c;
   r=f;
   v=i;
   if(i==0) v=1;
//--------------------------------------------------------------- for closed and cancelled orders
   if(h!=H)
     {
      if(t==1)
        {
         for(i=H-1; i>H-20; i--)
           {
            if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
              {
               date=OrderCloseTime();
               if(time<date)
                 {
                  cmd=OrderType();
                  d=TimeToStr(date,TIME_DATE|TIME_MINUTES|TIME_SECONDS);
                  symbol=OrderSymbol();
                  digits=(int)MarketInfo(symbol,MODE_DIGITS);
                  price=OrderClosePrice();
                  p=DoubleToStr(price,digits);
                  stop=OrderStopLoss();
                  sl=DoubleToStr(stop,digits);
                  take=OrderTakeProfit();
                  tp=DoubleToStr(take,digits);
                  if(Market==true && cmd<2)
                    {
                     q="Order "+type[cmd]+" closed.";
                     text=type[cmd]+"   "+symbol+"   sl: "+sl+"   tp: "+tp+"    "+d+"    at: "+p;
                     Comment(q,"\n",text);//b=SendMail(q,text);
                     if(b==false)
                       {
                       // error=GetLastError();
                       // Alert("The notification by an order "+text+" has not been sent!\nError: "+ErrorDescription(error)+"");
                       }
                    }
                  else
                    {
                     if(Pending==true && cmd>1 && cmd<6)
                       {
                        q="Order "+type[cmd]+" cancelled.";
                        price=OrderOpenPrice();
                        p=DoubleToStr(price,digits);
                        text=type[cmd]+"   "+symbol+"   at: "+p+"   sl: "+sl+"   tp: "+tp+"    "+d;
                        Comment(q,"\n",text);//b=SendMail(q,text);
                        if(b==false)
                          {
                          // error=GetLastError();
                          // Alert("The notification by an order "+text+" has not been sent!\nError: "+ErrorDescription(error)+"");
                          }
                       }
                    }
                 }
              }
           }
        }
      //----
      for(i=H-1; i>H-20; i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true)
           {
            date=OrderCloseTime();
            if(time<date) time=date;
           }
        }
     }
   t=1;
   return(0);
  }
//+------------------------------------------------------------------+
whroeder1
13609
whroeder1 2014.06.24 23:03  
jfortes: Is there a command to create the Alerts in the terminal window ?
  1. Alert - MQL4 Documentation
  2. Alphabetic Index of MQL4 Functions (600+) - MQL4 forum
John
79
John 2014.06.25 07:39  

Thanks. But none of the examples creates conditional Alerts in the terminal windows.

How can I code a function for this ? 

whroeder1
13609
whroeder1 2014.06.25 11:29  
jfortes: none of the examples creates conditional Alerts in the terminal windows.
if(condition) Alert(...);
Edward Hirsch
685
Edward Hirsch 2014.06.25 11:39  

Press Ctrl-T to access Terminal, click on tab "Alerts", in "Alerts" window right click for menu,

select "Create" and set up your condition.

Alternatively you could use push notification for messages between your expert and your

iphone/android mobile, see SendNotification() for limitations, you will require a MetaQuotes ID,

the messages are also notified in the Journal log. 

John
79
John 2014.06.25 21:06  
Thanks everyone. Will look in to the SendNotification() .
/
To add comments, please log in or register