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-14-2010, 09:53 PM   #1
trader.ilya
Junior Member
 
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
Default SetStopLoss and SetProfitTarget

Hi All,

I'm new to NJ, so please forgive me if this is not a very smart question.

I'm trying to modify a default crossover strategy that goes with NJ. I'd like to add stop and profit targets to this strategy.

In initialize() method I've added the following lines:
SetStopLoss(CalculationMode.Percent, 2);
SetProfitTarget(CalculationMode.Percent, 5);

In my onBarUpdate() I have the following:
bool isFlat = Position.MarketPosition == MarketPosition.Flat;

if (isFlat && CrossAbove(SMA(Fast), SMA(Slow), 1))
EnterLong();
else if (isFlat && CrossBelow(SMA(Fast), SMA(Slow), 1))
EnterShort();


I was assuming that the effect would be that after I enter long, the stop and profit targets would be set. But this does not seem to happen.

I'm working with EOD data from Yahoo.

Please, let me know what I'm doing wrong here.

Thanks.
trader.ilya is offline  
Reply With Quote
Old 03-15-2010, 04:48 AM   #2
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

Welcome to the forums - correct they should be 'set' if added this way, however for 2 and 5 percent you want to enter a value of 0.02 and 0.05, so this is likely the reason you don't see them getting 'hit' during testing.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 03-15-2010, 09:50 AM   #3
trader.ilya
Junior Member
 
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
Default Thanks

Thank you, Bertrand, this makes sense now.
trader.ilya 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 setprofitTarget Creamers General Programming 5 07-20-2008 12:40 PM
SetStopLoss & SetProfitTarget problem pauljff Strategy Development 4 10-09-2007 04:42 PM
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


All times are GMT -6. The time now is 06:54 AM.