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

Setting Strategy builder to scale out at profit targets and stop loss?

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

    Setting Strategy builder to scale out at profit targets and stop loss?

    How do I set up Strategy builder for-profit taking scaling out of contract orders?
    Last edited by alikakbar; 01-12-2021, 11:40 AM.

    #2
    Hello alikakbar,

    I have a few examples you may find helpful.

    Custom exit movement behavior - https://ninjatrader.com/support/foru...596#post806596
    Scaling out - https://ninjatrader.com/support/foru...80#post1077380

    Each quantity amount should be a separate entry. The exit orders would use the from entry signals of that entry.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea, I have done exactly as you indicated - Each quantity amount as a separate entry. The exit orders use the from entry signals of the entry. And finally added stops and targets. I don't see it working as desired. Can I send you the download for you to review?

      Comment


        #4
        Hello alikakbar,

        What specifically is not working?

        Are there error messages appearing?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          no error is appearing and it successfully compiles.
          Also, it works if I don't break the contract size into 4-4-2 (and one-stop loss).
          When I try to break into three entry-and exits, including trailing stops, I don't see the intended behavior.

          Comment


            #6
            Hello alikakbar,

            What is the intended behavior you are not seeing?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              after the 1st profit target is hit, move the stop-loss to breakeven and after the 2nd profit target is hit, use 16 ticks trailing stop loss.

              Comment


                #8
                Hello alikakbar,

                To confirm, after the 1st target is hit, the stop loss is moved to breakeven and you are not wanting this to happen?

                When you say it's not working, the stop should not be moved and is being moved unexpectedly?

                Is the method for the stop being called multiple times with new prices using the same signal name?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I wasn't clear earlier:
                  after the 1st target is hit, the stop loss is not moving to the breakeven.
                  and I also don't think the trailing stop is working after the 2nd profit target is hit.

                  Comment


                    #10
                    Hello alikakbar,

                    Ok, to confirm, the issue is that the stop loss is not moving to breakeven.

                    Add prints to confirm that the condition that changes the exit order price is evaluating as true when you expect.

                    Print the time of the bar, print all variables used in that condition set.

                    Enable TraceOrders, remove and re-add the script, so that we may see when the order methods are being called.

                    Save the output from the output window to a text file and please include this with your next post.

                    Below is a link to a forum post that demonstrates using prints to understand behavior.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      I tried to add prints and wasn't successful. I am sending the link to the strategy. do you think this is helpful to resolve the issue?

                      Last edited by alikakbar; 01-12-2021, 09:30 AM.

                      Comment


                        #12
                        Hello alikakbar,

                        Yes, debugging is an extremely important part of the development process and tells you why a strategy is behaving as it is, which is what you are wanting to learn today.

                        I can help you with prints.

                        Start by adding a simple print of the time to the first line of OnBarUpdate():
                        Print(Time[0]);

                        Then reload the script and ensure the time of the bar is printing in the output window.
                        Below sure to watch the videos in the forum post that demonstrate how to do this.

                        Please let me know if you are not able to write Print(Time[0]); at the top of OnBarUpdate().


                        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi, I added print for time and other variables and it's showing in the output as per your video.

                          Print(Convert.ToString(Times[0][0].TimeOfDay));
                          Print(Convert.ToString(ProfitTarget1) + " " + Convert.ToString(ProfitTarget2) + " " + Convert.ToString(InitialStopDistance) + " " + Convert.ToString(ExitSize1) + " " + Convert.ToString(ExitSize2) + " " + Convert.ToString(ContractSize));

                          I know we can solve this in a day or two but to save time, could you ask the NinjaTrader Ecosystem team to suggest a professional NinjaScript Consultant who will validate or tweak my existing strategy builder script (not someone who is looking to build from scratch). The current strategy builder (v1) is working except for one logic of moving to breakeven and trailing stop (v1.1).
                          Last edited by alikakbar; 01-12-2021, 09:57 AM.

                          Comment


                            #14
                            Hello alikakbar,
                            Thank you for your post.


                            This is Thomas from the NinjaTrader Ecosystem responding on behalf of my colleague Chelsea.


                            You can search our list of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more:
                            You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third-party services for NinjaTrader, all pricing and support information will need to be obtained through the consultant.

                            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem, LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.



                            Let me know if I may be of further assistance.


                            Thomas C.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Stanfillirenfro, Today, 07:23 AM
                            1 response
                            3 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Started by cmtjoancolmenero, Yesterday, 03:58 PM
                            2 responses
                            21 views
                            0 likes
                            Last Post cmtjoancolmenero  
                            Started by olisav57, Yesterday, 07:39 PM
                            1 response
                            9 views
                            0 likes
                            Last Post NinjaTrader_ChelseaB  
                            Started by cocoescala, 10-12-2018, 11:02 PM
                            7 responses
                            944 views
                            0 likes
                            Last Post Jquiroz1975  
                            Started by oviejo, Today, 12:28 AM
                            1 response
                            12 views
                            0 likes
                            Last Post NinjaTrader_Gaby  
                            Working...
                            X