Forex



Go Back   Forex Trading > Discussion Areas > Metatrader 4
Forex Forum Register More recent Blogs Calendar Advertising Others Help






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
  • Elite Section
    Get access to private discussions, specialized support, indicators and trading systems reported every week.
  • Advanced Elite Section
    For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
See more

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-27-2006, 01:39 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Code to send email alerts when closed trades...

I was writing some code to send me email alerts after trades close, regardless of whether or not the expert closed the trade or the trade was closed via TP or SL. I have tested it and it works, however, I am having problems with the emails violating SMTP rules when use MT4's SendMail(). (see http://cr.yp.to/docs/smtplf.html)

Does anyone know how to get around or correct this problem, because this would be a VERY valuble tool, especially for those who need to focus time on other work and would like to keep up to speed on the account as trades are being executed. Personally, it would be great to have trades emailed to my BlackBerry to see the details after the trade is close. I appreciate any help!
Attached Files
File Type: mq4 MailAlert TEST.mq4 (2.2 KB, 248 views)

Last edited by Nicholishen; 02-27-2006 at 01:47 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 02-27-2006, 02:21 AM
cockeyedcowboy's Avatar
Senior Member
 
Join Date: Nov 2005
Posts: 480
cockeyedcowboy is on a distinguished road
Nicholishen


Try to send emails to other address, like some friend that receives email on different sever then yours. I use a mailer to send messages to myself from MetaQuote and I get errors when sending to HotMail.com addresses, the emailer wont work. Thats the only email sever I can't send to. LF means LINE FEED. In your message it mentions MSN net work which includes hotmail.com. Also some email severs donot permit you to email to the address from which the mail originates from as well. Emailing to a friend will at least eliminate the above conditions from the list.

I have not used the mailer that comes with MQ. I use a third party software, as MQ didnot have that function back in v3.xx I have not rewriten my communication module to use the built-in mailer yet, plan to do this in the near future.

The CockeyedCowboy

Last edited by cockeyedcowboy; 02-27-2006 at 02:27 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 02-27-2006, 02:24 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
fixed

...It seems that it did not like my "\n" statements.

To use the mail alert you must first setup MT preferences. If you haven't yet done it, you would go to: TOOLS>OPTIONS>EMAIL. Enable the email feature and set the preferences for SMTP.

Depending on how you intend to use it you can insert it into your code and change the subject to the name of the advisor. Make sure to add filters to the qualifying if statement. An example is inserted but commented out. Optionally you can just#include as a generic mailer.

The benefit of this is to have the system email you the details of closed trades; even when they have closed due to SL or TP.

I would appreciate feedback as to what details you would like to see in the email.
Attached Files
File Type: mq4 MailAlert TEST.mq4 (2.4 KB, 256 views)

Last edited by Nicholishen; 02-27-2006 at 02:49 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 02-27-2006, 02:26 AM
Nicholishen's Avatar
Senior Member
 
Join Date: Dec 2005
Posts: 531
Nicholishen is on a distinguished road
Quote:
Originally Posted by cockeyedcowboy
Nicholishen


Try to send emails to other address, like some friend that receives email on different sever then yours. I use a mailer to send messages to myself from MetaQuote and I get errors when sending to HotMail.com addresses, the emailer wont work. Thats the only email sever I can't send to. LF means LINE FEED. In your message it mentions MSN net work which includes hotmail.com. Also some email severs donot permit you to email to the address from which the mail originates from as well. Emailing to a friend will at least eliminate the above conditions from the list.

I have not used the mailer that comes with MQ. I use a third party software, as MQ didnot have that function back in v3.xx I have not rewriten my communication module to use the built-in mail yet, plan to do this in the near future.

The CockeyedCowboy

...looks like we posted at same time. Thanks for the info!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 05-27-2009, 02:36 AM
Junior Member
 
Join Date: Apr 2009
Posts: 3
dimmyr is on a distinguished road
I used your script and beefed it up a bit. Can't get around /n but it works for me. I am not a coder, I just played a little.

I would like to change it to alert on every instance of a market order, opening or closing.

Can you look at the code and see how you can augment the EA to do that?

Code:
//+------------------------------------------------------------------+
//|                                               MailAlert TEST.mq4 |
//|                                                      Nicholishen |
//|                                                                  |
//+------------------------------------------------------------------+
//http://www.forex-tsd.com/metatrader-4/1125-code-send-email-alerts-when-closed-trades.html
#property copyright "Nicholishen"
#property link      ""
int k;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
for(int i=0;i<1000;i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
         if(OrderSymbol()==Symbol()  ){
            k++;
         }
      }else{
         break;
      }  
   }
   Comment("Init() Trades Count = ",k);
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----

