• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trailing stop loss

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

    trailing stop loss

    I think I have it figured out, but was wondering if someone could check my assumptions.


    I have a running strategy with CalulateOnBarClose set to true.

    Under this section --> protected override void Initialize(), I have CalculateOnBarClose = true;

    Under this section --> protected override void OnBarUpdate(), I have SetTrailStop("entryname", CalculationMode.Ticks, STP_LOSS, false);




    STP_Loss is a variable that I set when I enable the strategy

    What I am trying to have happen is that entry signals are only triggered on bar close, which is what is happening.

    However, I do not want the trailing stop loss calculated/adjusted only on bar close. I want the trailing stop to adjust real time, tick by tick, a set amount (STP_LOSS variable) behind the market.

    I previously had settrailstop under Initialize(). It seemed that the stop wasn't trailing tick by tick so I moved it to OnBarUpdate().

    Is the code above appropriate? Does it matter which section settrailstop is under?

    Thanks,
    m6

    #2
    Hello medicsix,

    Thanks for your post.

    If you are intending to use the same SetTrailStop() for all entries, putting the trail statement in the initialize method is the proper place for it.

    You can place it in the OnBarUpdate() but the update performance would be the same. A typical reason for putting it in the OnBarUpdate() section would be: if you are intending to change the amount of trail stops on different entries, for example trail by 10 ticks this time and trail by 5 ticks another time. The limitation here is that you would need to ensure that the correct level of trail stop is set before making the next entry because the trail stop is immediately applied when the entry is made and the method retains the last value used.

    To clarify, using the same example, if you set once to 10 ticks then the next to 5 ticks and on the 3rd one wanted 10 ticks again, you would have had to set it back to 10 ticks before the entry is made. This is easily done by making sure that you first set the trail stop level desired before the entry code.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Okay, thanks. That's what I was looking for.

      Comment


        #4
        Hi PaulH,

        I am facing the same issue - trailing stop is not trailing - behaving as regular hard stop. It is placed in Initialize() and placing it in OnBarUpdate() makes no difference.
        This is what I am using:
        Strategy - Calculate.OnPriceChange

        SetTrailStop(CalculationMode.Percent, 0.16);

        When I checked in my broker app (IB), it shows that Stop-loss was placed as a regular Stop-loss (not trailing).
        What am I missing pls?

        Thanks!

        Comment


          #5
          Hello Paco0,

          Thanks for your post.

          Are you also using SetStopLoss()?
          Do you see any errors listed in the "log" tab of the control center related to the strategy?
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hi Paul,

            I was very careful not to use SetStopLoss as I know it would overwrite the trail stop.. No errors in Log.

            Thank you

            Comment


              #7
              Hello Paco0,

              Thanks for your reply.

              I understand that there are no errors and that you are also not using SetStopLoss().

              The Trail stop will move up for each tick into profit your trade goes. When the stop moves depends on the Calculation mode of the strategy. If it is run with CalculateOnBarClose = false, then the stop will move on a tick by tick basis. If the strategy is run with CalculateOnBarClose = true, then the stop can only move when the current bar closes (and assuming that the trade went into profit during the bar).


              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by saltminer, Today, 05:19 PM
              0 responses
              3 views
              0 likes
              Last Post saltminer  
              Started by martyn73, Today, 04:18 PM
              0 responses
              2 views
              0 likes
              Last Post martyn73  
              Started by aprendiz, Today, 03:42 PM
              0 responses
              2 views
              0 likes
              Last Post aprendiz  
              Started by 1001111, Today, 09:10 AM
              1 response
              18 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Started by usero86, Today, 06:02 AM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_ChrisL  
              Working...
              X