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 03-04-2008, 01:26 AM   #1
BenHeaton
Member
 
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default Stop losses on Positions from limit orders

Hi there

I have a strategy which enters positions using the EnterLongLimit & EnterShortLimit methods.

My strategy with stop losses is to only add a stoploss if the position has moved into a profit on the previous bar. I then set the profit to be the avg entry price.

However, i keep on having the stoploss triggerred inside the same 1 minute bar as the position was enterred, even when I add some code trying to prevent this (stipulating only SetStopLoss() when BarsSinceEntry() is greater than 0).

The code is here:

// Introduce stoploss on pos if sitting on profit
if (Position.MarketPosition == MarketPosition.Short && Position.GetProfitLoss(Close[1], PerformanceUnit.Points)>=0)
{SetStopLoss(short_position_name,CalculationMode.P rice, Position.AvgPrice,
true);}

if (Position.MarketPosition == MarketPosition.Long && BarsSinceEntry(long_position_name)>1 && Position.GetProfitLoss(Low[0], PerformanceUnit.Points )>=0)
{SetStopLoss(long_position_name,CalculationMode.Pr ice, Position.AvgPrice,
true);}


Any advice much appreciated as usual!! :-)

Ben

I have tried to exclude the stoploss from doing this
BenHeaton is offline  
Reply With Quote
Old 03-04-2008, 04:09 AM   #2
Pete S
Senior Member
 
Join Date: Jul 2007
Location: Fairfax, VA
Posts: 216
Thanks: 0
Thanked 0 times in 0 posts
Default

The current price and average position price will be very close together, no? Are you sure it's not just triggering like it's supposed to?
Pete S is offline  
Reply With Quote
Old 03-04-2008, 08:18 AM   #3
BenHeaton
Member
 
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

Hi Peter

Hmm. Pretty sure that's not the case. Iin historical data there is no way o knowing what came first within the same bar of data (the trade ebtry or the stop loss). To avoid this problem I'd be happy to just prevent the stop loss being set in the same bar of data as the opening of the trade, but not sure how to achieve that.

BH
BenHeaton is offline  
Reply With Quote
Old 03-04-2008, 08:59 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

If you do not want the stop loss to be submitted on the same bar as entry then do not use the SetStopLoss() method but instead call the ExitLongStop() or ExitShortStop() methods.
NinjaTrader_Ray is offline  
Reply With Quote
Old 03-04-2008, 10:18 AM   #5
BenHeaton
Member
 
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

Tks Ray - i'll do that - BH
BenHeaton is offline  
Reply With Quote
Old 03-04-2008, 11:41 AM   #6
BenHeaton
Member
 
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
Default

Its working! Tks Ray, pls ignore below..

BH

Hi Ray

I tried as you suggested, but am struggling to get the stops to activate at all now... I tried the following:

// Introduce stoploss
if (Position.MarketPosition != MarketPosition.Flat)
{ExitShortStop(Position.AvgPrice);
ExitLongStop(Position.AvgPrice);
}

The stops are never activated, even on loss making trades. Just to recap, all the opening trades are enterred into using EnterLongLimit() and EnterShortLimit() statements.

Tks for your help on this!

Ben Heaton
Last edited by BenHeaton; 03-04-2008 at 11:54 AM.
BenHeaton 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
Stop Losses not working? zoltran General Programming 2 11-08-2007 04:00 AM
Stop or Limit Orders? davidfw1866 ATM Strategies (Discretionary Trading) 3 11-07-2007 03:01 PM
Stop Limit Orders Quicktrader10 Miscellaneous Support 3 08-11-2006 07:05 AM
Negative Limit - Stop Limit Entry Orders biswar Automated Trading 1 10-18-2005 12:58 AM
Targets - Stop Orders or Stop Limit Orders? Nereus ATM Strategies (Discretionary Trading) 3 05-31-2005 07:13 AM


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