From a strategy script, can I change the target in SetProfitTarget elsewhere other than ininitialize()?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Changing the Profit Target
Collapse
X
-
imported post
No, this method is not intended to dynamically changea profit target, from what I recall, will check on that.
Here is an option:
In replace of SetProfitTarget(),use an ExitLimit() within the OnBarUpdate() method itself. Just make sure youcall this method on each bar. Theupsideis you can change the price on each bar/tick. The downside is thatthe order will not be submitted until the followingbar/tick afterentry.
Example code:
private double targetPrice = 0;
private override void OnBarUpdate()
{
if (SMA(5)[0]> SMA(10)[0])
EnterLong();
targetPrice = Math.Max(targetPrice, Low[0]);
ExitLongLimit(targetPrice);
}
RayNinjaTrader Customer Service
-
imported post
Suzy,
Apparently it should work within the OnBarUpdate() method. Reviewing the code and running the test script below works.
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
if (Historical)
return;
EnterLong();
if (Position.MarketPosition == MarketPosition.Flat || BarsSinceEntry() < 3)
SetStopLoss(CalculationMode.Ticks, 10);
else
SetStopLoss(CalculationMode.Ticks, 5);
}
RayNinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
590 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
342 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
555 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment