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 jclose, Today, 09:37 PM
              0 responses
              5 views
              0 likes
              Last Post jclose
              by jclose
               
              Started by WeyldFalcon, 08-07-2020, 06:13 AM
              10 responses
              1,414 views
              0 likes
              Last Post Traderontheroad  
              Started by firefoxforum12, Today, 08:53 PM
              0 responses
              11 views
              0 likes
              Last Post firefoxforum12  
              Started by stafe, Today, 08:34 PM
              0 responses
              11 views
              0 likes
              Last Post stafe
              by stafe
               
              Started by sastrades, 01-31-2024, 10:19 PM
              11 responses
              169 views
              0 likes
              Last Post NinjaTrader_Manfred  
              Working...
              X