Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Daily Profit/Loss limit
Collapse
X
-
Daily Profit/Loss limit
Found a few posts on this and tried a couple with no success. Just looking for a simple way to flatten everything when Daily PL(Realized and unrealized combined) hit a certain amount. I restart my platform daily so I'm not worried about it resetting each day or anything, thanksTags: None
-
Hello Steve4616,
As this is posted in the Strategy Development section of the forums, I am assuming you are programming a NinjaScript Strategy in C#.
Below is a link to an example that will submit an exit order to exit the strategy position and prevent new entries until the next session after the PnL level is reached.
Hello, I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8. These are often requested and I felt they are good examples to have for NT8. DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241 (http://ninjatraderChelsea B.NinjaTrader Customer Service
-
Thanks Chelsea, Sorry I probably posted in the wrong section. The link you posted, the DailyLossLimitBuilder is the exact one i tried. Unfortunately, I can't get it to enter the trades like my other strategy. On the set where you added the long entry, I added my conditions, and same for short entry, but it seems to only take the first trade or 2 then holds them almost all day, completely ignoring the conditions for opposite entry.
Also, I am running multiple strategies, so I'm just looking for an easy way to flatten everything once the daily profit target is met. If i get this working, and put it on each strategy, will they all work together and flatten everything once the daily target is met? Thanks
Comment
-
Hello Steve4616,
Is the DailyLossBuilderExample not making trades or is your custom script not making trades?
The DailyLossBuilderExample uses an SMA cross to flip from long to short and vice versa, and then stops placing new entries once the DailyPNL is less than or equal to DailyLoss.
I've put this on a 1 minute ES 06-22 1 minute chart and I am finding this is making multiple trades.
Regarding a custom script, to understand the behavior add prints.
Print the time of the bar, and print all values used in the condition. Print is demonstrated in DailyLossBuilderExample.
Below is a link to a forum post on using Print() to understand behavior. See the video 'Debugging using prints with the Strategy Builder'.
Chelsea B.NinjaTrader Customer Service
Comment
-
Hi Chelsea, sorry I just revisited this. Working on it right now, just curious, if i load the strategy on todays chart, will it stop showing the trades after it hit the daily profit target? Also, do my strategy need to be "OnEachTick" or "OnStateChange" for the daily PL to flatten everything once the daily target is met?(As in, if I'm "OnBarClose", does that mean i need to wait til the bar closes before it will flatten everything?). Thanks man, I appreciate the help
Comment
-
ok heres my issue. several days are loaded. So at the start time, it enters a couple trades then stays open til my "flatten" time(There are multiple entries after those trades that it does not take). I have added a set in the strategy "if current market position is long, and DailyPNL is Greater than Daily PL, exit long(and same for short), no difference. I might end up emailing you the code for you to have a look but wanted to try here first1 Photo
Comment
-
Hello Steve4616,
Thanks for your note.
This is Brandon responding on behalf of Chelsea who is out of the office at this time.
I understand that your other strategy does not place entries in the same way as the DailyLossLimitBuilderExample script that Chelsea linked in a previous post.
The example strategy that Chelsea linked to will work differently than your custom strategy unless your strategy is programmed exactly the same as the example. If you need your strategy to work similar to the example strategy, you would need to work with the sample directly to learn how the script works and then make those logic modifications in your strategy.
"will it stop showing the trades after it hit the daily profit target?"
Yes, the strategy would stop trading once the daily profit target is reached.
"Also, do my strategy need to be "OnEachTick" or "OnStateChange" for the daily PL to flatten everything once the daily target is met?(As in, if I'm "OnBarClose", does that mean i need to wait til the bar closes before it will flatten everything?). "
This would ultimately depend on your script. You could view the example strategy, DailyLossLimitBuilderExample, to check which Calculate setting the strategy defaults to in order to know how changing the Calculate mode may affect the logic of the strategy.
Note that when you run the strategy with a Calculate mode of OnBarClose, the strategy OnBarUpdate() method will process only at the close of each bar. Running the strategy with a Calculate mode of OnEachTick means that the strategy would calculate intrabar for each incoming tick that occurs.
Calculate: https://ninjatrader.com/support/help.../calculate.htm
Also, note that when using multiple strategies this logic would need to be added for each individual strategy that is being used since strategies are not able to see other strategy's positions.
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Thanks Brandon. What i did was used the sample and where Chelsea put his entry criteria(was an EMA crossover i believe) i just deleted that and put my entry criteria in. The only other changes i made was i added a couple sets to flatten all positions at a certain time. This strategy works well by itself, but wont with the daily PL for some reason
Comment
-
Hello Steve4616,
Thanks for your note.
As stated by Chelsea in a previous post, debugging steps would need to be taken to determine how the strategy is behaving. Once you understand how the strategy is behaving and placing orders, you could modify the logic in your script.
"Regarding a custom script, to understand the behavior add prints.
Print the time of the bar, and print all values used in the condition. Print is demonstrated in DailyLossBuilderExample.
Below is a link to a forum post on using Print() to understand behavior. See the video 'Debugging using prints with the Strategy Builder'.
https://ninjatrader.com/support/foru...121#post791121"
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
I believe i found one of the issues. In the builder example, somehow Chelsea was able to set "YesterdaysPL", and "Strategy Total PL" yet they are not listed in the "varibles" of the strategy. How is that possible? At first when i seen this i thought it was just an option under Misc and because i don't need the PL to reset each day(Because i shut everything down every day) i thought i could just set this up without the example. Another issue i have is the strategy only has "DailyLoss", so i created a "DailyProfit" user input(along with a TimeStart, TimeEnd and Quantity. So I'm still not sure why it doesn't work. I never get anywhere with debugging so i haven't messed with it yet but i will try it at some point, thanks2 Photos
Comment
-
Ignore my post about the variables, I found them under "custom series". On a side note, can we put in a ticket to have the option to click a box in "Tools" and then set a "Total Daily Profit(Realized and unrealized combined) and a "Total Daily Stop loss" in ticks or currency? I feel like most traders would use this, as it is an important step in any trading strategy. Also, more and more people are using multiple automated strategies so it seems convenient if this was an option, thanks
Comment
-
When I load this strategy on 1min NQ it does make multiple trades, but once it hits the DailyLoss, it stays in that trade until End of session. Can you check to see if you get this too? ThanksOriginally posted by NinjaTrader_ChelseaB View PostHello Steve4616,
Is the DailyLossBuilderExample not making trades or is your custom script not making trades?
The DailyLossBuilderExample uses an SMA cross to flip from long to short and vice versa, and then stops placing new entries once the DailyPNL is less than or equal to DailyLoss.
I've put this on a 1 minute ES 06-22 1 minute chart and I am finding this is making multiple trades.
Regarding a custom script, to understand the behavior add prints.
Print the time of the bar, and print all values used in the condition. Print is demonstrated in DailyLossBuilderExample.
Below is a link to a forum post on using Print() to understand behavior. See the video 'Debugging using prints with the Strategy Builder'.
https://ninjatrader.com/support/foru...121#post791121
Comment
-
Hello Steve4616,
Thanks for your note.
The DailyLossBuilderExample script does not contain logic to exit a current position when the daily loss limit is reached. The strategy simply stops placing trades once this limit is reached.
If you would like your strategy to exit the current position when the daily loss limit is reached, you would need to add logic to your strategy that checks for the daily loss limit being reached and then call an exit method, such as ExitLong()/ExitShort() to exit your current position.
Let us know if we may assist further.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Thanks Brandon. It now exits, but not the correctly. The biggest thing is that the platform isn't recognizing "TotalPL", on "Realized". So instead of it stopping on the way up in a trade at the daily profit target, it will always close that trade due to the indicators, not the TotalPL. I sent an email, probably better because then I'll end up sharing my actual strategy as well, thanks again
Comment
-
Hello Steve4616,
Thanks for your note.
I understand that you would like to get a total PnL by adding together the Realized PnL (StrategyTotalPNL[0]) and the Unrealized PnL (Strategy folder > Unrealized PnL).
Note the Realized PnL will only update once a trade has been exited. If the trade has not exited then the Realized PnL would not be included/updated.
You could add a custom Series named something like TotalUPnL. Then in Set 1, you could add together StrategyTotalPNL[0] and the Unrealized PnL (Strategy folder > Unrealized PnL) to get a total PnL and assign that to your TotalUPnL custom series. You could then use that custom series for exit conditions in your script.
See the attached screenshots demonstrating this.
Ultimately, debugging steps would need to be taken to understand how the script is processing.
To understand why the script is behaving as it is, such as placing orders or not placing orders when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.
In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).
Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.
Below is a link to a forum post that demonstrates how to use prints to understand behavior.
https://ninjatrader.com/support/foru...121#post791121
Please let me know if I may further assistLast edited by NinjaTrader_BrandonH; 04-12-2022, 09:06 AM.<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
139 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|
Comment