Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily loss limit examples

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #61
    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.

    Comment


      #62
      Originally posted by NinjaTrader_ChelseaB View Post
      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

      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.
      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 help

      Comment


        #63
        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


          #64
          Wihich file is working in the above links? I am. trying to enable and it just doesnt work.

          Comment


            #65
            Hi Pavan, thanks for posting. All of the strategy files in the first post should be working properly. Could you please detail what exactly is not working? Are you not able to enable the strategy, or does it get enabled, but you are seeing unexpected output?

            Comment


              #66
              Can someone please advise best way to open those files as its doesn't add up for me?

              Comment


                #67
                Hello elic1968,

                To import a NinjaScript into NinjaTrader 8 do the following:
                1. Download the script to your desktop, keep it in the compressed .zip file.
                2. From the Control Center window select Tools -> Import -> NinjaScript...
                3. Click the Desktop icon on the left to navigate to the desktop
                4. Select the downloaded .zip file -> then click Open
                5. NinjaTrader will then confirm if the import has been successful.
                Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

                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


                  #68
                  Chelsea thanks. I'm aware of the process. Problem I cant download the file (not getting the option). Could you please place it once again?

                  Comment


                    #69
                    Hello elic1968,

                    I've added the links in post # 1.

                    As a heads up, you cannot download files from the forum until you have completed the registration process by clicking the link in the registration email.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #70
                      Hey Chelsea, I have downloaded the daily PnL script and have it as an independent strategy on my strategy builder strategies menu. What should I do in order to incorporate into an existing strategy that I have already structured?

                      Comment


                        #71
                        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

                        Comment


                          #72
                          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


                            #73
                            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.
                            Hello, I see in the documentation you have fixed: 15048 Added Adapter, Rithmic Updated Rithmic API to version 11.3.0.0 Can you elaborate on that please? Will OnOrderUpdate() OnExecutionUpdate() and OnPositionUpdate() be called in the expected order?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #74
                              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


                                #75
                                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, 03-30-2026, 11:51 AM
                                0 responses
                                26 views
                                0 likes
                                Last Post CarlTrading  
                                Started by CarlTrading, 03-30-2026, 11:48 AM
                                0 responses
                                26 views
                                0 likes
                                Last Post CarlTrading  
                                Started by CaptainJack, 03-25-2026, 09:53 PM
                                0 responses
                                30 views
                                0 likes
                                Last Post CaptainJack  
                                Started by CaptainJack, 03-25-2026, 09:51 PM
                                0 responses
                                18 views
                                0 likes
                                Last Post CaptainJack  
                                Started by Mindset, 03-23-2026, 11:13 AM
                                0 responses
                                29 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Working...
                                X