Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Email alert on Range Bar
 Post subject: Email alert on Range Bar Post rating: 0   New post Posted: Wed 02 May, 2012, 23:18 

User rating: 0
Joined: Sun 22 Apr, 2012, 19:19
Posts: 54
Location: United KingdomUnited Kingdom
Hello Support

I would like some help developing a manual strategy. I want to receive an alert by email when MACD crosses for a range bar chart. I have cribbed together some code using files submitted in another post. It compiles, but I get email authentication errors. I am not sure how to resolve this.

The code is attached. I would be grateful for some help.


Attachments:
SIMPLEMACD_Strat3.java [14.54 KiB]
Downloaded 343 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Email alert on Range Bar Post rating: 3   New post Posted: Thu 03 May, 2012, 01:07 
User avatar

User rating: 94
Joined: Mon 06 Feb, 2012, 12:22
Posts: 357
Location: Portugal, Castelo Branco
tinfx:

You need to autenticate to smtp servers for them to allow sending e-mails.

Please take the following example:


import java.util.Properties;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.Authenticator;
import javax.mail.PasswordAuthentication;

public class SendMail {
   
   private String mailSMTPServer;
   private String mailSMTPServerPort;
   
   SendMail() {
      mailSMTPServer = "smtp.gmail.com";
      mailSMTPServerPort = "465";
   }
   
   SendMail(String mailSMTPServer, String mailSMTPServerPort) {
      this.mailSMTPServer = mailSMTPServer;
      this.mailSMTPServerPort = mailSMTPServerPort;
   }
   
   public void sendMail(String from, String to, String subject, String message) {
      
      Properties props = new Properties();

                /*
                props.setProperty("proxySet","true");
                props.setProperty("socksProxyHost","192.168.155.1");
                props.setProperty("socksProxyPort","1080");
                */

      props.put("mail.transport.protocol", "smtp");
      props.put("mail.smtp.starttls.enable","true");
      props.put("mail.smtp.host", mailSMTPServer);
      props.put("mail.smtp.auth", "true");
      props.put("mail.smtp.user", from);
      props.put("mail.debug", "true");
      props.put("mail.smtp.port", mailSMTPServerPort);
      props.put("mail.smtp.socketFactory.port", mailSMTPServerPort);
      props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
      props.put("mail.smtp.socketFactory.fallback", "false");
      
      
      SimpleAuth auth = null;
      auth = new SimpleAuth ("login","password");
      
      Session session = Session.getDefaultInstance(props, auth);
      session.setDebug(true);
      Message msg = new MimeMessage(session);

      try {
         
         msg.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
         
         msg.setFrom(new InternetAddress(from));
         
         msg.setSubject(subject);
         
         msg.setContent(message,"text/plain");

      } catch (Exception e) {
         System.out.println(">> Error: Need to complete message");
         e.printStackTrace();
      }
      
      
      Transport tr;
      try {
         tr = session.getTransport("smtp");
         
         tr.connect(mailSMTPServer, "login", "password");
         msg.saveChanges();
         
         tr.sendMessage(msg, msg.getAllRecipients());
         tr.close();
      } catch (Exception e) {
         
         System.out.println(">> Error: Send message");
         e.printStackTrace();
      }

   }
}

class SimpleAuth extends Authenticator {
   public String username = null;
   public String password = null;


   public SimpleAuth(String user, String pwd) {
      username = user;
      password = pwd;
   }

   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication (username,password);
   }
}


I hope this helps

Best regards

Trade well and good luck

JL


 
 Post subject: Re: Email alert on Range Bar Post rating: 0   New post Posted: Thu 03 May, 2012, 11:03 

User rating: 0
Joined: Sun 22 Apr, 2012, 19:19
Posts: 54
Location: United KingdomUnited Kingdom
Thanks JL

I am new to Java. How would I call sendmail from SIMPLEMACD_strat.

Assistance greatly appreciated.

Tin


 
 Post subject: Re: Email alert on Range Bar Post rating: 0   New post Posted: Thu 03 May, 2012, 12:14 

User rating: 0
Joined: Sun 22 Apr, 2012, 19:19
Posts: 54
Location: United KingdomUnited Kingdom
Managed to work it out. Thanks for your help.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com