Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
daily loss limit in strategy builder
Collapse
X
-
Hello 37s29nala,
Thank you for your post.
Here's an example script a former colleague of ours created that should help. It's a little tricky to do this in the Strategy Builder, but you can if you use a custom series to track the current Strategy PnL. I'd advise importing this and then opening a new Strategy Builder window. On the first screen, find "DailyLossLimitBuilderExample" in the list and from there you can use the Builder navigation buttons to view the necessary logic.
Please let us know if we may be of further assistance to you.Attached Files
-
Hello 37s29nala,
Thank you for your reply.
It should not be copied and pasted, it should be imported into NinjaTrader and then you can open a new Strategy Builder window, select "DailyLossLimitBuilderExample" from the dropdown on the first page, and then you can use the navigation buttons to view how the logic is set up.
Note — To import NinjaScripts you will need the original .zip file.
To Import:- Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
- From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
- Select the downloaded .zip file
- NinjaTrader will then confirm if the import has been successful.
Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
Once installed, you may add the strategy to a chart to test with the Sim101 account by:- Right-click your chart > Strategies... > Select the Strategy from the 'Available' list on the left > Add > Check the Enable checkbox on the right > OK
Comment
-
Hey Kate,
Jumping in here.
I ran this strategy by itself through the strategy analyzer to verify that it worked. One of the things that I noticed was that the Net Profit column in the strategy analyzer was still showing days that had -$7,000 or more, while the daily loss was set at -100. That doesn't make sense. Shouldn't the daily loss prevent a net loss greater than -$100?
Is there some setting in the Strategy Analyzer that I am missing, or is there something that I am missing in the process? I am just trying to stop the strategy from losing a lot of money on it's bad days. Please help!Last edited by 102531911197541600524:NTB; 05-26-2024, 03:05 PM.
Comment
-
Hello,
Thank you for your post.
The actual PnL of the strategy does not have to match the amount for the DailyLoss you have set in code - this is is just the limit to prevent the following trade.
As an example, if you enter and it goes bad and the PnL of that trade is -300 when it's closed, then the next trade won't be submitted because it is past the limit. However, the actual PnL is -300 which is what the Analyzer is reporting.
If you take a look at the output of the script, you can see once your DailyLoss has been hit no further trades are taken until the next trading day.
If you want the analyzer to only show losses of 100, you would need to add additional code to check the unrealized PnL while in a trade and check if it is past -100, then close the trade.
Please let us know if you have any further questions.
Comment
-
"Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'[/B]"Originally posted by NinjaTrader_Kate View PostHello 37s29nala,
Thank you for your reply.
It should not be copied and pasted, it should be imported into NinjaTrader and then you can open a new Strategy Builder window, select "DailyLossLimitBuilderExample" from the dropdown on the first page, and then you can use the navigation buttons to view how the logic is set up.
Note — To import NinjaScripts you will need the original .zip file.
To Import:- Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
- From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
- Select the downloaded .zip file
- NinjaTrader will then confirm if the import has been successful.
Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
Once installed, you may add the strategy to a chart to test with the Sim101 account by:- Right-click your chart > Strategies... > Select the Strategy from the 'Available' list on the left > Add > Check the Enable checkbox on the right > OK
Well I accidentally pressed yes. is there any way to revert back?
Comment
-
Yep I installed only those scripts. Thank youOriginally posted by NinjaTrader_Gaby View PostHello,
There is no way to revert back - you may need to do a clean install to restore them to the default versions. However, if you simply installed the script posted by Kate then there is nothing to worry about as the script she posted did not change any of these default scripts.
Comment
-
How does this strategy know to stop at a daily profit limit? It appears to only be tracking the daily loss and is trading as long as the loss limit is not hit. It seems that the desired profit could be hit but it would keep trading and possibly move back into the red after hitting profit limit earlier? Also, I am cloning this strategy and adding my own conditions, is this the proper way to copy this strategy example and track daily PNL and trade within those limits?
Comment
-
You would just need to keep track of the number of whatever number you wanted to use. You can keep track of how many trades you take, how many contracts, time of day. So if you wanted to limit trades to number of trades per day, say three per day, you would need to add that to your entry conditions. So to enter a trade, if your entry conditions are present, and the amount of trades taken are not greater than your max number of trades, you take the trade. I don't really use strategy builder, but I would assume it shouldn't be difficult to add this with that. If you are coding manually, you can definitely do it.Originally posted by JMont1 View PostIs it possible to also limit trades per day by quantity of trades? Some strategies will take way too many trades in a day if it is very simple logic. Rather than limit by PnL, it would be helpful if the quantity of entries could be limited.
Thank you!
Comment
-
rockmanx00Thank you for your response. THis should have been more explicit that it is for Strategy Builder since I am not a coder.
In a general interest, and if I unlocked the code, is there a NT8 count that can be called? Or it is a simply a variable created in the code?
I hope a Super Moderator will respond about the Strategy Builder.
Good trading ALL !!!
Comment
-
If you are using strategy builder, I feel you should be able to create your own integer variables and use that to keep track of what you want. For example, if you want to keep track of max trades, you can create a tradesTaken variable and a max trades variable. you need to add to your tradesTaken variable after every trade you take and add the condition for your max trades when you enter trades.
Comment
-
rockmanx00 You are correct. I was coming back to the thread to delete my post after thinking thru your advice. Very much appreciated it and your follow up.
Good Trading ALL !!!
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
85 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
47 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
29 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
32 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
67 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment