Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Daily loss limit examples
Collapse
X
-
Hi tkaboris, thanks for writing in. Its best to override OnPositionUpdate because this event triggers when there is any change in the strategy position. It can be done in OnOrderUpdate but you would need some extra steps such as checking the current and last position held, also checking if the order is an exit order or an entry order, and so on. You can add OnPositionUpdate to your script.
-
Hi, thank you for this great example. Could you tell me how to set formula on a "do the following" for my Custom serie ? i only succeed in setting the 0 value but not +1 on the last value Thank you for your helpOriginally posted by NinjaTrader_ChelseaB View PostHello,
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
DailyLossLimitMultiTradeExample_NT7 - http://ninjatrader.com/support/forum...367#post475367
Update Sep 4th, 2018:
- I realized the print in OnPositionUpdate should print when currentPnL is equal to less than the LossLimit, not just less than it.
Update July 13th, 2020:
- Added DailyLossLimitBuilderExample_NT8; NinjaTrader_PaulH was clever enough to realize the Strategy Builder custom series can be used with offsets to do math and subtract the total pnl from yesterdays pnl to get the current pnl and provided an example.
Comment
-
Hi rht5692, for questions related to help with customizing an example, please create a new topic and explain your question in as much detail as possible. It is going to be difficult to answer your question and understand the trouble you are having with this little detail about your question in this post.
Comment
-
Comment
-
Hello elic1968,
To import a NinjaScript into NinjaTrader 8 do the following:- Download the script to your desktop, keep it in the compressed .zip file.
- From the Control Center window select Tools -> Import -> NinjaScript...
- Click the Desktop icon on the left to navigate to the desktop
- Select the downloaded .zip file -> then click Open
- NinjaTrader will then confirm if the import has been successful.
Below is a link to the help guide on importing NinjaScripts.
https://ninjatrader.com/support/help...-us/import.htm
The DailyLossLimitMultiTradeExample_NT8 and DailyLossLimitExample_NT8 can be viewed in the NinjaScript Editor.
New -> NinjaScript Editor -> Strategies -> DailyLossLimitExample.
The DailyLossLimitBuilderExample_NT8 can be viewed in the Strategy Builder.
New -> Strategy Builder -> select DailyLossLimitBuilderExample from the drop-down on the Welcome page.
These strategies can be run on a chart or backtested in the Strategy Analyzer.
Chelsea B.NinjaTrader Customer Service
Comment
-
Hello elic1968,
Our examples are created for you to learn from. They are not intended to be actually traded.
Please open the script in the Strategy Builder and learn from the logic implemented in the Conditions and Actions so that you fully understand how the script works.
Once you have an understanding of how the script works, use that knowledge to create your own script with your own custom logic.Chelsea B.NinjaTrader Customer Service
- Likes 1
Comment
-
The script "DailyLossLimitMultiTradeExample_NT8" is completely losing accuracy when trading more than 1 contract according to logic below (where Contract1s=3, Contracts2=2, etc. )
if (entryOrders[1] == null) {entryOrders[1] = EnterLong(Convert.ToInt32(Contracts1), @"LongTP1");}
if (Contracts2 != 0 && TP2 > 0) {if (entryOrders[2] == null) {entryOrders[2] = EnterLong(Convert.ToInt32(Contracts2), @"LongTP2");}}
if (Contracts3 != 0 && TP3 > 0) {if (entryOrders[3] == null) {entryOrders[3] = EnterLong(Convert.ToInt32(Contracts3), @"LongTP3");}}
Do you know why it happens? Especially when 3 (4 or 5...) contracts order is not filled at once but is filled partially.​
Comment
-
Hello cpppower,
Welcome to the NinjaTrader forums.
In the DailyLossLimitMultiTradeExample the currentPnL is assigned the trade profit (thisTrade.ProfitCurrency) one line 120 which would be for all contracts.
This is added with the Position.GetUnrealizedProfitLoss() of the position, for all contracts.
Testing this original script on my end I am not seeing any unexpected behavior.
Note, partial fills will cause separate trades to appear in the SystemPerformance collection. You may want to only add the PnL of a trade once the exit order has fully filled.
With your custom script, add prints to find out what is incorrect.
https://ninjatrader.com/support/foru...121#post791121
This example linked below, also has some sample code for working with part fills.
Chelsea B.NinjaTrader Customer Service
Comment
-
Many thanks for your replay!
Many thanks for your reply! I think I have found the reason for lack of accuracy at my end.
My strategy is running onEachTick and I use "DailyLossLimitMultiTradeExample" to exit currently running position when the total daily loss/profit reaches certain level.
But when the strategy reads this data (currentPnL + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0])) <= (-LossLimit)) to close running position it is always late (unaccurate).
And here is my concerne: Close[0] in this example (when strategy works onEachTick) refers to current price or it is waiting for bar close?​
Comment
-
Hello cpppower,
When Calculate is OnEachTick in realtime Close[0] refers to the current price (the close of the building bar is the current price).
In historical without tickreplay this is the close of the previously most fully closed bar. With TickReplay this is the current price.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, Yesterday, 09:41 PM
|
1 response
14 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
31 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
30 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|
||
|
Started by CaptainJack, 03-25-2026, 09:53 PM
|
0 responses
34 views
0 likes
|
Last Post
by CaptainJack
03-25-2026, 09:53 PM
|
||
|
Started by CaptainJack, 03-25-2026, 09:51 PM
|
0 responses
19 views
0 likes
|
Last Post
by CaptainJack
03-25-2026, 09:51 PM
|

Comment