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


SendMail() for strategies
Updated: Views / Replies:6,558 / 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

  #21 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,218 received


dsraider View Post
Okay, as far as defining a variable is concerned, this works:

 
Code
                            
Variables

private Trade     lastTrade
The rest is weird. I changed lastTrade to lastTrade.ProfitPoints in SendMail() and it's brought my strat to a hault. Anyone know why?

Thanks,
Dave

You need to check for null/existance before using lastTrade, you can do this with something like Performance.AllTrades.Count > 0.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
The following 2 users say Thank You to Big Mike for this post:
 
  #22 (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 Mike,

That's what makes it even stranger because I have the following in place:

 
Code
                            
protected override void OnBarUpdate()


// Check to make sure there is at least one trade in the collection 
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); 

To add to it, Print works perfectly as my output window currently reads "The last trade's profit is 2.5". Eventually, I want to add an "if' statement so if lastTrade >= 0, it will add a "+" to the string but I can't get it working at all.

Thanks for your reply,
Dave

Reply With Quote
 
  #23 (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


dsraider, have you tried this:

 
Code
                            
Print("The last trade profit is " + (lastTrade.ProfitPoints >= "+" lastTrade.ProfitPoints lastTrade.ProfitPoints)) 



Last edited by gregid; June 2nd, 2010 at 08:07 AM. Reason: no need for "-" before negatives
Reply With Quote
 
  #24 (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,

Thanks for that but it gave me the following error message:

Type of conditional expression cannot be determined because there is no implicit conversion between 'string' and 'double'



Dave

Reply With Quote
 
  #25 (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

I can't check it now but try something along these lines:

 
Code
                            
Print("The last trade profit is " + (lastTrade.ProfitPoints >= "+" Convert.ToString(lastTrade.ProfitPoints) : Convert.ToString(lastTrade.ProfitPoints))) 


Reply With Quote
The following user says Thank You to gregid for this post:
 
  #26 (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

Greg,

You're a genius! It's worked like a charm in Print. Thank you! Can I do that in SendMail as well? I just don't get why changing

 
Code
                            
SendMail("""username@yahoo.com"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade""); 

to

 
Code
                            
SendMail("""username@yahoo.com"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints""); 

not only doesn't work but prevents my strat from trading.

Thanks again!

Dave

Reply With Quote
 
  #27 (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

Check if you haven't missed any curly brackets in your code:

 
Code
                            
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) : Convert.ToString(lastTrade.ProfitPoints)))  
        
SendMail("""username@yahoo.com"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints"");  
    }

If all brackets are in place try converting to string... just guessing here

Reply With Quote
 
  #28 (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,

I'm worried that I might have an issue with what's below as I have both my target and stop emailing me when filled so I will try using if(lastTrade != null) ---> SendMail() in both parts when I get home.

Thanks, Greg. I really appreciate your help with this.

Dave

P.S. As of now, my brackets are okay. I've checked. And checked again. And again

Reply With Quote
 
  #29 (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

Well, I tried throwing:

 
Code
                            
SendMail("""username@yahoo.com"Instrument.MasterInstrument.Name " Cross2050 Stop Filled " order.AvgFillPrice ": " lastTrade.ProfitPoints""); 

into

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

            {
                
// Check order for terminal state
                
if (order.OrderState == OrderState.Filled)
                {
                    
// Print out information about the order
                    
Print(order.ToString());
                    
SendMail("""username@yahoo.com"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);
            } 
but came up with the same issue. It just brings my strat to a hault. No trades are taken and the output window freezes. WEIRD!

Dave

Reply With Quote
 
  #30 (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 didn't check if lastTrade contains any value before using it. You should check it every time you ask for its value.

Greg

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 09:02 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.13 seconds with 20 queries on phoenix via your IP 54.83.122.227