Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how use trailing stop at strategy builder

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

    #16
    Hello Mykro,

    Thank you for your reply.

    You may have missed my last response on the previous page of this thread where I detailed the steps you'd need to take in order to add short trades:

    Originally posted by NinjaTrader_Kate View Post
    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.
    If you've attempted to set this up but it doesn't seem to be working or if you're not sure you've set them up correctly, please post screenshots of the strategy builder sets in question.

    Please let us know if we may be of further assistance to you.

    Comment


      #17
      Kate,

      Got it..! Thanks..

      Another question.. I assume I can add other Conditions/Actions to trigger my Longs or Shorts..?? In other words, I could incorporate other code from a different strategy into this one..? Along with using the Strategy Analyzer..?

      Thanks
      Michael

      Comment


        #18
        Kate,



        I got to work building a new version of the TrailBuilderExample which is now called "TrailStopBuilder".. I got it completed to Tab # 6 and came to an impasse.
        In your post on how to add the other conditions... "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" I'm not sure about the subtraction part of the equation in the "Do the following box" When I choose * Ticks it only adds instead of subtract. If I choose "Arithmetic" it lets you add a "minus" sign.
        Is this line of code correct?? CurrentShortTrigger = (Default input(0) - (TrailFreqShort)); See Attachment...



        TrailStopBuilder 072920.pdf

        Comment


          #19
          Hello Michael,

          Thanks for your reply.

          When selecting ticks, you can enter a negative value.

          Comment


            #20
            Originally posted by NinjaTrader_PaulH View Post
            Hello Michael,

            Thanks for your reply.

            When selecting ticks, you can enter a negative value.
            Paul,

            It won't let me choose "Ticks" as a negative value, only positive... Only as "Arithmetic" will it accept an Negative value...

            Comment


              #21
              good day
              I have my strategy but I could not configure trailingstop

              Comment


                #22
                Hello Michael,

                Thanks for your reply.

                I took a closer look at the strategy which I understand is a copy of NinjaTrader_Kate's example.

                In the case of a trailstop for a short order, the trail stop would need to be a positive value of ticks above the price and the trigger would need to be a negative value to trigger as price drops. So you would need to set the Trailfreq to be a negative value and the TrailDist to be a positive value. As you are setting the value to be a negative, in both cases you can add to the Close value the same as the long side shows but with the short variables.

                Michael, the strategy Kate provided is merely an example, you will not be successful in just duplicating it on the short side because of the Entry conditions. The only entry condition is that you are flat and in state realtime. So if you duplicate a short set with the long set they will both enter at the same time because of the strategy being flat. I would suggest that you create, for set 2 an actual entry condition that can only be unique for long entries and the same but short for short entry in set 6. If you do not do this then the strategy is as is will error out.






                Comment


                  #23
                  Hello Camacho,

                  Thanks for your post and welcome to the NinjaTrader forums!

                  If your question relates to the custom trail stops in this thread please clarify what you cannot do. Please note that these are not the trail stop found in the strategy builder itself.

                  If your question relates to the built in trailstop found in the Stops and targets section of the strategy builder then I would suggest going back to the top of the forum and creating a new topic (click the blue "Topic" button) and elaborate there on what you need specific help with. Please use screenshots to help identify what you are working with regarding the trail stop.

                  Comment


                    #24
                    Originally posted by NinjaTrader_PaulH View Post
                    Hello Michael,

                    Thanks for your reply.

                    I took a closer look at the strategy which I understand is a copy of NinjaTrader_Kate's example.

                    In the case of a trailstop for a short order, the trail stop would need to be a positive value of ticks above the price and the trigger would need to be a negative value to trigger as price drops. So you would need to set the Trailfreq to be a negative value and the TrailDist to be a positive value. As you are setting the value to be a negative, in both cases you can add to the Close value the same as the long side shows but with the short variables.

                    Michael, the strategy Kate provided is merely an example, you will not be successful in just duplicating it on the short side because of the Entry conditions. The only entry condition is that you are flat and in state realtime. So if you duplicate a short set with the long set they will both enter at the same time because of the strategy being flat. I would suggest that you create, for set 2 an actual entry condition that can only be unique for long entries and the same but short for short entry in set 6. If you do not do this then the strategy is as is will error out.
                    Paul,

                    I understand... At this point I'm going to abandon this project based upon my lack of programming skills... Thank you for your insight though..

                    Comment


                      #25
                      Originally posted by Mykro View Post

                      Paul,

                      I understand... At this point I'm going to abandon this project based upon my lack of programming skills... Thank you for your insight though..
                      Paul, Kate,

                      Ok.. I decided to not abandon this project and I broke out the Long TrailStop and the Short TrailStop seperatly into their own stategies and I got them both working thanks to Pauls suggestion to set the Trailfreq to a negative, and the TrailDist to a positive. And now they both work great.. Except for one thing.. The trail increments by one point each time instead of Ticks.. So I fired the original TrailBuilderExample and it too trails by one point instead of by ticks. Is this by design..? I know this is just an example but can it be corrected??..



                      Thanks Michael
                      Last edited by Mykro; 08-02-2020, 07:44 AM.

                      Comment


                        #26
                        Hello Michael,

                        Thanks for your reply.

                        Really glad to hear you stuck with it.

                        The Trailfreq variable would set when the stop is adjusted.

                        The TrailDist variable sets how far behind the current price to move the stop to.

                        The TrailBuilderExample posted by Ninjatrader_Kate has its strategy calculate set to Calculate.OnEachTick, please make sure you are setting yours to that or Calculate.OnPriceChange. If you wait for Calculate.OnBarClose you may end up with inalid orders due to the price movement.

                        Comment


                          #27
                          Paul,

                          See PDF File....

                          The calculate "on each tick" property never changed.. I left that alone...

                          What I found from Kates TrailBuilderExample is that it would not update on each tick when the number 1 is chosen for the frequency. It updates every 4 ticks or 1 point. So I thought what if
                          I changed everything to type double instead of int just to see what it would do. Wel,l it does increment by each tick when you choose a decimal number under 1... (.25,.50 etc...) The LONGS seem to work out ok.. The SHORTS error out immediantly when enabled.. That's as far as I have gone.. I'm stumped.. I could use your help.. I just don't know enough.. Can you see just by what I coded whats wrong..??

                          Thanks Michael
                          Attached Files

                          Comment


                            #28
                            Hello Michael,

                            Thanks for your reply.

                            Changing the Int to doubles, for the freq and distance does not make any sense to me as these are to set the number of ticks to add and they are converted to a double by multiplying them by the TickSize property which is a double so if you are using less then 1 for a tick then you would generate an incorrect price level.

                            Looking at set #7, the purpose of this set is to check to see if the Close price (which is the live right edge price) is less than the trigger price. If so then the action in set 7 is to reset the trigger to a new level based on the freq value and to set the new stop value (which is performed in set 8). As you are running a live chart (or replay chart) with Calculate.OnEachTick, the stop will move when the current price is less than the trigger. If you set to 1 tick, I would expect the stop to be move each time price (decreases) 1 tick (going short). How far the stop moves is related to the live price plus the distance. So if price is really moving around, the stop will definitely move more than 1 tick and this would be expected.

                            Comment


                              #29
                              Originally posted by NinjaTrader_PaulH View Post
                              Hello Michael,

                              Thanks for your reply.

                              Changing the Int to doubles, for the freq and distance does not make any sense to me as these are to set the number of ticks to add and they are converted to a double by multiplying them by the TickSize property which is a double so if you are using less then 1 for a tick then you would generate an incorrect price level.

                              Looking at set #7, the purpose of this set is to check to see if the Close price (which is the live right edge price) is less than the trigger price. If so then the action in set 7 is to reset the trigger to a new level based on the freq value and to set the new stop value (which is performed in set 8). As you are running a live chart (or replay chart) with Calculate.OnEachTick, the stop will move when the current price is less than the trigger. If you set to 1 tick, I would expect the stop to be move each time price (decreases) 1 tick (going short). How far the stop moves is related to the live price plus the distance. So if price is really moving around, the stop will definitely move more than 1 tick and this would be expected.
                              Paul,

                              Updated PDF attached...

                              I changed everything back to Int and the Longs work just as did prior, but the Short side dosen't work correctly. It just dosn't trail correctly.. I cant pinpoint the error..

                              Michael
                              Last edited by Mykro; 08-04-2020, 07:20 PM.

                              Comment


                                #30
                                Hello Michael,

                                Thanks for your reply.

                                The PDF was not attached. If you don't mind, please attach the strategy directly. It will be found in the Documents>NinjaTrader8>bin>Custom>Strategies> and will be named as you named it with a .cs extension.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                56 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                133 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                73 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                45 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                49 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X