Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
SendMail() for strategies
Updated January 17, 2015
Top Posters
looks_one
dsraider
with 20 posts (5 thanks)
looks_two
gregid
with 6 posts (3 thanks)
looks_3
sam028
with 6 posts (10 thanks)
looks_4
Big Mike
with 1 posts (2 thanks)
Best Posters
looks_one
Big Mike
with 2 thanks per post
looks_two
sam028
with 1.7 thanks per post
looks_3
gregid
with 0.5 thanks per post
looks_4
dsraider
with 0.3 thanks per post
trending_up
14,478 views
thumb_up
20 thanks given
group
5 followers
forum
34 posts
attach_file
4 attachments
SendMail() for strategies
June 3rd, 2010, 09:24 AM
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 / 4 >= 0 ? "+" + 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 / 4 >= 0 ? "+" + 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
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
June 4th, 2010, 10:29 AM
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.
June 5th, 2010, 12:02 PM
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 / 4 >= 0 ? "+" + 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 / 4 >= 0 ? "+" + 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 / 4 >= 0 ? "+" + 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
June 6th, 2010, 03:30 PM
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 / 4 >= 0 ? "+" + 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 >= 0 ? "+" + 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
January 17th, 2015, 04:03 PM
barcelona
Experience: Advanced
Platform: ninjatrader
Trading: futures
Posts: 6 since Nov 2013
Thanks Given: 1
Thanks Received: 1
dsraider
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 / 4 >= 0 ? "+" + 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 >= 0 ? "+" + 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
Last Updated on January 17, 2015