Send buy alert via email
Author: angel57
Creation Date: 10/15/2008 4:20 PM
profile picture

angel57

#1
Is there a mechanism already in WL5.x, or through Fidelity, or a way in C# to have the alerts (generated by a strategy ) sent by email or SMS? Since I am not always sitting at my desk while the strategy is running, I miss some of the buy alerts so I would like it to send me an email/SMS which will show up on my phone. I don't have the confidence yet to run the strategy fully automated, so I would like to get the buy alert and then analyze the current situation to see if I should execute the trade. If all the pieces are not there but someone can point me to some code I can modify/adapt, then I could make it work for WL and donate to the community.
profile picture

Cone

#2
It's such a highly-used feature (in Version 4) that I'm sure Alerts by email will eventually find its way back into Version 5. Until then, Eugene already posted a simple routine that you can incorporate into your Strategy here.

Repeated here for your convenience -
CODE:
Please log in to see this code.
profile picture

angel57

#3
Works perfectly, thanks.
profile picture

maustin30062

#4
Could you show how the above email code would be used in a simple buy strategy passing the signal name and number of shares in the email?

Thanks,

profile picture

maustin30062

#5
I am getting an error message when I run a practice code in the debug window it is "Insufficient system storage. The server response was: 4.1.1 ... temporary failure".

Thanks
profile picture

maustin30062

#6
Never mind the above error message. Seems to be related to my cellphone SMS, not the code.

Thanks
profile picture

Eugene

#7
QUOTE:
Could you show how the above email code would be used in a simple buy strategy passing the signal name and number of shares in the email?


CODE:
Please log in to see this code.
profile picture

prestonford

#8
When I run Cone's text I'm taking an "The operation has time out." error message. Could this be due to my smtp outgoing server (godaddy's "smtpout.secureserver.net") requiring authentication? If so, what should I add?
Many thanks.
profile picture

Eugene

#9
It's better asking Godaddy support if their service requires authentication. ;)

The method works with Gmail and therefore doesn't require adding anything, just specifying your account and password in the appropriate lines of code (i.e. From, Pass...)

Although it shouldn't make substantial difference, using the updated AlertByEmail method from the Community.Components library will be more convenient.

If using WLP 5.1 that currently does not have the Extension Manager, download the library from WL5Wiki.
profile picture

prestonford

#10
Thanks, Eugene.
My smtp server does require authentication, and I suspect that is the cause of my timing out. I'm running WL5.1 with some simple coded strategies and trying to avoid flogging myself learning net.mail. Any suggestions?
profile picture

Eugene

#11
As Gmail certainly requires SMTP authentication, this code already supports it.

How exactly is your setup different from the example above? Have you specified your credentials?
profile picture

prestonford

#12
If anyone else is trying to send a WL 5.1 email from a Godaddy-hosted URL (to a user on that same URL) the changes that, finally, worked for me are:

string smtpServer = "smtpout.secureserver.net";
SmtpClient sc = new SmtpClient( smtpServer, 25 );
sc.EnableSsl = false;

profile picture

Eugene

#13
CODE:
Please log in to see this code.


In other words, some outgoing mail servers require secure connection (using SSL and/or TLS encryption) and for Godaddy (and many more) to work this setting should be turned off. (Actually, if you look into the Debug window of WL5 there should be a line that says something like "This server doesn't support secure connections".)

Thanks for the heads-up. I'm adding a switch to turn secure connection on/off to the AlertByEmail method. Developer 5.1 users can download the updated Community.Components library using Extension Manager shortly.
profile picture

prestonford

#14
Eugene, thanks very much. Your assistance is most appreciated. I have a couple questions...
Email is a bit slow for alerts from this strategy. Can I send a text message from WL 5.1?
Finally, if I need to use email, how do I set the email priority to High instead of Normal?
profile picture

Eugene

#15
QUOTE:
Can I send a text message from WL 5.1?

What is a text message, SMS? Then here's one possible way (in the last message):
Threading and MessageBox?

CODE:
Please log in to see this code.

Since Priority is a property of the MailMessage object, the answer is -- by changing the property like this:

CODE:
Please log in to see this code.
profile picture

prestonford

#16
Thanks, Eugene. Both of your recent suggestions were just what I needed.
profile picture

JJWTX

#17
Hello,

I am very new to WLP and would appreciate if someone could help walk me through how to set up the above email alert. Here is a copy f the code from the rules based system i set up:
CODE:
Please log in to see this code.


Now how would I get this system to send me buy alerts? I will be setting a TSL on each trade so I dont need to worry about any other indicators. I am trying to keep it simple with this and would appreciate anyones help.

Thank you!

JJWTX
profile picture

Eugene

#18
QUOTE:
Now how would I get this system to send me buy alerts?


1. At first you'll need to have Community.Components downloaded. From this site - "Get Extensions" - for Developer 5.1 and Pro 5.3 users, or from our Wiki - all versions. If you're a Pro 5.1 user, download the binary archive from the Wiki download page and unpack it in WLP main directory.
2. Take a look at the function parameters and configure them in your strategy code - SMTP server, port, secure connection or not etc. It's documented here: AlertByEmail

CODE:
Please log in to see this code.
profile picture

JJWTX

#19
Hi Eugene,

Thanks so much for the prompt reply and the help! I think I have it all together I just have a couple questions:

There are two places for email addresses, in the first one I put in a gmail account along with the pass, port and smtp. On one of the last lines of code I put in an AOL email. Am I correct that the email will be generated and sent from the Gmail account and sent to the AOL account? Also, where it said "Hello World" I replaced it with "BUY ALERT". As I believe this will be the subject line in the email?

On the current system it has a trade activated. Is there any way to test the email function so that when an alert comes along I know it will be sent?

Lastly, do I have to have WLP on and be logged in to Fidelity for it to work?

Thank you!
profile picture

JJWTX

#20
I just tried to run the strategy and I keep recieving the error "Error Sending Mail". Any ideas? This is what I have in the code (email/pass changed of course)
CODE:
Please log in to see this code.


profile picture

JJWTX

#21
Ok, I just realized that I had the port wrong. I changed it to 995 instead of 998 but I still get the error "Failure Sending Mail".
profile picture

Eugene

#22
QUOTE:
As I believe this will be the subject line in the email?

No need to believe: the parameters are documented by the link above (see my 1st reply to you).

QUOTE:
Lastly, do I have to have WLP on and be logged in to Fidelity for it to work?

Of course. All the time.

QUOTE:
I changed it to 995 instead of 998 but I still get the error "Failure Sending Mail".

Make sure that 1) your credentials are correct and 2) your antivirus/firewall/router/whatever is not blocking WealthLabPro.exe from communicating with SMTP server.
profile picture

