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
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.
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 arvidvanstaey, Today, 02:19 PM
|
4 responses
11 views
0 likes
|
Last Post Today, 04:08 PM | ||
Started by samish18, 04-17-2024, 08:57 AM
|
16 responses
61 views
0 likes
|
Last Post
by samish18
Today, 03:30 PM
|
||
Started by jordanq2, Today, 03:10 PM
|
2 responses
9 views
0 likes
|
Last Post
by jordanq2
Today, 03:23 PM
|
||
Started by traderqz, Today, 12:06 AM
|
10 responses
18 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
||
Started by algospoke, 04-17-2024, 06:40 PM
|
5 responses
48 views
0 likes
|
Last Post Today, 02:36 PM |
Comment