![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Jul 2007
Location: Fairfax, VA
Posts: 216
Thanks: 0
Thanked 0 times in 0 posts
|
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?
|
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
Tks Ray - i'll do that - BH
|
|
|
|
|
|
#6 |
|
Member
Join Date: Jul 2007
Posts: 34
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |