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

Trailing Stops

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

    Trailing Stops

    Hello,

    Is there a trailing stop that will work based on the current price?

    Both SetTrailStop() and SetStopLoss work off the entry price.

    Thanks

    #2
    Hello peteM,

    Thank you for your post.

    You are correct on SetStopLoss() as it is set based on the entry price.

    Now the SetTrailStop() is different in the following manner, it will set itself at the defined value from the entry but will trail the market up as the price changes. Information on SetTrailStop() can be found at the following link: http://www.ninjatrader.com/support/h...ttrailstop.htm

    However, if you want to place your Stop Loss based on the current price (Close[0]) you can use ExitLongStop() or ExitShortStop() which can be placed based on the values you wish.
    For information on these methods and the Managed Approach for order methods please visit the following link: http://www.ninjatrader.com/support/h...d_approach.htm

    Please let me know if you have any questions.

    Comment


      #3
      Patrick,

      Thanks for your response. Is it possible in any way to use SetTrailStop to protect a profit? This is what I'm trying to do based off the current price.

      Thanks again

      Comment


        #4
        Originally posted by peteM View Post
        Patrick,

        Thanks for your response. Is it possible in any way to use SetTrailStop to protect a profit? This is what I'm trying to do based off the current price.

        Thanks again
        You mean that you want to tighten the Trail Stop? Just reissue it with the adjusted amount of ticks.

        Comment


          #5
          Originally posted by koganam View Post
          You mean that you want to tighten the Trail Stop? Just reissue it with the adjusted amount of ticks.

          As an example, let's say once my unrealized gain was $100, I want to stop out if the unrealized drops to $80. I initially though the TrailStop was from current price.

          Sounds like I'll have to program that manually, but any ideas would be much appreciated.

          Thanks

          Comment


            #6
            Originally posted by peteM View Post
            As an example, let's say once my unrealized gain was $100, I want to stop out if the unrealized drops to $80. I initially though the TrailStop was from current price.

            Sounds like I'll have to program that manually, but any ideas would be much appreciated.

            Thanks
            Here is some pseudocode:

            Code:
             
            private bool Tightened = false; //declared as class variable
            Code:
             
            bool IsTimeToTighten = (UnrealizedGain() >= 100.00);
             
            if (IsTimetoTighten && !Tightened)
            {
            SetTrailStop(20);
            Tightened = true;
            }
             
            if (Position.MarketPosition == MarketPosition.Flat)  //reset relevant variables and properties
            {
            Tightened = false;
            // reset the TrailStop here
            }

            Comment


              #7
              Originally posted by koganam View Post
              Here is some pseudocode:

              Code:
               
              private bool Tightened = false; //declared as class variable
              Code:
               
              bool IsTimeToTighten = (UnrealizedGain() >= 100.00);
               
              if (IsTimetoTighten && !Tightened)
              {
              SetTrailStop(20);
              Tightened = true;
              }
               
              if (Position.MarketPosition == MarketPosition.Flat)  //reset relevant variables and properties
              {
              Tightened = false;
              // reset the TrailStop here
              }

              I believe that's similar to what I've done. I'm simulating it today, and that SetTrailStop order sets a trailing stop from my entry price. Meaning if the position moved against me immediately, I'd be left with a $20 loss as opposed to an $80 gain. Unless I'm missing something, which is entirely possible.

              Comment


                #8
                Hello peteM,

                Thank you for your response.

                That is correct, if the markets moves down after the entry is filled and you have SetTrailStop(20) then it will stop you out at $20.

                Please let me know if you have any questions.

                Comment


                  #9
                  Originally posted by peteM View Post
                  I believe that's similar to what I've done. I'm simulating it today, and that SetTrailStop order sets a trailing stop from my entry price. Meaning if the position moved against me immediately, I'd be left with a $20 loss as opposed to an $80 gain. Unless I'm missing something, which is entirely possible.
                  Some Print() statements, referenced to the log entry should tell you what is wrong. I know that code is correct because that is how I tighten my trail stop at a predetermined time (right now, 1555EDT), at EOD. However, I tighten using the tick count, rather than a cash value, and I tighten specifically to the entry signal. I guess I could check if that is the difference.

                  SetTrailStop() takes its start point from the current price, whatever it is. If you set it on entry, then it will take its exit based on that. You have to reset it at the time that you want. Maybe, if you strip your code of the secret details, and post just your adjustment code, I can take a look.

                  In the meantime, here is a section of my log. See how on 3/21/13, I am adjusting my exit for my short entry continually down as each bar closes, and how on 3/22/13, I am adjusting my exit for my long entry on the exact same strategy, upwards as each bar closes. (My adjustment is actually variable, designed to trail each time just 1-tick below the bar that closed, but only adjusted if the price movement is favorable).
                  Attached Files

                  Comment


                    #10
                    Originally posted by koganam View Post
                    Some Print() statements, referenced to the log entry should tell you what is wrong. I know that code is correct because that is how I tighten my trail stop at a predetermined time (right now, 1555EDT), at EOD. However, I tighten using the tick count, rather than a cash value, and I tighten specifically to the entry signal. I guess I could check if that is the difference.

                    SetTrailStop() takes its start point from the current price, whatever it is. If you set it on entry, then it will take its exit based on that. You have to reset it at the time that you want. Maybe, if you strip your code of the secret details, and post just your adjustment code, I can take a look.

                    In the meantime, here is a section of my log. See how on 3/21/13, I am adjusting my exit for my short entry continually down as each bar closes, and how on 3/22/13, I am adjusting my exit for my long entry on the exact same strategy, upwards as each bar closes. (My adjustment is actually variable, designed to trail each time just 1-tick below the bar that closed, but only adjusted if the price movement is favorable).
                    My problem was that I didn't want to set it on entry. I've thrown in the towel on SetTrailStop and I'm working on setting up a Stop variable to keep track of my stop on each tick, then using if (Close[0] < StopVariable) ExitLong. Haven't figured it out completely yet so I'll be working on it more after the close. Can you direct me to a help section on adjusting a trailing stop? I'm not familiar with that.

                    I hadn't coded in 14 years until I started working with NinjaTrader so it's been a struggle so far, but I'm enjoying it so far despite the frustrations. Thanks very much for your help.

                    Comment


                      #11
                      Originally posted by peteM View Post
                      My problem was that I didn't want to set it on entry.
                      Which most likely is your problem. You need to have set something, tied to the entry, before you can adjust it.

                      Typically if you want to have no Trail, why not just set it to a very large value (like the entry price, which effectively, sets the initial trail price at 0.00? Then adjust it later. I actually set my initial trail to my disaster stop value, and adjust it when we get to EOD, just in case we get one of those humongous reversals that come seemingly out of nowhere at the EOD.
                      Can you direct me to a help section on adjusting a trailing stop? I'm not familiar with that.
                      There is no section that specifically deals with that. It is a matter of extrapolation from what is described, showing that one can reissue the order with different parameters. Ergo, it follows that one just needs to decide when to reissue the order, and do so. My pseudocode shows one method, based on your description. The exact mechanics will always depend on what the code is intended to do.
                      Last edited by koganam; 03-25-2013, 02:08 PM.

                      Comment


                        #12
                        Originally posted by koganam View Post
                        I actually set my initial trail to my disaster stop value
                        Ah, that's an awesome idea. I manually coded my disaster stop, yours is much smarter.

                        Thank you, going to try to put this to work,

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by usazencort, Today, 01:16 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post usazencort  
                        Started by kaywai, 09-01-2023, 08:44 PM
                        5 responses
                        603 views
                        0 likes
                        Last Post NinjaTrader_Jason  
                        Started by xiinteractive, 04-09-2024, 08:08 AM
                        6 responses
                        23 views
                        0 likes
                        Last Post xiinteractive  
                        Started by Pattontje, Yesterday, 02:10 PM
                        2 responses
                        22 views
                        0 likes
                        Last Post Pattontje  
                        Started by flybuzz, 04-21-2024, 04:07 PM
                        17 responses
                        230 views
                        0 likes
                        Last Post TradingLoss  
                        Working...
                        X