PDA

View Full Version : Need email alert to give name of instrument


ninjablanks
10-28-2007, 06:27 PM
I run 2 different strategies on about 10 instruments in four different time frames. When I get an email I have to manually scan the instruments to see which one triggered the alert. Is there an easy way to get the strategy to tell me which instrument triggered the alert? Thanks!

NinjaTrader_Josh
10-28-2007, 06:40 PM
In your strategy you could use SendMail().

http://www.ninjatrader-support.com/HelpGuideV6/SendMail1.html

ninjablanks
10-28-2007, 06:47 PM
That is what I am using now to send the email but the message states "Long startegy triggered" I would like it to say long strategy triggered on USDJPY in 30 min time frame for example. Is there a way to get NT to "get the name of the instrument and automatically out it in the email. I am not aware of a way to get sendmail to do this. Thanks!

NinjaTrader_Josh
10-28-2007, 06:55 PM
SendMail("support@ninjatrader.com", "customer@winners.com", "Trade Alert", "Long strategy triggered on " + Instrument.MasterInstrument.Name + " in " + Bars.Period.Value + "-" + Bars.Period.Id + " time frame.");

The body of your email would end up as something like this:
"Long strategy triggered on ER2 in 1-Minute time frame."

ninjablanks
10-28-2007, 08:08 PM
Thanks for your help!

KBJ
10-28-2007, 08:34 PM
The NinjaTrader documentation people may already have done this, but if not, I'd like to suggest this as a good example to add to the Help under SendMail.

It would be nice to see this example of Josh's there, in addition to the somewhat less complex example that's already there.

Also, I know its a matter of personal preference, but I like this alternate, but equivalent format that could be added as well:


SendMail("support@ninjatrader.com", "customer@winners.com", "Trade Alert", String.Format("Long strategy triggered on {0} in {1}-{2} time frame", Instrument.MasterInstrument.Name, Bars.Period.Value, Bars.Period.Id ));
Adding little nuances like this could help people who are trying to get up to speed on C#, if they haven't yet read a manual on it.

When I first started with NinjaScript, some 8 months ago, I was somewhat lost on all the C# and .net ideosyncracies for a while, and it took me maybe a month to run across this one (String.Format instead of Variable.ToString() which really got tiresome after a while.) When I say I was a little lost, this is in spite of many years of programming in various other languages; I cannot imagine what it must be like for someone who has little or no experience when they're trying to pick up all these useful things that can be done in C#, but I suspect that little things like this might help. I think that adding more verbose and well-commented examples to the Help documentation would probably be a great assistance to any novice C# or NinjaScript programmer. I will try to add additional items to the forum to help on this, too, as they occur to me.