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

how use trailing stop at strategy builder

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

    how use trailing stop at strategy builder

    Good afternoon, I would like through the strategy builder to be able to use the trailing stop, I don't know how to use it so that my stop decreases when I have advanced a certain number of ticks? Thanks

    #2
    Hello Dist2020,

    Thank you for your post.

    A basic trail stop may be added in the Strategy Builder on the Stops and Targets screen. It should be noted that this is a very basic trailing stop and will trail by the same number of ticks each time - you cannot reduce the width of the trail stop after it's created.

    The Set methods in the Stops and Targets section of the Strategy Builder only allow for simple stops and targets that cannot be changed dynamically. Programming by hand will offer more flexibility, but you can also create your own logic in Conditions and Actions that controls how you would like to exit.

    We can not offer services to design strategy logic in the support department, but you may conceptualize the following as an example of using Exit orders to mimic Trail stop functionality:
    1. If the strategy is flat, set a bool to controlling your auto trail behaviors to false. Then Enter.
    2. If the strategy is not flat and some condition happens that you would like to trigger your auto trail, set the bool to true.
    3. If the strategy is not flat and the bool is false, place your initial stop loss as an Exit Order.
    4. If the strategy is not flat and the bool is true, modify the Exit Order in association to the current market price.
    More information on using the Strategy Builder can be found below.

    Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      What you say is this? when the order is flat

      Comment


        #4

        I would like your help please, I just want if it advances 8 ticks my stop decreases to 4

        Comment


          #5
          Hello Dist2020,

          Thank you for your replies.

          I am unable to view your video as the format it is in, Flash, is no longer supported.

          In the case that you want your stop movements to be triggered after the price increases by 8 ticks you will need to use exit orders to simulate stop movements in the builder. I've attached a simple example strategy that allows you to set the frequency with with your "trail stop" updates that should give you a good jumping off point to add your own logic.

          Here is a basic guideline of how to import NinjaScript add-ons in NinjaTrader 8:

          Note — To import NinjaScripts you will need the original .zip file.

          To Import:
          1. Download the NinjaScripts to your desktop, keep them in the compressed .zip file.
          2. From the Control Center window select the menu Tools > Import > NinjaScript Add-on...
          3. Select the downloaded .zip file
          4. NinjaTrader will then confirm if the import has been successful.
          Critical - Specifically for some NinjaScripts, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'

          Once installed, you may add the Strategy to a chart by:
          • Right click your chart > Strategies... > Select the Strategy from the 'Available' list on the left > Add > OK
          For this strategy, to look at the code and edit it, please open a new Strategy Builder window and select TrailBuilderExample from the list of strategies, then click through to view the various settings.

          Please let me know if I can be of further assistance.





          Attached Files
          Last edited by NinjaTrader_Kate; 08-06-2020, 09:36 AM. Reason: Updated TrailBuilderExample as it previously used ints instead of doubles which caused issues on certain instruments.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Hi Kate, I have looked at the TrailBuilderExample, I believe I understand it, but I would like to set the "TrailStopDistance" to a multiplier of ATR rather than a fixed number. Can I get a walk through on how to do this either in the builder or a snippet of code for me to study.

            Thanks

            Comment


              #7
              Hello clearlystocks,

              Thank you for your reply.

              Here's a different example for the strategy builder that shows how to set up a regular stop that uses the ATR times a multiplier and then rounds to the nearest integer for the stop distance - this could be modified and combined with the previous example to create a trail stop that uses the ATR.

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hello,

                your example trailing is very usefull for me, thats nice. But I have a problem if I use LONG & SHORTS in my strategy. Long Orders and TrailStopps works fine. In a Short Order the Script set the STP under the Price, so its an Error...

                I dont know how to change the script... I see the forest for the trees....

                Thank you,
                Daniel

                Comment


                  #9
                  Hello DannyB85,

                  Thank you for your reply.

                  That example has some bugs, so I've actually removed it.

                  I'm currently working on a new version and should have that available tomorrow.

                  Thanks in advance; I look forward to assisting you further.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Kate, perfect. Thank u.
                    I use your TrailBuilderExample

                    Comment


                      #11
                      Originally posted by NinjaTrader_Kate View Post
                      Hello DannyB85,

                      Thank you for your reply.

                      That example has some bugs, so I've actually removed it.

                      I'm currently working on a new version and should have that available tomorrow.

                      Thanks in advance; I look forward to assisting you further.
                      Nice, I got one working as I hoped for, but I am super curious as to what you come up with.

                      Comment


                        #12
                        Hello,

                        Thank you for your replies.

                        To submit orders using dynamic prices in the Strategy Builder it would be necessary to use Exit methods in the 'Do the following' > Order Management section.

                        Below is a link to an example created with the Strategy Builder.



                        The only math available in the Strategy Builder is with offsets.

                        While you could select set in the offset for a price (such as an exit price or when setting a double variable) and set this to the ATR, you would not be able to multiply this by your chosen value and this could not be added to the entry price.

                        Any kind of more complex math would require unlocking the script and coding by hand. This is possible to do in an unlocked script.

                        For example:

                        int myMultiplierValue = 2;

                        double myExitPrice = Position.AveragePrice + Instrument.MasterInstrument.RoundToTickSize( 2 * ATR(14)[0] );

                        Below is a link to examples of unlocked scripts that use Set methods as well as Exit methods.



                        I've also attached my unlocked revised version. What I'd recommend is setting up most of the logic in the builder, then unlocking it to make the small changes necessary for this to properly function.

                        Please let us know if we may be of further assistance to you.
                        Attached Files
                        Kate W.NinjaTrader Customer Service

                        Comment


                          #13
                          Hello Kate,

                          thank you for your Updated Scripted. But i mean the TrailBuilderExample from your post Above. Can you help me with an V2.0 too?
                          That would be Nice. The Shorts doenst work, I dont know why.

                          After EnterShort and the filled Order, the Stop Order will be placed "under" the MarketPrice (ends with Error) and not above. Thank you.

                          Greetings,
                          Daniel

                          Comment


                            #14
                            Hello DannyB85,

                            Thank you for your reply.

                            That example is meant to be a jumping off point to add your own code. We would expect that you would add logic to it if you need it to go short as well as long.

                            That particular example would need separate variables for the trigger and stop prices for short orders and for those you'd need to set them up similarly to how the current trigger and stop price works. Basically, for a short you would need to reverse the logic used to update the stop and trigger prices. I might also rename the CurrentTriggerPrice and CurrentStopPrice to CurrentLongTrigger and CurrentLongStop and then create a CurrentShortTrigger and CurrentShortStop. You would then want to make sure that those are getting updated by subtracting the TrailFrequency * TickSize or TrailStopDistance * TickSize from the current price rather than adding as with the long entry stops. You'd also need to create a separate ExitShortStopMarket to use for the trail.

                            Basically, you would need to add 4 more sets that do the identical things that the long ones do, but in reverse.

                            If you are unsure if you've got it set up correctly, please post screenshots of the builder screens in question.

                            Please let us know if we may be of further assistance to you.
                            Kate W.NinjaTrader Customer Service

                            Comment


                              #15
                              Hello Kate,

                              I have studied the TrailBuilderExample that you posted in this thread.. I have a question about how go about to adding code to include "Short Entres" to this strategy.. The coding part is a bit fuzzy for me as of yet.. What would I need to do..?

                              Thanks Michael

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by MarianApalaghiei, Today, 10:49 PM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by love2code2trade, Yesterday, 01:45 PM
                              4 responses
                              28 views
                              0 likes
                              Last Post love2code2trade  
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              37 views
                              0 likes
                              Last Post jeronymite  
                              Started by bill2023, Yesterday, 08:51 AM
                              8 responses
                              45 views
                              0 likes
                              Last Post bill2023  
                              Working...
                              X