NexusFi: Find Your Edge


Home Menu

 





SendMail() for strategies


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one dsraider with 20 posts (5 thanks)
    2. looks_two sam028 with 6 posts (10 thanks)
    3. looks_3 gregid with 6 posts (3 thanks)
    4. looks_4 Pristine with 1 posts (0 thanks)
      Best Posters
    1. looks_one Big Mike with 2 thanks per post
    2. looks_two sam028 with 1.7 thanks per post
    3. looks_3 gregid with 0.5 thanks per post
    4. looks_4 dsraider with 0.3 thanks per post
    1. trending_up 14,200 views
    2. thumb_up 20 thanks given
    3. group 5 followers
    1. forum 34 posts
    2. attach_file 4 attachments




 
Search this Thread

SendMail() for strategies

  #1 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

Hi All,

I'm trying to add SendMail() to my strat for when it enters, moves my stop to breakeven and closes. Since I'm using CalculateOnBarClose = false, I can't use the regular SendMail() code as it produces a zillion emails. Does anyone know of a work around? It's the usual easter egg hunt on the Ninja forum and I think I'm currently moving in reverse. Also, if it matters, I'm using a breakeven, a trail and an exit. I'd like to get an email when the first of those is filled.

Thanks,
Dave

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
NexusFi Journal Challenge - May 2024
Feedback and Announcements
Quant vue
Trading Reviews and Vendors
 
  #3 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


Just add a flag after each email/event:

 
Code
                            
protected override void Initialize() {
private 
bool _enter_mail false;
private 
bool _be_mail false;
private 
bool _close_mail false;
...
}

protected 
override void OnBarUpdate() {
if (! 
_enter_mail  && _orderfilled) {
_enter_mail=true;
SendMail(...
}

if (! 
_be_mail  && _moved_stop_to_breakeven) {
_be_mail=true;
SendMail(.... 

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

Sam,

I'm off to work now but wanted to thank you for your quick reply. This looks very promising. Question, though. Do I need to insert this code with each condition or can I just post it anywhere under the respective overrides? For example:

 
Code
if (CrossAbove(EMA(20), EMA(50), 1))
            {
                entryOrder = EnterLong(DefaultQuantity, "2050 Cross");
				
				
			if (! _enter_mail  && _orderfilled) {
                        _enter_mail=true;
                        SendMail(...;
	     }
Do I have that right?

Thanks,
Dave

Reply With Quote
  #5 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

It looks good.
I use in this example a variable _ordefilled which needs to de defined and correctly initialized, but you have the idea I think: send the email only if the order is really filled. Maybe the good place for this is in OnOrderUpdate(), with something like:

 
Code
                            
if entryOrder.OrderState == OrderState.Filled {
  
_enter_mail=true;
  
SendMail(.. 

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #6 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

Okay, now I'm getting confused. I'm one year older today and closer to senility so please take it easy on me. Do I use both or should I just use the code in your last post and then add something to variables and Initialize()?

Reply With Quote
  #7 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


dsraider View Post
Okay, now I'm getting confused. I'm one year older today and closer to senility so please take it easy on me. Do I use both or should I just use the code in your last post and then add something to variables and Initialize()?

It's up to you, 2 choices:
- send the email when the order is sent, or
- send the email when he order is filled
So not both, unless you want two emails, one went the order is sent, an other one when it's filled (so you'll need another boolean variable).
I think I have an example, I was doing similar stuff but with sending sms, I'll try to put it in this thread later.

And happy birthday

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
  #8 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

When the order is filled is probably better. If you have an example, I'd greatly appreciate it as I'm getting a little lost on this one. Oh, and thanks for the birthday wishes. As you can probably imagine, my head currently hurts.

Dave

Reply With Quote
  #9 (permalink)
dsraider
New York, NY
 
Posts: 142 since Dec 2009
Thanks Given: 41
Thanks Received: 87

Update - I'm making progress but am still having issues.

 
Code
private IOrder 	entryOrder1			= null;

if (CrossAbove(EMA(20), EMA(50), 1))
        {
        entryOrder1 = EnterLong(DefaultQuantity, "60 Cross");
	}

if (entryOrder1 != null && entryOrder1.Token == order.Token)
     	{
	if (entryOrder1.OrderState == OrderState.Filled)
        SendMail("", "[email protected]", "ES Long " + Position.AvgPrice, "");
	}
This does email but I get two instead of one and price is listed as 0. Same for exits.

I'm completely lost on how to use SendMail() with targets and stops. Any help would be greatly appreciated.

Thanks,
Dave

Reply With Quote
  #10 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


Can you attache the .cs file for the strategy you're working on ?
It will much much easier to see what's wrong.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on January 17, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts