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 charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
61 views
0 likes
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
148 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
162 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
98 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
286 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|

Comment