![]() |
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
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Junior Member
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,413
Thanks: 252
Thanked 976 times in 959 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Mar 2010
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you, Bertrand, this makes sense now.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |