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 gregid with 6 posts (3 thanks)
    3. looks_3 sam028 with 6 posts (10 thanks)
    4. looks_4 Big Mike with 1 posts (2 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,171 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

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

Hi Greg,

Not sure I 100% follow. I tried:

 
Code
                            
if (stopLossTokens.Contains(order.Token))
            {
                
// Check order for terminal state
                
if (order.OrderState == OrderState.Filled)
                {
                    if(
lastTrade != null)
                    {    
                    
// Print out information about the order
                    
Print(order.ToString());
                    
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " + (lastTrade.ProfitPoints/>= "+" Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4)), "");
                    Print(
"SendMail: " Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints);
                    }
                if (
order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)    
                    
// Remove from collection
                    
{
                    
stopLossTokens.Remove(order.Token);
                        
entryOrder1 null;
                        
entryOrder2 null;
                    }
                    
                }
                
// Print out the current stop loss price
                
else
                    Print(
"The order name " order.Name " stop price is currently " order.StopPrice);
            } 
and

 
Code
                            
if (stopLossTokens.Contains(order.Token))
            {
                
// Check order for terminal state
                
if (order.OrderState == OrderState.Filled && lastTrade != null)
                {
                    
                        
                    
// Print out information about the order
                    
Print(order.ToString());
                    
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " + (lastTrade.ProfitPoints/>= "+" Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4)), "");
                    Print(
"SendMail: " Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints);
                    
                if (
order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)    
                    
// Remove from collection
                    
{
                    
stopLossTokens.Remove(order.Token);
                        
entryOrder1 null;
                        
entryOrder2 null;
                    }
                    
                }
                
// Print out the current stop loss price
                
else
                    Print(
"The order name " order.Name " stop price is currently " order.StopPrice);
            } 
Both resulted in an active output window and both traded (which is progress) but neither sent an email nor printed "SendMail()" to the output window. Did I misunderstand you?

Thanks,
Dave

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
MC PL editor upgrade
MultiCharts
REcommedations for programming help
Sierra Chart
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #32 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623

Dave, you understood it correctly. The reason why no Print statement or SendMail executed is because lasttrade at the time is empty (no value).

Move the (full) code where you update the “Trade lasttrade…” to the same module (OnOrderUpdate or OnPositionUpdate?) before you check for lasttrade value in your example and if there will be any value stored in lasttrade Print and SendMail will be executed.

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


Got it! If interested:

 
Code
                            
if (stopLossTokens.Contains(order.Token))

            {
                
// Check order for terminal state
                
if (order.OrderState == OrderState.Filled && stopSent == false)
                {
                    
// Print out information about the order
                    
if (Performance.RealtimeTrades.Count 0
                        {     
                            
// Get the last completed real-time trade (at index 0) 
                            
Trade lastTrade Performance.AllTrades[Performance.AllTrades.Count 1];
                            
                            if (
lastTrade != null
                            {
                                if(
lastTrade.ProfitPoints >= 0)
                                {    
                                Print(
"The last trade profit is " + (lastTrade.ProfitPoints/>= "+" Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4)));
                                
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": +" lastTrade.ProfitPoints/4"");
                                
stopSent true;    
                                }
                                else 
                                    Print(
"The last trade profit is " + (lastTrade.ProfitPoints/>= "+" Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4)));
                                    
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints/4"");
                                
stopSent true;
                            } 
                        }    
                if (
order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)    
                    
// Remove from collection
                    
{
                    
stopLossTokens.Remove(order.Token);
                        
entryOrder1 null;
                        
entryOrder2 null;
                    }
                    
                }
                
// Print out the current stop loss price
                
else
                    Print(
"The order name " order.Name " stop price is currently " order.StopPrice);
            }
            
            
            
// Process profit target orders
            
if (profitTargetTokens.Contains(order.Token))
            {
                
// Check order for terminal state
                
if (order.OrderState == OrderState.Filled && targetSent == false)
                {
                    
// Print out information about the order
                    
if (Performance.RealtimeTrades.Count 0
                        {     
                            
// Get the last completed real-time trade (at index 0) 
                            
Trade lastTrade Performance.AllTrades[Performance.AllTrades.Count 1];
                            
                            if (
lastTrade != null)
                            Print(
"The last trade profit is " + (lastTrade.ProfitPoints/>= "+" Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4)));
                            
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Target Filled " order.AvgFillPrice ": +" lastTrade.ProfitPoints/4"");
                            
targetSent true;
                        }
                    if (
order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled || order.OrderState == OrderState.Rejected)
                    {    
                    
// Remove from collection
                    
profitTargetTokens.Remove(order.Token);
                        
entryOrder1 null;
                        
entryOrder2 null;
                    }
                }
                
                
// Print out the current stop loss price
                
else
                    Print(
"The order name " order.Name " limit price is currently " order.LimitPrice);
            }  
        } 
I owe you a steak dinner, sir. We're talking garlic mashed, caesar salad, a little vino, the whole nine. Thank you for your help and (especially) for your patience. I greatly appreciate both.

Best,
Dave

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

My last post actually needs a bit of editing but it won't let me edit. First, dividing ProfitPoints by 4 was unnecessary so get rid of "/4" wherever you see it. Second, turn this:

 
Code
                            
else  
Print(
"The last trade profit is " + (lastTrade.ProfitPoints/>= "+" Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4))); 
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints/4""); 
stopSent true
into this:

 
Code
                            
else 

Print(
"The last trade profit is " + (lastTrade.ProfitPoints >= "+" Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints))); 
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints""); 
stopSent true:

in the stop loss code. Otherwise, it'll send emails as if both options occurred.

Thanks,
Dave

Reply With Quote
  #35 (permalink)
 
Pristine's Avatar
 Pristine 
barcelona
 
Experience: Advanced
Platform: ninjatrader
Trading: futures
Posts: 6 since Nov 2013
Thanks Given: 1
Thanks Received: 1


dsraider View Post
My last post actually needs a bit of editing but it won't let me edit. First, dividing ProfitPoints by 4 was unnecessary so get rid of "/4" wherever you see it. Second, turn this:

 
Code
                            
else  

Print(
"The last trade profit is " + (lastTrade.ProfitPoints/>= "+" Convert.ToString(lastTrade.ProfitPoints/4) : Convert.ToString(lastTrade.ProfitPoints/4))); 
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints/4""); 
stopSent true
into this:

 
Code
                            
else 


Print(
"The last trade profit is " + (lastTrade.ProfitPoints >= "+" Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints))); 
SendMail("""[email protected]"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints""); 
stopSent true:

in the stop loss code. Otherwise, it'll send emails as if both options occurred.

Thanks,
Dave

You may be able to put a .zip to import. thx

Follow me on Twitter Reply With Quote




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