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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
43 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
21 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
30 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
50 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
42 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment