Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy - how to stop strategy if certain profit is reached?
Collapse
X
-
Strategy - how to stop strategy if certain profit is reached?
Is there a way to turn off strategy from running if you make $50 or $100 or whatever? -
Hello MatthewLesko,
Thank you for your note.
It looks from the tags like you're referring to programming this into your own strategy, so I've moved this to our NinjaTrader 8 Strategy Development forum.
I'm attaching a basic Strategy Builder example strategy that works in real time only that uses a bool to stop entries from occurring after a set PnL has been reached. It would need to be disabled and re-enabled to resume taking trades.
We also have an example of doing this from a manually coded strategy in our help guide here:
Please let us know if we may be of further assistance to you.Attached Files
- Likes 1
-
Kate thanks sorry I missed this. So I'm wondering, my strategy may either profit me between $30 and $50 if I have 1 loss and then 1 win, otherwise it will profit me between $150 and $250 if I have one win.
So I'm thinking is there a way to just have a minimum realized profit?
Comment
-
Maybe I have a double type input/variable that is MinimumProfit and if cumulative realized profit is greater than that, then set to profit target reached?
Comment
-
I've got it setup I think but it's not triggering a trade when I add those conditions.
Would this be expected to work in Market Replay?
Comment
-
Hello MatthewLesko,
Thank you for your replies and I do apologize for the delay in my reply - we've just switched to a new system for our support tickets and have a bit of a backlog.
The above example would be expected to work on Market Replay data in the Playback connection, yes - it would not, however, show prior trades on the chart historically or work in the Strategy Analyzer.
Please let us know if we may be of further assistance to you.
Comment
-
Problem it still makes a trade if my realized pnl is equal to or less than my loss limit if the next bar meets condition for trade.
Comment
-
-
I think I've come up with a work-around.
For my initial condition set that does the order execution, I added this:
The second set is what sets my variable to stop trading depending on profit/loss.Code:&& (SystemPerformance.AllTrades.TradesPerformance.TradesCount < 2)
With this, I believe it will never make more than 2 trades, but if I have 2 potential trades back to back/bar to bar, if the first is profitable, it will not make a trade right after and will honor the minimum profit variable.
Comment
-
Lol ok so as I piecemeal this thing now i'm confused over number of taken trades and contracts.
If my strategy goes entry for 5 contracts, and I run this command for output:
It saysCode:Print("The strategy has taken " + SystemPerformance.AllTrades.Count + " trades.");Then the very next entry again is exactly 5 contracts and the output says it's taken 3 trades!?!"The strategy has taken 0 trades."
How exactly is it calculating the number of trades?
Comment
-
Hello MatthewLesko,
Thank you for your replies.
I would not expect the output for SystemPerformance.AllTrades.Count to be greater than 0 until at least one exit has been seen - a trade is comprised of an entry and an exit. Did any partial fills occur? If that happens, each partial fill would be counted as a separate trade.
Thanks in advance; I look forward to assisting you further.
Comment
-
So I think with the StopTradingAfterSetPnLExample, Set 1 and Set 2 in the conditions need to be swapped.
It appears, that Set 1 gets processed first, and Set 2 gets processed second.
Set 2 is where the variable gets set. So if your trade condition happens to occur more than 2 times right in a row upon bar close, the variable won't get set until after the 3rd trade, but by then, you are either way over your profit or loss limit so it makes no sense.
Swapping Set 2 with Set 1 makes more sense, as the realized profit is calculated first, and variable is set first, before trades can occur that relies on the variable.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
44 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
65 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment