Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Change the value in SetProfitTarget?
Collapse
X
-
Hello,
You should be able to call SetProfitTarget in OnBarUpdate and even change the value of SetProfitTarget in OnBarUpdate.
What error do you receive when entering SetProfitTarget in OnBarUpdate?
Another note on this is if you are using it in OnBarUpdate you will need to make sure it is not in Initialize. SetProfitTarget can not be in Initialize or another method but never in Initialize() and another method.Cody B.NinjaTrader Customer Service
-
When I used it in OnBarUpdate(), the strategy didn't run. I thought it couldn't be run in there, so I didn't think the problem might be on my end. I'll check my code then.
I'm trying to use the Swing() to get the highs and lows and use those values to get a profit taker target in ticks. And I was converting the difference of high and low to int. So it must be from there.
I'm using Convert.ToInt32(high-low). Is there something better to use?
Comment
-
This is for ES, so .25 per tick
With this, the code wouldn't run. If I disable these code, it runs.Code:double High = Swing(5).SwingHigh[0]; double Low = Swing(5).SwingLow[0]; ProfitTgt = Convert.ToInt32((High - Low) * 4); SetProfitTarget("Long", CalculationMode.Ticks, ProfitTgt);
Comment
-
Hello,
I have provided how you would do this in my example below.
Please let me know if you have any questions.
Code:protected override void OnBarUpdate() { EnterLong("Long"); if(Position.MarketPosition != MarketPosition.Flat) { double High = Swing(5).SwingHigh[0]; double Low = Swing(5).SwingLow[0]; ProfitTgt = Position.AvgPrice + (High - Low); SetProfitTarget("Long", CalculationMode.Price, ProfitTgt); } }Cody B.NinjaTrader Customer Service
Comment
-
Hello,
To debug this please enter in the following Print statement.
You can then view the printed statement when running the strategy by going to Tools> Output Window.Code:Print("Average Entry Price is" + Position.AvgPrice );
Does the average price printout to always be 1863.25 or do you see other prices?Cody B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
105 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
53 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
36 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
38 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
74 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment