![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
Hi there,
Got a little problem while programming my strategy, concerning the Profit targets. I want to make them dependent of the last bar. So, let's say, the profit target of a position should always be on the Open of the last bar. I have really no idea, how I should get this. Can anyone help me? Thanks in advance Sepp |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Sepp, you would need to adjust your Target value on each bar then, this sample should help - http://www.ninjatrader-support2.com/...ead.php?t=3222
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks for the link, but it didn't help me as much as I hoped... My problem is, that for example I go long, when the bar was red (and vice versa). Now, I want to take the profit at the Open of the bar before. I tried it with SetProfitTarget(CalculationMode.Price, Open[1]) but it doesn't work
![]() Can you help me again? Thanks in advance Sepp |
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Sepp,
Please provide the complete code snippet you are using. Thank you.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
Here it is:
Quote:
Regards, Sepp |
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Sepp,
You can't put it in Initialize(). Open[1] is not recognized there. You need to put it in OnBarUpdate().
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you very much, now it works better but still not as I want. The main problem now is, that once the Profit target is triggered, he sells only on the next bar.
I've put the SetProfitTarget now in a if (Market.Position == Long/Short) {SetProfitTarget(...)}, because he didn't do anything when I just wrote it into the code alone. Is there another way to set the target as soon as the position is opened? Regards, Sepp |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Sepp,
Not following you. When profit target is reached it will execute immediately. If it is not reached then nothing will happen. You should be calling your Set() method before you call your Enter() method.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
I still don't get it... Tried yesterday the whole evening... Here my code again:
Again my strategy: if a bar closes green, I want to sell short on the open of the next bar. The profit target for this example is the open of the last bar (the green bar e.g.) + 2% of the Close of the same bar. If the target shoulnd't be reached until the current bar closes, the position shall be closed. Can you help me? Thanks in advance again Sepp |
|
|
|
|
|
#10 | |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
Here's the code, cause he was too long for the other post:
Quote:
|
|
|
|
|
|
|
#11 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
MasterSepp, please try printing the values you set as targets, so they actually return what you expect. You also want to reset those values when you're flat, as mentioned in this sample - http://www.ninjatrader-support2.com/...ead.php?t=3222
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
First, I don't really understand, what you mean with "printing the values ... so they return what you expect"?
Second, I tried like in the PriceModification-Sample, but when I enter anything other than a number in the variables (for example Open[1]), he can't compile it correctly. Can you help me again please? Thanks in advance Sepp |
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
Sepp, I refererred to printing the value for the stop loss to loss to the output window with the Print command - http://www.ninjatrader-support2.com/...ead.php?t=3418
This way you can easily check the calculated values on each bar and if they turn out to be what you expect. What compile error do you receive in the Price modification sample?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Apr 2009
Posts: 195
Thanks: 0
Thanked 0 times in 0 posts
|
I don't think, that I have to use the print command, because I think to know what the system does
My 2 main problems are just that the position is closed when it's hold longer than one bar. Second problem: the "complicated" profit target. My NT is in German, so I can tell you the exact problem, but the Codes are CS0120 and CS0266. Here the excerpt of the code:#region Variables privateint profittargetprice = Open[1]; #endregion ///<summary> /// This method is used to configure the strategy and is called once before any strategy method is called. ///</summary> protectedoverridevoid Initialize() { SetProfitTarget(CalculationMode.Price,profittarget price); CalculateOnBarClose = true; } |
|
|
|
|
|
#15 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
|
On the compile error, please try SetProfitTarget
Code:
(CalculationMode.Price,profittargetprice);
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Profit Target | tooearly | Automated Trading | 1 | 02-05-2009 05:49 AM |
| Profit target in a strategy | ju1234 | Strategy Development | 9 | 12-15-2008 07:22 AM |
| Profit target | Charlie | ATM Strategies (Discretionary Trading) | 4 | 11-19-2008 10:32 AM |
| Profit Target? | Ninja B | Automated Trading | 4 | 08-04-2008 12:09 PM |
| Profit target | maninjapan | Strategy Development | 11 | 05-19-2008 07:41 AM |