SendMail() for strategies - NinjaTrader Programming | futures io social day trading
futures io futures trading


SendMail() for strategies
Updated: Views / Replies:6,560 / 34
Created: by dsraider Attachments:4

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you dont need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 4  
 
Thread Tools Search this Thread
 

SendMail() for strategies

  #31 (permalink)
Trading for Fun
New York, NY
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 83 received

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("""username@yahoo.com"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("""username@yahoo.com"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
 
  #32 (permalink)
Elite Member
Wrocław, Poland
 
Futures Experience: Intermediate
Platform: NinjaTrader, Racket
Favorite Futures: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 321 given, 605 received

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
The following user says Thank You to gregid for this post:
 
  #33 (permalink)
Trading for Fun
New York, NY
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 83 received


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("""username@yahoo.com"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("""username@yahoo.com"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("""username@yahoo.com"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
The following user says Thank You to dsraider for this post:
 
  #34 (permalink)
Trading for Fun
New York, NY
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Amp Futures/Zen-Fire
Favorite Futures: ES
 
Posts: 142 since Dec 2009
Thanks: 41 given, 83 received

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("""username@yahoo.com"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("""username@yahoo.com"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)
Elite Member
barcelona
 
Futures Experience: Advanced
Platform: ninjatrader
Favorite Futures: futures
 
Pristine's Avatar
 
Posts: 6 since Nov 2013
Thanks: 1 given, 1 received


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("""username@yahoo.com"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("""username@yahoo.com"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

Reply With Quote

Reply



futures io > > > > > SendMail() for strategies

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing a delay after first SendMail execution, possible? raindrop NinjaTrader Programming 13 August 17th, 2011 03:55 PM
Stop Loss/Target & SendMail() dsraider NinjaTrader Programming 4 May 30th, 2010 07:15 AM
Communication between strategies zwentz NinjaTrader Programming 4 May 2nd, 2010 11:15 PM
Question about sendmail in strategies fiki NinjaTrader Programming 3 June 24th, 2009 02:25 AM


All times are GMT -4. The time now is 11:01 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-11 in 0.09 seconds with 20 queries on phoenix via your IP 54.145.16.43