int f =0;
   for(int i=0;i<10000;i++){
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
         if(OrderSymbol()==Symbol() /*&& OrderMagicNumber()==MAGICMA && OrderComment() ==Cmt(Period())*/ ){
            f++;
          
         }
      }else{
         break;
      }  
   }
   Comment(" Trades in History ",f," Init cnt ",k  );
   if(k < f){
      string ordertyp;
      
      OrderSelect(f,SELECT_BY_POS,MODE_HISTORY);
      if(OrderType()==0)ordertyp="BUY";
      if(OrderType()==1)ordertyp="SELL";
      SendMail("prof: "+DoubleToStr(OrderProfit(),2)+", bal: "+DoubleToStr(AccountBalance(),2)+", eq: "+DoubleToStr(AccountEquity(),2)+"",
      "Symbol: "+Symbol()+" "+ordertyp+"   "+DoubleToStr(OrderMagicNumber(),0)+" \n"+
      "Comment: "+DoubleToStr(OrderComment()
      "Ticket: "+DoubleToStr(OrderTicket(),0)+" \n"+ 
      "Size: "+DoubleToStr(OrderLots(),2)+" \n"+ 
      "OpenTime: "+TimeToStr(OrderOpenTime())+" \n"+
      "Close Time: "+TimeToStr(OrderCloseTime())+" \n"+
      "Open: "+DoubleToStr(OrderOpenPrice(),4)+" \n"+
      "Close: "+DoubleToStr(OrderClosePrice(),4)+" \n"+
      "Profit: "+DoubleToStr(OrderProfit(),2)+" \n\n"+

      "Balance: "+DoubleToStr(AccountBalance(),2)+" \n"+
      "Used Margin: "+DoubleToStr(AccountMargin(),2)+" \n"+
      "Free Margin: "+DoubleToStr(AccountFreeMargin(),2)+" \n"+
      "Equity: "+DoubleToStr(AccountEquity(),2)+" \n"+
      "Open Orders: "+DoubleToStr(OrdersTotal(),0)+"" );

      k++;
   }
 return;
} 


//----
  
//+------------------------------------------------------------------+
Attached Files
File Type: mq4 MailAlert-On Order Close-1.mq4 (3.1 KB, 19 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 06-01-2009, 09:46 PM
Junior Member
 
Join Date: Apr 2009
Posts: 3
dimmyr is on a distinguished road
Just made final modifications to it.

It alerts upon the close of a trade on a pair to which the EA was attached. I use a commercial EA, and I open up an extra chart to which I attach the alerter.

I would love to have it augmented to alert on trade openings as well, but I am not that smart yet. If anyone can contribute to this code, that would be great!

This is what the email looks like:


Subject: CLOSE pr: 23.59, bal: 5152.57, eq: 5058.81

Symbol: <PAIR> <BUY/SELL> <MAGIC#>
Comment: <COMMENT>
Ticket#: <TICKET#>
Size: <SIZE_LOT>
OpenTime: <OPEN_TIME/DATE>
Close Time: <CLOSE_TIME/DATE>
Open: <OPEN_PRICE>
Close: <CLOSE_PRICE>
Profit: <$PROFIT>
Pips: <PROFIT_IN_PIPS>

Balance: <CURRENT_BALANCE>
Used Margin: <USED_MARGIN>
Free Margin: <FREE_MARGIN>
Equity: <CURRENT_EQUITY>
Open Orders: <CURRENT_OPEN_ORDERS>

Broker: <BROKER_NAME>
Leverage: <LEVERAGE_USED>
Attached Files
File Type: zip MailAlertOnOrderClose.zip (1.0 KB, 50 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 06-09-2009, 06:15 AM
Junior Member
 
Join Date: Apr 2009
Posts: 3
dimmyr is on a distinguished road
Hmm

Looks like my EA counts wrong, gives me some random closed trade from history. Anyone can look at the code?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 06-12-2009, 07:00 AM
Junior Member
 
Join Date: Aug 2008
Posts: 5
CilO is on a distinguished road
"Auto email" sent modified to add price in indicator, help !

Hello !

First, i would like to thank the many contributos of the forum ! Great place !!!

I have no skills in programming and would like to slightly modify an indicator i use.
It sends an email whena na alert occurs. All is mentionned except the price.
So, what to add to have the price inserted in the email ?

SendMailOnce("Signal " + Symbol(),Symbol()+ ":" + PeriodToText() + " - Up Signal" + #price# ,1);

I will have to specify the correct code for price as well as a conversion from real to string.

I know this sounds too easy for most of you, but it will help me a lot !

Thanks in advance,

CilO
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using CCI to trigger Email alerts techtrader Metatrader 4 5 11-26-2008 02:13 AM
Send Email On Pre Set Time not Working, event is not firing ! icm63 Metatrader 4 2 03-26-2007 08:55 AM
Email Alerts - SMTP Server cballew General Discussion 1 03-16-2007 04:17 PM


All times are GMT. The time now is 11:45 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.