This forum is in read-only mode now. You may discuss your questions on forums of MQL4.community and MQL5.community

Email Help


Back to topics list
avatar
100
mpfx 2005.03.29 00:51 
I am trying to set up a daily email alert.
This is the code that I am using.

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
if ( Hour()==22 )
if ( Minute()==39)
if ( Seconds()>45)
{
SendMail("TEST FX Alert", "OPEN " +Open[0] + " LOW " +Low[0] + " HIGH " + High[0] + " BID " +Bid);

Print(" Daily Email Alert Sent ");
}
//----
return(0);
}
//+------------------------------------------------------------------+

There are 2 problems tha I have encountered.
1. When I receive the email the prices look like this
OPEN 1.19970000 LOW 1.19930000 HIGH 1.20840000 BID 1.20500000
How do I round this to 4 decimal places ??

2. Is there a code that will limit only one email being sent?
At present I am giving the expert a 15 second window to send the email but sometimes there is no tick movement in this time and the email is not sent.
If I use if ( Hour()==22 ) if ( Minute()==39) with no seconds it sends emails continully for for 1 minute.

Any help or advice greatly apprieciated....



avatar
4464
Slawa 2005.03.29 11:15 
1. see conversion function DoubleToStr
2. use flag variable. if mail is sent then set flag to true
avatar
100
mpfx 2005.03.29 13:34 
1. see conversion function DoubleToStr
2. use flag variable. if mail is sent then set flag to true


Hi Slawa,
Thanks you very much for the info.
1. The DoubleTo Str worked a treat.

2. As I have no formal training in programming I can understand what you mean but I cannot figure out how to tell if mail has been sent.
I was trying to use ArraySetAsSeries ( What is the code for this? , true);

Thanks again
avatar
100
mpfx 2005.03.31 11:33 
Slawa or Anybody that can help....

Sorry to be a pain but I cannot figure out how to tell of an email has been sent.
What code to I use ?? I have read everything possible in the dictionary provided but am still lost.

Thanks.....
avatar
14
ctt 2005.03.31 20:55 
maybe try something like:

when you start the function:
flag = 0
---------------------------------------

where you are sending now, put:
if flag == 0 {
send email
flag = 1
}


if you need to, find the beginning of the day and set the flag to 0 so that the mail goes out the next day.
avatar
100
mpfx 2005.04.01 00:37 
Hi ctt

Thanks for your help, really apprieciate it.
This is what I have come up with but it still does not work.
Can you tell me what I am doing wrong??

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double flag;

if ( Hour()==23 )
flag = 0;

//---- TODO: Add your code here.
if (flag ==0)
if ( Hour()==22 )
{
SendMail("TEST FX Alert", "OPEN: " +DoubleToStr(Open[0], 4)
+ " LOW: " +DoubleToStr(Low[0],4)
+ " HIGH: " +DoubleToStr(High[0],4)
+ " BID: " +DoubleToStr(Bid,4));
flag =1 ;

Print(" Daily Email Alert Sent ");

}

//----
return(0);
}
//+------------------------------------------------------------------+
avatar
14
ctt 2005.04.01 08:02 
what does it do?

maybe try using an int instead of a double for the flag...
avatar
100
mpfx 2005.04.03 01:47 
It will send an email each day at a given time containing the days high, low and current bid price.
The email address that I send it to has a service that then sends the info as an sms to my mobile phone.
I will try int and see what happens but will have to wait till the market opens to see if it works.
Again many thanks for your help...
avatar
100
mpfx 2005.04.04 02:32 
FWIW I have got it working, here is code, thanks again ctt

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
static int flag;

if (flag ==0)
if ( Hour()==03)
{
SendMail("TEST FX Alert"," PROFIT:$" +DoubleToStr(AccountProfit(),2)
+ " BALANCE:$" +DoubleToStr(AccountBalance(),2)
+ " EQUITY:$" +DoubleToStr(AccountEquity(),2)
+ " OPEN:" +DoubleToStr(Open[0], 4)
+ " LOW:" +DoubleToStr(Low[0],4)
+ " HIGH:" +DoubleToStr(High[0],4)
+ " BID:" +DoubleToStr(Bid,4)
);

flag = 1 ;

Print(" Daily Email Alert Sent ");

}

if ( Hour()==04 )
{flag = 0;}

return(0);
}
//+------------------------------------------------------------------+
Back to topics list  
Download MetaTrader 5 (450 Kb, web installer) — a new terminal for financial markets