Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Daily loss limit examples

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

    #31
    Originally posted by NinjaTrader_Jim View Post
    Hello Trader17,


    If you change the strategy to Calculate.OnEachTick or OnPriceChange, line 53 if (Bars.IsFirstBarOfSession) will be true for each tick of that bar. I would suggest adding an IsFirstTickOfBar check with that condition to ensure it only happens once on that bar.

    Please let us know if you have any questions.
    Thank you. In this statement for Line 53 I would leave it as is because the PnL is reset each day on the first session bar, correct? And I add IsFirstTickOfBar in the logic itself to prevent calculation more than once for the last closed bar. Correct?

    Thanks a lot.

    Comment


      #32
      Originally posted by NinjaTrader_Jim View Post
      Hello Trader17,

      Bools return a true or false value and checking if (YourBool == true) is equivalent to checking if(YourBool). It can be very helpful and will at times be necessary to test out the concept to observe the behavior. For example, you could create a couple conditions that print a message if the condition becomes true.

      if (IsFirstTickOfBar) Print("Condition 1 This is true"");

      if (IsFirstTickOfBar == true) Print("Condition 2 This is true");

      We look forward to being of further assistance.
      So are both correct for Ninja Script? I know == True is meaningless as it is what is returned upon checking the logic.
      Thank you.

      Comment


        #33
        Hello Trader17,

        There will be countless questions in regards to what is possible with C#/NinjaScript and what is correct syntax. It will be necessary for you as an individual working on the script to test your questions to see if what you think you have written is correct or if it is not. For that reason, I will leave the question presented in #32 as an exercise to you. Please set up test conditions similar to my reply in which you have quoted. Testing this will be a straightforward answer to your question that you can set up on your end.

        Thank you. In this statement for Line 53 I would leave it as is because the PnL is reset each day on the first session bar, correct? And I add IsFirstTickOfBar in the logic itself to prevent calculation more than once for the last closed bar. Correct?
        If you add a check for IsFirstTickOfBar to the condition on line 53 in Chelsea's script and change the script to use Calculate.OnPriceChange or Calculate.OnEachTick, then you will restrict the code to only reset the daily PnL once, and not multiple times per bar.

        Many of these questions will be best answered by testing on your own. Our role is not to provide examples that perform multiple tasks so you can copy and use in your custom works, but to educate you on how each concept works. My recommendation would be to start with simple test scripts so you can get used to working with scripts that calculate OnEachTick or OnPriceChange, and then once you have mastered these concepts, combine the behavior with the Daily Loss example.

        We look forward to being of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #34
          Originally posted by NinjaTrader_Jim View Post
          Hello Trader17,

          If you add a check for IsFirstTickOfBar to the condition on line 53 in Chelsea's script and change the script to use Calculate.OnPriceChange or Calculate.OnEachTick, then you will restrict the code to only reset the daily PnL once, and not multiple times per bar.

          We look forward to being of further assistance.
          Thanks. I was going to leave Line 53 as is with Calculate set to Each Tick and just use Is First Tick of Bar in the condition logic to restrict it from calculating entry logic on each tick. And Script will still recognize the first bar of session with calculate set to calculate on each tick, correct?

          Or to reset the PnL only once while using Calculate on Each Tick if I use Is First Tick of Bar and First Bar of Session keeps it from resetting on every tick in the first session bar as you mentioned. So as long as a tick is traded in the new session it assumes it is the first bar of session without waiting for it to close and we are calculating on each tick it will reset the PnL to zero only once, correct?

          Thank you.
          Last edited by Trader17; 04-17-2019, 01:55 PM.

          Comment


            #35
            Now when this is used in a strategy it calculates the PnL on all trades for the day including historical trades. What if I want to start it for just a couple of hours anytim I wish and have the PnL start from zero at that point? Anything in Script that can prevent calculating historical trades for the day till I start it?
            Thank you.

            Comment


              #36
              Hello Trader17,

              I noticed that you also have a ticket open regarding this item with my colleague, Kate, over email. We ask that you continue working with the current technician assigned to your ticket without opening a new ticket. This helps us to ensure that the same technicians are not working on the same items which improves our ability to serve all of our clients.

              Thanks. I was going to leave Line 53 as is with Calculate set to Each Tick and just use Is First Tick of Bar in the condition logic to restrict it from calculating entry logic on each tick. And Script will still recognize the first bar of session with calculate set to calculate on each tick, correct?
              We should be clear that our role is not to provide recommendation for modifying single lines of code. Our role is to provide educational information on how to use the software. As with learning any new language there will be a necessary level of testing to understand how to work with that language. This sort of hypothetical question would be best answered by testing with prints to see the behavior yourself.

              Or to reset the PnL only once while using Calculate on Each Tick if I use Is First Tick of Bar and First Bar of Session keeps it from resetting on every tick in the first session bar as you mentioned. So as long as a tick is traded in the new session it assumes it is the first bar of session without waiting for it to close and we are calculating on each tick it will reset the PnL to zero only once, correct?
              The first bar of a session is determined by the Trading Hours template. The first tick of that bar will have IsFirstTickOfBar == true and Bars.IsFirstBarOfSession == true. This is another item that would be best answered by testing with prints to observe the behavior.

              Now when this is used in a strategy it calculates the PnL on all trades for the day including historical trades. What if I want to start it for just a couple of hours anytim I wish and have the PnL start from zero at that point? Anything in Script that can prevent calculating historical trades for the day till I start it?
              You can have the strategy return from historical processing in OnBarUpdate with if (State == State.Historical) return;

              Please understand that while we are here to assist you on your journey, our support services are not equipped to handle large numbers of questions that involve confirming a concept, and many such items are best understood through testing. If you have any additional questions, please attach the debug prints you are using and the output received so we can offer further direction to help you test these items to better understand these concepts.

              We look forward to being of further assistance.
              JimNinjaTrader Customer Service

              Comment


                #37
                Hello,
                Does anyone know the status of the "loss limit tool for NinjaScript Strategies" ID# SFT-2936 and a link to track its progress or release? An indicator that stops my trades if I gain or loose set mounts would be a major improvement to my stratagies!
                Thank you!

                Comment


                  #38
                  Originally posted by JonTansey View Post
                  Rookie question here. How do I view the DailyLossLimitExample_NT8.zip (1.6 KB, 1 view) once I import it?
                  After Import it you have to enable the strategy on your chart or you can try to understand the logic of the script with the ninjascript editor and copy it on your own strategy

                  Comment


                    #39
                    Hello jpatri,

                    There is no ETA and feature requests are tracked internally as the requests often contain internal discussion which we would not want to have public facing.

                    Feature Request Disclaimer.

                    We receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing.

                    When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number will be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.

                    Release Notes -
                    https://ninjatrader.com/support/help...ease_notes.htm

                    Let us know if you have any questions.
                    JimNinjaTrader Customer Service

                    Comment


                      #40
                      Hey everyone, I'm curious if it's possible to do something like this directly inside the strategy builder without manually coding it? For instance if I have a strategy working properly from the Strategy Builder, is there a way to allow for the ability of a daily loss limit or profit limit with a combination of the strategy builder parameters?

                      TIA

                      Comment


                        #41
                        Welcome to the forums TheTradingNetwork!


                        There would not be a parameter to add, the logic will have to be created in the Strategy Builder. Please see post 1 for the DailyLossLimitMultiTradeExample_NT8 example to see how this logic can be set up.

                        We look forward to assisting.
                        JimNinjaTrader Customer Service

                        Comment


                          #42
                          I'm looking for a more streamlined version of the max account profit and loss strategy. I start each day with clean new strategy enabled so my currentpnl is always starting at 0. I see there is mention above of a much easier version if each day already starts at 0, but don;t see any link to one. Anyone have one?

                          Comment


                            #43
                            Hi,

                            Thanks for the example. Just curious if theres a calculate on each tick example available?

                            Also, can you please explain what this line is for?

                            Code:
                            entryOrders = new Order[3];
                            when set to 3, I receive an error in the output window "Error on calling 'OnBarUpdate' method on bar 1934: Index was outside the bounds of the array"

                            I have 3 entry orders per direction.

                            when set to 7 the strategy runs, but the results and daily loss math don't seem to add up correctly.

                            Thanks!

                            Comment


                              #44
                              Hello howardtrade,

                              If you set the strategy to calculate OnPriceChange or OnEachTick, OnBarUpdate will update with each tick or price change after it is processing realtime data. Please note that BarsAgo 0 references would then reflect the developing bar rather than the bar that has just closed. If you need to separate logic in an OnEachTick/OnPriceChange strategy so it happens on bar closures, you can use IsFirstTickOfBar and check BarsAgo 1 references to get the bar close values when a bar closes.

                              IsFirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

                              Without making modifications to DailyLossLimitMultiTradeExample, we do not get an error on line 63 "entryOrders = new Order[3];" This creates an array of orders which is used in the strategy for order tracking. If you would like to learn more about arrays, I suggest reviewing publicly available C# materials on arrays. If you would like to learn more above using Order objects, I suggest reviewing the SampleOnOrderUpdate strategy and associated documentation.

                              Arrays (publicly available C# resource) - https://www.tutorialspoint.com/csharp/csharp_arrays.htm

                              SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

                              We look forward to assisting.
                              JimNinjaTrader Customer Service

                              Comment


                                #45
                                Originally posted by NinjaTrader_ChelseaB View Post
                                Hello Trader17,

                                I have received tracking ID# SFT-2936 for this request for a daily loss limit built into NinjaScript Strategies.

                                Please note it is up to the NinjaTrader Development to decide if or when any request will be implemented.

                                We appreciate your feedback on this.
                                Did this ever get developed? If not, can we change the request to include a Daily Profit to it as well. Would be nice to just go to "Options" under "Tools" and select which account, and then a daily profit target and a daily stop loss. If either is met(Realized + Unrealized) then it flattens all positions and disables all the strategies for that account

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Jon17, Today, 04:33 PM
                                0 responses
                                1 view
                                0 likes
                                Last Post Jon17
                                by Jon17
                                 
                                Started by Javierw.ok, Today, 04:12 PM
                                0 responses
                                6 views
                                0 likes
                                Last Post Javierw.ok  
                                Started by timmbbo, Today, 08:59 AM
                                2 responses
                                10 views
                                0 likes
                                Last Post bltdavid  
                                Started by alifarahani, Today, 09:40 AM
                                6 responses
                                41 views
                                0 likes
                                Last Post alifarahani  
                                Started by Waxavi, Today, 02:10 AM
                                1 response
                                21 views
                                0 likes
                                Last Post NinjaTrader_LuisH  
                                Working...
                                X