NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 02-04-2009, 04:35 PM   #1
SystemTrading
Senior Member
 
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
Default Exit Strategy

Can anyone tell me why this isn't working properly?

Code:
 
// risk management
if (Positions[0].MarketPosition==MarketPosition.Long)
{
 // place profit target
 EnterLongLimit(Positions[0].AvgPrice+(profitamount*TickSize));

 // place stop loss
 EnterLongStop(Positions[0].AvgPrice-(stopamount*TickSize)); 

 // track breakeven highwater 
 hw=Math.Max(hw,Positions[0].GetProfitLoss(High[0],PerformanceUnit.Points));
 if (hw>=betrigger)
 behit=true; 

 // place breakeven order
 if (behit)
 EnterLongStop(Positions[0].AvgPrice); 

 // place trailing stop
 EnterLongStop(hw-(stopamount*TickSize));
}

elseif (Positions[0].MarketPosition==MarketPosition.Long)
{
 // place profit target
 EnterShortLimit(Positions[0].AvgPrice-(profitamount*TickSize));

 // place stop loss
 EnterShortStop(Positions[0].AvgPrice+(stopamount*TickSize)); 

 // track breakeven highwater 
 hw=Math.Max(hw,Positions[0].GetProfitLoss(High[0],PerformanceUnit.Points));
 if (hw>=betrigger)
 behit=true; 

 // place breakeven order
 if (behit)
 EnterShortStop(Positions[0].AvgPrice); 

 // place trailing stop
 EnterShortStop(hw+(stopamount*TickSize));
}
SystemTrading is offline  
Reply With Quote
Old 02-04-2009, 08:20 PM   #2
Newshues
Member
 
Join Date: Jan 2009
Posts: 40
Thanks: 0
Thanked 0 times in 0 posts
Default

elseif (Positions[0].MarketPosition==MarketPosition.Long)


just as a guess.
Newshues is offline  
Reply With Quote
Old 02-04-2009, 08:30 PM   #3
SystemTrading
Senior Member
 
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
Default

good call. probably the culprit. Thanks for the help.
SystemTrading is offline  
Reply With Quote
Old 02-05-2009, 07:36 PM   #4
SystemTrading
Senior Member
 
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
Default

still not working. What could be wrong?
SystemTrading is offline  
Reply With Quote
Old 02-06-2009, 04:13 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,384
Thanks: 252
Thanked 967 times in 950 posts
Default

What exactly is not working?

Is this a MultiInstrument Strategy? Positions should only be used in that context - http://www.ninjatrader-support.com/H...Positions.html

Have you tried adding Print() statements and TraceOrders to debug the code?
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 02-06-2009, 09:05 AM   #6
SystemTrading
Senior Member
 
Join Date: Aug 2008
Location: Orlando, Florida
Posts: 166
Thanks: 0
Thanked 0 times in 0 posts
Default

Found the problem. The problem is I was using EnterLongLimit and EnterLongStop to exit positions.
SystemTrading 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
Exit strategy.... jed77 Strategy Development 18 10-16-2008 09:58 AM
Exit strategy question twaydow Strategy Development 1 09-30-2008 10:34 AM
'Exit on Close' in Strategy Wizard Elliott Wave Strategy Development 1 05-07-2008 10:14 PM
Entry / Exit Strategy Edgar V. Strategy Analyzer 19 03-17-2008 07:29 AM
Exit Strategy in Initialize() Oli Automated Trading 10 03-30-2007 03:06 AM


All times are GMT -6. The time now is 12:21 PM.