NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Sunday May 26th at 12PM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > Application Technical Support > Miscellaneous Support

Miscellaneous Support Miscellaneous support issues.

Reply
 
Thread Tools Display Modes
Old 09-17-2009, 11:20 AM   #1
mballagan
Member
 
Join Date: Nov 2008
Posts: 87
Thanks: 0
Thanked 0 times in 0 posts
Default Trailing stops

I have some code where I enter long 3 contracts with 3 seperate profit targets but the same stop loss.

If the first profit target is hit I would like to move the stop for the remaining two positions. I realise I can use the following syntax:

SetStopLoss("LongEntry2",CalculationMode.Price,stoplossnew,true);
SetStopLoss("LongEntry3",CalculationMode.Price,stoplossnew,true);

assuming LongEntry1 is closed due to profit being hit. But how would I catch the event that the target is hit for LongEntry1?

I can use code such as
profit = GetCurrentBid() - LongOrder.AvgFillPrice;

to calculate the current profit on an open position but wish to catch the event of a position hitting its target. Is this done using the
OnPositionUpdate event?

mballagan is offline  
Reply With Quote
Old 09-17-2009, 12:25 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

mballagan,

You can check change in positions, then if you had your own variables tracking where the profit value and where the stop values are, you could then check it against price the moment a position change occurred and then you will be able to deduce which order was filled.
NinjaTrader_Josh is offline  
Reply With Quote
Old 09-17-2009, 12:38 PM   #3
mballagan
Member
 
Join Date: Nov 2008
Posts: 87
Thanks: 0
Thanked 0 times in 0 posts
Default profit target hit

Is a better way of doing it to use the OnExecution event? -

protectedoverridevoid OnExecution(IExecution execution)
{

if (LongOrder1 != null && LongOrder1.Token == execution.Order.Token)
{
if (execution.Order.OrderState == OrderState.Filled ))
{
//modify stop loss here for LongEntry2 & LongEntry3 using SetStopLoss

}

}


mballagan is offline  
Reply With Quote
Old 09-17-2009, 12:46 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

If you want to use advanced order methods, don't use Set() methods and just handle everything with IOrders.
NinjaTrader_Josh is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trailing Stops snaphook ATM Strategies (Discretionary Trading) 4 01-06-2009 04:03 PM
Trailing stops newtrader1 SuperDOM and other Order Entry Windows 1 10-17-2008 06:36 AM
Trailing Stops gdargento ATM Strategies (Discretionary Trading) 1 04-05-2007 10:56 AM
Trailing Stops unclelou ATM Strategies (Discretionary Trading) 2 01-18-2005 03:46 PM
Trailing Stops unclelou Miscellaneous Support 3 12-31-1969 06:00 PM


All times are GMT -6. The time now is 06:01 PM.