NinjaTrader Support Forum  

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 10-09-2007, 11:03 AM   #1
pauljff
Junior Member
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
Default SetStopLoss & SetProfitTarget problem

I'm encountering a problem with these two functions. I'm not sure if it's a problem with the strategy code or the strategy analyzer. I'll create a simple strategy that has SetStopLoss/SetProfitTarget in Initialize(). Create orders with EnterLong() or EnterShort(). Backtest it in the Strategy Analyzer.

Everything will work fine for so many trades. Then it will ignore the StopLoss/ProfitTarget and keep a trade open for the rest of the backtest.

I've checked over the order log, everything looks ok. The Stops and Limits are being issued. Then I see "Profit Target, Stop Loss, Buy, Exit on Close." The exit on close price is far above the stop/profit level, like they were not there.

I wrote many simple strategies and all had this problem. I downloaded the sample code from http://www.ninjatrader-support.com/v...ead.php?t=3222

and it also failed in the exact same way.

Has anyone encountered this problem?
Last edited by pauljff; 10-09-2007 at 11:36 AM.
pauljff is offline  
Reply With Quote
Old 10-09-2007, 11:46 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Someone will follow up with you later today on this.
NinjaTrader_Ray is offline  
Reply With Quote
Old 10-09-2007, 02:04 PM   #3
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

That is very interesting pauljff. Does there seem to be a set number of trades before it starts messing up or does it seem like its random?

If you don't mind could you attach the log files and point me at the point of interest?
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-09-2007, 04:42 PM   #4
pauljff
Junior Member
 
Join Date: Oct 2007
Posts: 6
Thanks: 0
Thanked 0 times in 0 posts
Default

After fooling around with it for hours I think found the problem... in the Strategy analyzer "Time in Force" was set to "Day." I set it to GTC and my strategy worked fine. I'm guessing if the stop/profit orders weren't hit by the end of the trading day they expired, and then the position stayed open forever? (I am writing Strategies for Forex so end of day isn't a problem for me.)

Maybe add a warning to the manual (if there isn't already one) so no one else goes crazy fighting with this.
pauljff is offline  
Reply With Quote
Old 10-09-2007, 04:42 PM   #5
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

Glad to here you resolved this. Thanks for the suggestion.
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
SetStopLoss() and SetProfitTarget() SamIam Strategy Development 9 09-05-2007 08:49 PM
Currency in SetProfitTarget / SetStopLoss DarrylT Strategy Development 1 05-12-2007 10:54 AM
SetStopLoss and SetProfitTarget in Initialize FireFly Strategy Development 9 04-05-2007 11:52 PM
Exiting a position with SetStopLoss or SetProfitTarget SuzyG Strategy Development 8 04-02-2007 11:47 PM
SetProfitTarget() nolantx Automated Trading 1 02-08-2007 12:55 AM


All times are GMT -6. The time now is 01:12 AM.