Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to LIMIT loss and daily gain?

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

    How to LIMIT loss and daily gain?

    Good Morning,
    I am designing a strategy with the Strategy Buider of NinjaTrader 8.

    I need to program something very simple, however, I have been looking for information on the website of NinjaTrader and in the forum, support etc and I can not find it.

    I want to set a limit of daily loss and another of daily gain for my strategy (independent of other possible strategies in operation).

    That is to say,
    I want to:

    1. when the cumulative loss of the day is -200 $, the strategy or the robot disconnects or stops working until the next day or session
    and on the other hand,

    2. that when the accumulated profit is $ 400, the strategy or the robot is disconnected or stops working until the next day or session.

    It is very important to me your help please.
    Thank you very much and greetings
    NATALIA

    #2
    Hello danakede,

    Thanks for your post and welcome to the NinjaTrader forums!

    You can accomplish your goal using the strategy builder, however, you would need to start/stop your strategy on a daily basis in order to correctly access the strategies realized PNL. Otherwise, the strategy PNL will continue to accumulate as it is not reset.

    What you would need to do is to create a bool variable (initially set to true) that is set false when you are greater than or equal to 400 or are less than or equal to -200. The bool variable then can be a part of each set that has an entry condition. This means that if the realized PNL is >= 400 or is <= -200 the bool will be set to false and no further orders can occur because the bool is set to false and to trade you need the bool to be true.

    You would create the bool variable in the "Variables" section of the Inputs and variables screen. As a suggestion, you might use the name of "OkToTrade" and set it true by default. The name can be anything you wish but using OkToTrade makes the function of the bool clear when looking at the strategy builder.

    In a set, in the Conditions section, you would create a group to place two conditions. Please left click on the word "group" to open the "Condition Group Editor" window. It is important that the selection "if Any" is showing in the group drop down, as you will want either condition to set the bool to false. Now add the two PNL conditions. Click Add to open the conditions screen. On the left side select the strategy folder and inside locate and select "RealizedPnL", in the center select "Greater equal", on the right side select the "Misc" folder and inside find and select "Numeric value", in the field enter the value 400, click OK to add the condition. Repeat the same steps to add the next condition except in the center select "Less equal" and on the right, for the numeric value, enter -200, click OK. The Conditions group editor window should have both conditions and again should show "if Any". Click OK to complete the conditions section.
    Next in the actions section (below the conditions section), please left click "add" to add an action.In the "Actions" window, left click on to open the "Misc" folder, locate and select Set OkToTrade (if that was the name you used, or select whichever name you gave to your bool variable), once select the bottom 1/2 of the window will show the bool and a check box. It will show checked because it was set to true by default when created, at this point we want it to be set to false, so please click to "uncheck" the check box which means we are now setting it false. Click OK to close the actions window.

    So you have created a set that will set the bool OkToTrade to false if the realizedPnL is >=400 or is <= -200

    In your condition sets where you have your entry conditions, you can now add the condition to see if the bool OkToTrade is true. Please open one of your existing condition sets where you place a trade. In the conditions section click "add", in the conditions window, on the left side, left click on the folder "user variables", in there select "OkToTrade". In the center section select "Equals", on the right side select the "misc" folder and find and select "True", then click OK to add the condition. Repeat this for ever set where you have an entry condition.

    Here are strategy builder reference materials that may help your overall knowldege of the strategy builder:

    Understand the fundamentals of basic strategy creation by developing an actual strategy using the NinjaTrader Strategy Builder.2:45 Opening a Strategy Builde...
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Wow. Over the past few years I've seen countless times users asked for help with a daily profit and loss for their strategy. I've been thinking about going back to Tradestation due to this limitation in Ninjatrader. This is the first time I recall seeing a solution using the Strategy Builder.

      Nice job Paul!

      Comment


        #4
        Hello bob77713,

        Thanks for your post.

        The limitation in the strategy builder is that you have to stop and start the strategy on a daily basis for the strategies realizedPnL to be reset as otherwise the realizedPNL accumulates the longer the strategy runs and at some point it will stop taking trades.

        If you create a strategy in Ninjascript (or convert the strategy builder into the coded version) you can create a situation where you can effectively reset the daily PNL. You would do this by storing the strategies realized pNL into a variable on the first bar of the session (or when ever you wish really), then instead of testing the strategies realized PNL you would test the difference between the strategies realized Pnl and the variable that holds the realized PNl from the start of the session. The difference then being that days realizedPnl.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Good morning Paul,

          Thank you very much for your effort to help me with my problem. I have been studying your information carefully and I have some questions:

          1. In the "Actions" section of the "Misc" folder I can not find OkToTrade to "uncheck" the check box. I only find the Alert, Log, Play Sound, Send Mail, Print and Share options. Can you tell me how to do it?


          2. I had designed my strategy in the following way:

          If All:
          Conditions for entry in Largo
          Realized Pnl (currency) <= 400
          Realized Pnl> = -200
          Then:
          Enter Long Position

          If All:
          Conditions for entry in Short
          Realized Pnl (currency) <= 400
          Realized Pnl> = -200
          Then:
          Enter Short Position


          Is this strategy the same as yours? If not, what is the difference between the two?

          3. The option that you propose to me, daily reset the strategy, it does not work for me, that is a semi-automatic strategy. I want an automatic robot. Also I can not perform optimizations, nor can I backtest my strategy, so it's not useful.

          There is a way to get it, you say you can get programming the source code, I just need someone to provide the piece of software that does what you indicate, that stores the Pnl in a variable in the first bar of the session and that in the conditions it is compared with the difference between the pnl performed and the variable that contains the pnl made since the beginning of the session. Maybe it could even be done with the Strategy Builder, right?

          Please, help me and a large number of traders that we have the same problem.

          Thank you very much Paul
          NATALIA

          Comment


            #6
            Hello danakede,

            Thanks for your reply.

            1) "OkToTrade", I wrote, "You would create the bool variable in the "Variables" section of the Inputs and variables screen. As a suggestion, you might use the name of "OkToTrade" and set it true by default. The name can be anything you wish but using OkToTrade makes the function of the bool clear when looking at the strategy builder."

            2) What you have written is perfectly fine (within the same limitations of resetting the strategy each day). The differences are that I choose a different way to do the same thing so that you would only need to use one condition (OkToTrade = true) in each entry set.

            3) In the case of a continuous running strategy that needs the strategy PNL reset on every session, you would not be able to use the strategy builder. There are no means to perform the subtraction of the realizedPNl from the saved pnl in the variable. I will create a feature request to advise the need for a daily Pnl type variable and will update this thread when I have further information. A feature request does not mean that the feature will or will not be implemented but is a tool to let program management be aware of user interest/requests. To be clear this is not something that would happen quickly if it is implemented at all.

            If you want a continuous running strategy that needs the strategy PNL reset on every session, then it would have to be coded in Ninjascript.

            If you would like someone to code your strategy for you, if requested, we can provide references to 3rd party coders who can provide that service for you.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Hello danakede,

              Just to follow-up, the feature request to provide a daily PNL variable has been assigned as SFT-2980.
              If the feature is implemented, it will be identified in the release notes of the NT8 version. The release note can be found here: https://ninjatrader.com/support/help...ease_notes.htm
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Here's some NT8 code that will limit daily PL and doesn't need to be reset each session. Link

                Comment


                  #9
                  Hello algotrading,

                  Thanks for your post.

                  We appreciate your Ninjascript contribution, however, please note that this thread is about using the strategy builder for this effort.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Is it possible to automatically exit the trade when the daily profit/loss is reached?

                    Comment


                      #11
                      Hello TheMasterBlaster,

                      Thanks for your post.

                      Yes, you would check your unrealized PNL (perhaps added with your realizedPNL) and issue an ExitLong() or ExitShort() which are markets orders to close the position. You would likely need to also set a bool variable when you have reached your limit and use that bool as one of the entry condition to prevent further orders when you have reached your goal.
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Hello TheMasterBlaster,

                        You may want to check with your broker to see if your broker is able to impose a daily loss limit that will exit an open position.


                        Alternatively, you could write a custom coded Addon script to monitor the account and exit a position if the loss is to great.
                        Below are links to an example strategy with this kind of logic that may be adaptable to an Addon, and example addon that places orders, and a link to the help guide.
                        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://ninjatrader


                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello, I'm new to using strategy building, I'm having an issue implementing the following. I want to be sure I'm doing this correctly. Please advise. I have already set my strategy up to enter trades and that is working fine. I now want to set daily pnl goal and loss limits. In the conditions section, does this order work? Based on screenshots do you see an issue here? Also, How do I test to make sure this works? When I add to the chart I don't see backtested results. Thanks for your help.

                          Comment


                            #14
                            Hello T1brewster,

                            Welcome to the support forum.

                            In the builder what you have shown looks correct for the two conditions however I think you need to reverse the Greater/Lesser equal between the two conditions. How did you use this group in your condition, is the group set for any or all? If you have it set to all conditions need to be true for the group then the greater/lesser should be reversed if you are trying to allow trades when within the ranges you set.

                            You can test this in realtime if you load less than a days worth of data meaning just the current session. You can also test this in a backtest but the results will be for the first day only. When using the builder you have to keep in mind it uses the total performance from the time it started so if you have multiple previous days loaded you may hit that condition early in the charts historical data. The builder specifically is not able to reset the PnL values daily, for that you would need to manually code the strategy.

                            I look forward to being of further assistance.
                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              Hello,
                              Thank you PaulH for your post. I have tried to make this work in the strategy builder without success.
                              Can Ninjatrader Ecosystems apps be discussed here, if so here is my question:
                              Has anyone tried the "
                              daily-loss-profit-limit" shared
                              app from
                              ninjatrader ecosystems?
                              Does it limit the daily profit and loss?
                              Does it have to be reset each day?

                              Regards,
                              Joe P

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fiddich, Today, 05:25 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post fiddich
                              by fiddich
                               
                              Started by gemify, 11-11-2022, 11:52 AM
                              6 responses
                              803 views
                              2 likes
                              Last Post ultls
                              by ultls
                               
                              Started by ScottWalsh, Today, 04:52 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by ScottWalsh, Today, 04:29 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post ScottWalsh  
                              Started by rtwave, 04-12-2024, 09:30 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post rtwave
                              by rtwave
                               
                              Working...
                              X