Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Settrailstop()

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

    Settrailstop()

    Hello,

    I know there are numerous threads and examples about this but they are kind of custom responses to each specific situation. I couldn't find a direct answer to my (simple) question. I just need to place a trailing order in a strategy. I understand settrailstop() needs to be placed under OBU...

    if (whatever condition))
    {
    EnterLong("MyLongOrder");
    SetTrailStop(CalculationMode.Percent, 0.05);
    }

    but when I do that the order does not trail. I'm not using SetStopLoss()...What am I doing wrong?

    Thanks!
    Last edited by TexFly; 01-11-2018, 04:15 AM.

    #2
    Hello TexFly,

    Thanks for your post.

    I tested your example and after the order is entered (I used a long only entry) the stop is placed at 95% of the entry (you specified a 5% trail). As the order moved into profit, the trail stop maintained its 5% relationship in an upwards direction.

    I've attached a screenshot of a quick test along with the simple code used. It enters a long position and placed the settrailstop just as you show. The entry was as shown at 6690.50, a stop level would be 6690.50 * .95 = 6355.975, the actual stop was initially placed at 6356.00. As the screenshot shows the trail stop, since entry, has moved up to 6358.25. (Note the candles are compressed because the 5% trail stop is a large distance away and the screen compresses to show both candles and the stop flag)

    It is important to note that the movement of the stop is dependant upon the Calculate mode employed. If you are using Calculate.OnBarClose, then the stop is only adjusted when the current bar closes (assuming you are in profit and assuming your have moved in profit above the previous bars profit level). If you use the mode of Calculate.OnEachTick then the trailstop can adjust on a per tick basis.

    According to the helpguide, "It is suggested to call this method from within the strategy OnStateChange() method if your trail stop price/offset is static" See the #1 tip: https://ninjatrader.com/support/help...ttrailstop.htm

    If you wish to use it in the OnbarUpdate() you certainly can, however, it is a good practice to set the stop (or trailstop and/or profit target) before the entry so that the "set" methods are using correct values for the pending entry.

    Edit: Added screenshot
    Attached Files
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I'm still having issues with the trail stop. Maybe it's easier if I explain what I'm trying to accomplish so you can help me ;-)!

      a) Long position
      1-Enter position
      2- Set a trailing order of $100
      Basically make sure the position max loss is no more than $200/$x,00 but trail the order up to maximize the profit and avoid losing what earned if a down move happens


      b) Short position
      Same that long but inverted.


      Thanks!!!

      Originally posted by NinjaTrader_Paul View Post
      Hello TexFly,

      Thanks for your post.

      I tested your example and after the order is entered (I used a long only entry) the stop is placed at 95% of the entry (you specified a 5% trail). As the order moved into profit, the trail stop maintained its 5% relationship in an upwards direction.

      I've attached a screenshot of a quick test along with the simple code used. It enters a long position and placed the settrailstop just as you show. The entry was as shown at 6690.50, a stop level would be 6690.50 * .95 = 6355.975, the actual stop was initially placed at 6356.00. As the screenshot shows the trail stop, since entry, has moved up to 6358.25. (Note the candles are compressed because the 5% trail stop is a large distance away and the screen compresses to show both candles and the stop flag)

      It is important to note that the movement of the stop is dependant upon the Calculate mode employed. If you are using Calculate.OnBarClose, then the stop is only adjusted when the current bar closes (assuming you are in profit and assuming your have moved in profit above the previous bars profit level). If you use the mode of Calculate.OnEachTick then the trailstop can adjust on a per tick basis.

      According to the helpguide, "It is suggested to call this method from within the strategy OnStateChange() method if your trail stop price/offset is static" See the #1 tip: https://ninjatrader.com/support/help...ttrailstop.htm

      If you wish to use it in the OnbarUpdate() you certainly can, however, it is a good practice to set the stop (or trailstop and/or profit target) before the entry so that the "set" methods are using correct values for the pending entry.

      Edit: Added screenshot

      Comment


        #4
        Hello TexFly,

        Thanks for your reply.

        If you wish to use a trailing stop then you would not be able to use SetStopLoss as well because the SetStopLoss would override the use of SetTrailStop.

        If you use only SetTrailStop then your max stoploss will be whatever value you decide ($100) and less if your trade moves into profit.

        It sounds like you want a constant trail stop of $100 for each long or short entry order. In that case it would be recommended to put the SetTrailStop() in the State.Configure of OnStateChange() method. To trail by $100, you will need to convert that value to ticks and use the CalculationMode.Ticks. To convert to ticks you will need to know the $/Tick of your instrument. For example CL (Crude Oil) is $10.00/tick, ES is $12.50/Tick, 6E is $5.00/Tick.

        Here is an example of SetTrailStop() set in configure for 10 ticks for the CL. If it were ES then the ticks would be 8 or if it were 6E the ticks would be 20.

        protected override void OnStateChange()
        {
        if (State == State.Configure)
        {
        // Sets a trail stop of 10 tick
        SetTrailStop(CalculationMode.Ticks, 10);
        }
        }
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Paul,

          I just tried but the order does not trail. It stays at the same price level for the duration of the position no matters how high the profit is...

          What am I doing wrong?

          Thanks,


          Originally posted by NinjaTrader_Paul View Post
          Hello TexFly,

          Thanks for your reply.

          If you wish to use a trailing stop then you would not be able to use SetStopLoss as well because the SetStopLoss would override the use of SetTrailStop.

          If you use only SetTrailStop then your max stoploss will be whatever value you decide ($100) and less if your trade moves into profit.

          It sounds like you want a constant trail stop of $100 for each long or short entry order. In that case it would be recommended to put the SetTrailStop() in the State.Configure of OnStateChange() method. To trail by $100, you will need to convert that value to ticks and use the CalculationMode.Ticks. To convert to ticks you will need to know the $/Tick of your instrument. For example CL (Crude Oil) is $10.00/tick, ES is $12.50/Tick, 6E is $5.00/Tick.

          Here is an example of SetTrailStop() set in configure for 10 ticks for the CL. If it were ES then the ticks would be 8 or if it were 6E the ticks would be 20.

          protected override void OnStateChange()
          {
          if (State == State.Configure)
          {
          // Sets a trail stop of 10 tick
          SetTrailStop(CalculationMode.Ticks, 10);
          }
          }

          Comment


            #6
            Hello TexFly,

            Thanks for your reply.

            In order to assist further, please post your complete code (or attach the source file) and advise what instrument and bar type you are testing on.

            Alternatively, please feel free to write into PlatformSupport[at]NinjaTrader[dot]Com. Mark the e-mail Atten:Paul and please include a link to this thread. Please add your source code file found in Documents>NinjaTrader8>bin>Custom>Strategy>
            Paul H.NinjaTrader Customer Service

            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