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

Pause Trading after Realized Profit

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

    Pause Trading after Realized Profit

    Hello,

    I am working on an intraday strategy between 8am and 3:15pm.

    I am using the Strategy Builder to write the code. I basically would like to pause trading til the next day after X amount realized profit. X meaning negative or positive amount.

    Few questions:

    1. See attachment. Does Realized Pnl reset to $0.00 daily automatically?
    2. Is there any logic in the strategy builder to pause trading after X amount PnL? And also reset the logic?

    Thanks,
    Attached Files

    #2
    Hello simple_goodoboy,

    Thanks for your inquiry.

    Realized PnL (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit) will not reset after a new trading day. You can test this using the Playback Connection and 2 days of Market Replay data by printing out this value in a blank condition statement.

    Is there any logic in the strategy builder to pause trading after X amount PnL? And also reset the logic?
    This logic would have to be designed by you in the Strategy Builder. There is not any built in method or property that would accomplish this specific task.

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Jim View Post
      Hello simple_goodoboy,

      Thanks for your inquiry.



      This logic would have to be designed by you in the Strategy Builder. There is not any built in method or property that would accomplish this specific task.

      Please let us know if you have any additional questions.
      Thank you Jim,

      I use the following two managed order management methods SetProfitTarget and SetStopLoss.

      I would like to add a counter once either SetProfitTarget or SetStopLoss is triggered.

      Is there anyway I can build a line of code to increment once either order method is triggered?

      Ideally, I would like to stop trading for the time period I trade once my profit target is reached.

      Thanks
      Last edited by simple_goodoboy; 12-01-2017, 04:14 PM.

      Comment


        #4
        Hello simple_goodoboy,

        The Strategy Builder is limited in applying mathematical offsets to a variable. Within the Builder, you could create several more conditions that check if a "Count" variable is a certain value and then to set it to the next numeric value. For example, if Count == 4, Set Count to 5.

        Alternately you may unlock the code and add your mathematical operations manually. If you decide to take this route, I would suggest duplicating the strategy in case you wanted to go back to editing in the Strategy Builder.

        We also have a feature request tracking the ability to perform mathematical offsets on user variables. I'll submit a vote on your behalf.

        The ticket ID for the feature request is: SFT-2059

        As with other feature requests, we cannot present an ETA as they are fulfilled based on the development team's schedule and priorities. Upon implementation the ticket ID can be found publicly on the Release Notes page of the help guide. I'll provide a link below.

        Release Notes: https://ninjatrader.com/support/help...ease_notes.htm
        JimNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Jim View Post
          Hello simple_goodoboy,

          The Strategy Builder is limited in applying mathematical offsets to a variable. Within the Builder, you could create several more conditions that check if a "Count" variable is a certain value and then to set it to the next numeric value. For example, if Count == 4, Set Count to 5.

          Alternately you may unlock the code and add your mathematical operations manually. If you decide to take this route, I would suggest duplicating the strategy in case you wanted to go back to editing in the Strategy Builder.

          We also have a feature request tracking the ability to perform mathematical offsets on user variables. I'll submit a vote on your behalf.

          The ticket ID for the feature request is: SFT-2059

          As with other feature requests, we cannot present an ETA as they are fulfilled based on the development team's schedule and priorities. Upon implementation the ticket ID can be found publicly on the Release Notes page of the help guide. I'll provide a link below.

          Release Notes: https://ninjatrader.com/support/help...ease_notes.htm
          Thank you Jim,

          Please see my comment below regarding monitoring if profit target reached.

          Comment


            #6
            Sorry simple_goodoboy, looks like I missed that.

            This can be detected with BarsSinceExitExecution() with the signal name for "Profit Target" and "Stop Loss." You could also set a "Exit Executions Ago" value which could act similarly for a counter of how many times that exit has been hit. This can be found under Misc > Bars Since Exit in the Condition Builder.

            I'll provide an openly available documentation link for further reference on how this method works: https://ninjatrader.com/support/help...texecution.htm

            Please let us know if you have any additional questions.
            Last edited by NinjaTrader_Jim; 12-01-2017, 04:44 PM.
            JimNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jim View Post
              Sorry simple_goodoboy, looks like I missed that.

              This can be detected with BarsSinceExitExecution() with the signal name for "Profit Target" and "Stop Loss." You could also set a "Exit Executions Ago" value which could act similarly for a counter of how many times that exit has been hit. This can be found under Misc > Bars Since Exit in the Condition Builder.

              I'll provide an openly available documentation link for further reference on how this method works: https://ninjatrader.com/support/help...texecution.htm

              Please let us know if you have any additional questions.
              Thanks Jim.

              Just to make sure I understand how to use BarsSinceExitExecution() correctly.

              I built the following logic.

              Two questions please.

              1. Is my following understanding correct "Set bit to true, if profit target was triggered on the last bar and 1 execution has occurred. "?

              2. What does Exit Executions Ago? I am not sure I understand.



              // Set bit to true, if profit target was triggered on the last bar and 1 execution has occurred.
              if (BarsSinceExitExecution(0, @"Profit Target", 0) == 0)
              {
              Profit_Max_Done = true;
              }

              Comment


                #8
                Originally posted by NinjaTrader_Jim View Post
                Sorry simple_goodoboy, looks like I missed that.

                This can be detected with BarsSinceExitExecution() with the signal name for "Profit Target" and "Stop Loss." You could also set a "Exit Executions Ago" value which could act similarly for a counter of how many times that exit has been hit. This can be found under Misc > Bars Since Exit in the Condition Builder.

                I'll provide an openly available documentation link for further reference on how this method works: https://ninjatrader.com/support/help...texecution.htm

                Please let us know if you have any additional questions.
                Jim,

                Please see attachment. After profit target is reached , I do not want to enter another trade.

                I added the following code. but as you see from the screen shot after profit target reached, the strategy is still taking trades.

                Maybe I am using the BarsSinceExitExecution() incorrectly.
                Attached Files

                Comment


                  #9
                  Originally posted by NinjaTrader_Jim View Post
                  Sorry simple_goodoboy, looks like I missed that.

                  This can be detected with BarsSinceExitExecution() with the signal name for "Profit Target" and "Stop Loss." You could also set a "Exit Executions Ago" value which could act similarly for a counter of how many times that exit has been hit. This can be found under Misc > Bars Since Exit in the Condition Builder.

                  I'll provide an openly available documentation link for further reference on how this method works: https://ninjatrader.com/support/help...texecution.htm

                  Please let us know if you have any additional questions.
                  Jim,

                  I am still not able stop trading after a profit target order is exited.
                  Attached is my code and trades and chart example. You will see even though I use BarsSinceExitExecution(), a trade is still entered on next bar cause conditions are still true for some reason.
                  Attached Files

                  Comment


                    #10
                    Hello simple_goodoboy,

                    Two questions please.

                    1. Is my following understanding correct "Set bit to true, if profit target was triggered on the last bar and 1 execution has occurred. "?

                    2. What does Exit Executions Ago? I am not sure I understand.
                    I don't think what you have written makes sense as a logical operation. I would suggest to add this method to a print statement in a separate condition set in the Strategy Builder that has no actual conditions, but only has the print for BarsSinceExitExecution() under Actions. This way you can observe its return value in the Output window and see how it iterates for each bar that occurs after an exit execution. Taking these steps will help understand how you need to write the syntax or create the condition in the Strategy Builder.

                    You wouldn't be able to tell how many executions have occurred without programming your own counter. "Exit Executions Ago" will affect the "exitExecutionsAgo" argument in BarsSinceExitExecution(). It will have the method tell you how many bars have occured since the last execution or the execution before that. You can observe this parameter being modified by clicking View Code and you can reference the help guide page I linked previously for usage.

                    From the help guide:
                    exitExecutionsAgo
                    Number of exit executions ago. Pass in 0 for the number of bars since the last exit execution.
                    1 would be the prior exit execution to the last, 2 would be the exit execution before that, etc.

                    a trade is still entered on next bar cause conditions are still true for some reason.
                    Debugging steps will need to be taken to find out wich conditions you wrote are becoming true and why. I've included a link on debugging tips. We can also have a member of our Business Development team reach out to you with a list of NinjaScript Consultants who would be happy to debug the code for you.

                    As for the other code in you screenshot, it still remains as a logical issue where those operations should be debugged and observed while executing to understand why they are becoming true.

                    Debugging - https://ninjatrader.com/support/foru...ead.php?t=3418

                    Please let us know if we can provide further insight.
                    JimNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Jim View Post
                      Hello simple_goodoboy,


                      I don't think what you have written makes sense as a logical operation. I would suggest to add this method to a print statement in a separate condition set in the Strategy Builder that has no actual conditions, but only has the print for BarsSinceExitExecution() under Actions. This way you can observe its return value in the Output window and see how it iterates for each bar that occurs after an exit execution. Taking these steps will help understand how you need to write the syntax or create the condition in the Strategy Builder.

                      You wouldn't be able to tell how many executions have occurred without programming your own counter. "Exit Executions Ago" will affect the "exitExecutionsAgo" argument in BarsSinceExitExecution(). It will have the method tell you how many bars have occured since the last execution or the execution before that. You can observe this parameter being modified by clicking View Code and you can reference the help guide page I linked previously for usage.

                      From the help guide:

                      1 would be the prior exit execution to the last, 2 would be the exit execution before that, etc.


                      Debugging steps will need to be taken to find out wich conditions you wrote are becoming true and why. I've included a link on debugging tips. We can also have a member of our Business Development team reach out to you with a list of NinjaScript Consultants who would be happy to debug the code for you.

                      As for the other code in you screenshot, it still remains as a logical issue where those operations should be debugged and observed while executing to understand why they are becoming true.

                      Debugging - https://ninjatrader.com/support/foru...ead.php?t=3418

                      Please let us know if we can provide further insight.
                      Thank you Jim for the help.

                      Using the NinjaScript Output window is awesome. Thanks for the debugging tips. I don't need a consultant, i am learning on my own for about 6 months. So not using real money noo time soon. Just learning the platform for now.

                      I used the print statements to monitor
                      Print(Time[0].ToString());
                      Print("Exit From Short Signal");
                      Print((BarsSinceExitExecution(@"Short_Signal")));
                      Print((BarsSinceExitExecution(0, @"Short_Signal", 0)));
                      Print((BarsSinceExitExecution()));


                      I added both syntax to understand what each do.

                      I am not sure why (BarsSinceExitExecution(@"Short_Signal") is returning -1 every time I exit a trade. -1 means, no exit has not occurred yet. But as you see from the trades screenshoot, a exit did occur and many bars pass since I exit.


                      Please see screenshots.

                      1. Can you please explain why I continue to see -1 when I use BarsSinceExitExecution(@"Short_Signal") and BarsSinceExitExecution(0, @"Short_Signal", 0) even though many bars pass by after exit of short signal occurs?

                      2. But when I use BarsSinceExitExecution(), the bars start counting correctly.

                      Thanks for your help.
                      Attached Files
                      Last edited by simple_goodoboy; 12-04-2017, 10:56 PM.

                      Comment


                        #12
                        Hello simple_goodoboy,

                        You observe that you are getting the expected result with one overload but not another. That is a good indicator that the way one overload is written is not correct. It would be advised then to double check your implementation and what the help guide describes as should be used.

                        You are referencing the Entry Signal name in BarsSinceExitExecution() when the signal name that BarsSinceExitExecution() looks for is "The signal name of an exit order specified in an order exit method." The help guide notes to reference the SetProfitTarget(), SetStopLoss() and SetTrailStop() documentation pages for their signal name. I also gave this information in post #6.

                        This can be detected with BarsSinceExitExecution() with the signal name for "Profit Target" and "Stop Loss."
                        Please let us know if we can be of further help.
                        JimNinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_Jim View Post
                          Hello simple_goodoboy,

                          You observe that you are getting the expected result with one overload but not another. That is a good indicator that the way one overload is written is not correct. It would be advised then to double check your implementation and what the help guide describes as should be used.

                          Please let us know if we can be of further help.
                          Thanks Jim for response,

                          What do you mean by " with one overload but not another." ? Do you mean overload as in after Stop Loss signal is executed, another entry signal is taken? If that's the case, this is the expected results. I want another entry to be taken whenever stop loss is triggered. After profit target, do not take any more trades. The logical is working as expected for now. Unless overload means something else.


                          Originally posted by NinjaTrader_Jim View Post
                          Hello simple_goodoboy,
                          You are referencing the Entry Signal name in BarsSinceExitExecution() when the signal name that BarsSinceExitExecution() looks for is "The signal name of an exit order specified in an order exit method." The help guide notes to reference the SetProfitTarget(), SetStopLoss() and SetTrailStop() documentation pages for their signal name. I also gave this information in post #6.

                          Please let us know if we can be of further help.
                          Ohhh, now I understand. Sorry, I was not reading and understanding correctly. BarsSinceExitExecution() automatically looks for signal name of SetProfitTarget(), SetStopLoss() and SetTrailStop(). I understand now.

                          Thank yo

                          Comment


                            #14
                            Hello simple_goodoboy,

                            "Overload" refers to a different form of a method that accepts different arguments. This is a general C# concept. You may find external resources online that can provide educational information on C#. I have provided a link to an external resource I have found with a Google search.

                            Overloading - http://csharpindepth.com/Articles/Ge...erloading.aspx

                            The overload for BarsSinceExitExecution() that does not accept a signal name would not look for an exit marked by a specific signal name. It would report back the last exit execution from the strategy regardless of the signal name used.
                            JimNinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_Jim View Post
                              Hello simple_goodoboy,

                              "Overload" refers to a different form of a method that accepts different arguments. This is a general C# concept. You may find external resources online that can provide educational information on C#. I have provided a link to an external resource I have found with a Google search.

                              Overloading - http://csharpindepth.com/Articles/Ge...erloading.aspx

                              The overload for BarsSinceExitExecution() that does not accept a signal name would not look for an exit marked by a specific signal name. It would report back the last exit execution from the strategy regardless of the signal name used.
                              Thank you Jim for the response and help.

                              Now I see what you mean.

                              My problem is this:

                              BarsSinceExitExecution() - is working.

                              BarsSinceExitExecution(0, @"Short_Signal", 0) - is not working.

                              BarsSinceExitExecution(0, @"Short_Signal", 0) - is not working.

                              I will research why the 2 is not working by using the help files you provided. Thank you.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by bortz, 11-06-2023, 08:04 AM
                              47 responses
                              1,607 views
                              0 likes
                              Last Post aligator  
                              Started by jaybedreamin, Today, 05:56 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post jaybedreamin  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              6 responses
                              19 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Started by Jon17, Today, 04:33 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post Jon17
                              by Jon17
                               
                              Started by Javierw.ok, Today, 04:12 PM
                              0 responses
                              15 views
                              0 likes
                              Last Post Javierw.ok  
                              Working...
                              X