Download MetaTrader 5

How to send an email once an Expert Advisor places a trade?

To add comments, please log in or register
Manage agents in your profile. It is easy!
Ali irwan
178
Ali irwan 2016.08.20 16:54 
I can send a test email fine from mt4. 

But I would like an email once an Expert Advisor places a trade. Is there a little line of code I could include in the EA. I would just like the subject of the email to be the pair traded, buy or sell and price traded. 

Then another email would go when the EA closes with the pair traded and exit price.

I have looked here and elsewhere before posting this but I can't find the answer. Most focus on how to send email in mt4 generally. I've managed that.

Thanks in anticipation
Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.08.20 23:21  
Ali irwan:
I can send a test email fine from mt4. 

But I would like an email once an Expert Advisor places a trade. Is there a little line of code I could include in the EA. I would just like the subject of the email to be the pair traded, buy or sell and price traded. 

Then another email would go when the EA closes with the pair traded and exit price.

I have looked here and elsewhere before posting this but I can't find the answer. Most focus on how to send email in mt4 generally. I've managed that.

Thanks in anticipation

You can check the return value of OrderSend() function and if it is true, you call the SendMail() Function to send out the email.

The same can be done with the OrderClose() function, but not if the SL/TP levels are hit in that case you did not use OrderClose() function,

But in that case you can still detect those closed orders by monitoring OrdersTotal() function and whenever something changes still send out the message.

https://www.mql5.com/en/docs/common/sendmail

Documentation on MQL5: Common Functions / SendMail
Documentation on MQL5: Common Functions / SendMail
  • www.mql5.com
Common Functions / SendMail - Reference on algorithmic/automated trading language for MetaTrader 5
Cuong Truong
4248
Cuong Truong 2016.08.21 02:06  

MT4 platform have an option for you to input your email server.

It should send you an email whenever a trade is made on your account.

 You don't need to make an EA to send you email. 

 

 

Ali irwan
178
Ali irwan 2016.08.22 17:17  
Marco vd Heijden:

You can check the return value of OrderSend() function and if it is true, you call the SendMail() Function to send out the email.

The same can be done with the OrderClose() function, but not if the SL/TP levels are hit in that case you did not use OrderClose() function,

But in that case you can still detect those closed orders by monitoring OrdersTotal() function and whenever something changes still send out the message.

https://www.mql5.com/en/docs/common/sendmail

after I put the above functions, do I have the setting to serve email
Ali irwan
178
Ali irwan 2016.08.22 17:21  
Cuong Truong:

MT4 platform have an option for you to input your email server.

It should send you an email whenever a trade is made on your account.

 You don't need to make an EA to send you email. 

 

 

I've done the above options by entering the email server but it still can not be sent to email
Marco vd Heijden
Moderator
4704
Marco vd Heijden 2016.08.22 18:04  
Ali irwan:
after I put the above functions, do I have the setting to serve email

What do you mean?

You check the return value of OrderSend() function if it was successful it returns the ticket number.

int ticket=OrderSend(....

 if(ticket>0)
  {
   SendMail(....
  }


To add comments, please log in or register