gwrowe

#23
I am using cox as my e-mail provider and I'm having trouble getting an e-mail sent from within Wealth-Lab 5.3. Below is the code.

CODE:
Please log in to see this code.


I'm not getting any error messages but the e-mail is not being sent. Any suggestions? Thanks.
profile picture

Eugene

#24
See my reply from 1/21/2009 3:48 AM for a list of things to check.
profile picture

tasmaine

#25
I've gone through all the prior posts related to sending e-mail alerts. I'm still having problems though and will freely admit that it may be because my programming experience is not object-oriented.

In WL4, I'm alerted on my cell phone when a limit signal reaches 98% of its "target". I haven't found a way to do something other than at target in WL5 yet, so I would be satisfied with sending an alert to my cell that permits me to make the trade when the target is hit.

I am running this on a dataset that contains more than 100 symbols, so one of the critical pieces of info I need sent is the symbol that this pertains to. I found this in the alert object, but not the position object.

Code snippet:

CODE:
Please log in to see this code.


This compiles fine, but I get a runtime error: "Index was out of range. Must be non-negative and less than the size of the collection." I'm fairly certain that this is related to the line 'Alert a = Alerts[0];' - specifically the '0'.

The conceptual problem I'm having is that the script is written to operate on one symbol at a time, and will only create one alert at a time. How do I get beyond this error?

Thanks.
profile picture

Eugene

#26
You're probably getting the error because that Alert does not exist in that context. Please see any relevant QuickRef example that works with the Alert object outside of the main (trading) loop.

Here's what is supposed to work:
CODE:
Please log in to see this code.
profile picture

bgood

#27
Now that V5.5 has AlertByEmail built into WL, how is it used? I looked at the Wiki and there was not any explaination regarding how to use it. I have been using code like what is contained in the above posts and it works great. What I do not like is my email password is encoded in every strategy that I want alerts. I am hoping that the new mechanism fixes this.

profile picture

Eugene

#28
Just a little misconception: it's not AlertByEmail that was built into WL5.5, but a separate tab in WL's Preferences (hit F12) where you need to specify the host, the password and other communication details.
profile picture

bgood

#29
OK, so how do you utilize the information in the preferences into the existing AlertByEmail class so that the information is not built into every strategy?
profile picture

Eugene

#30
AlertByEmail was an interim workaround. There's no connection between it and Wealth-Lab's own e-mail alert function. There's no need to use AlertByEmail in your Strategy as long as you converted to the built-in option.
profile picture

skorandla

#31
WLP 6.x: Once built-in email options are configured in preferences, does it automatically send all alerts as email or do I need to call any function in the strategy code?
profile picture

skorandla

#32
Found enable/disable of emails in strategy monitor.
profile picture

Cone

#33
Right, no extra code required; just enable the EMail Alert buttons where required.

Note:
There is an open issue that EMail Alerts may fail to be sent approximately 5% of the time. Until that is resolved, if you are dependent on EMail Alerts I'd recommend using the manually-coded AlertByEmail method.
profile picture

skorandla

#34
Thanks Cone.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).