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 cmtjoancolmenero, Yesterday, 03:58 PM
|
6 responses
28 views
0 likes
|
Last Post Today, 08:55 AM | ||
Started by gbourque, Today, 06:39 AM
|
2 responses
14 views
0 likes
|
Last Post
by gbourque
Today, 07:05 AM
|
||
Started by rexsole, Today, 08:39 AM
|
0 responses
4 views
0 likes
|
Last Post
by rexsole
Today, 08:39 AM
|
||
Started by trilliantrader, Yesterday, 03:01 PM
|
3 responses
31 views
0 likes
|
Last Post Today, 08:28 AM | ||
Started by Brevo, Today, 01:45 AM
|
1 response
14 views
0 likes
|
Last Post Today, 08:14 AM |
Comment