• 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

TrailStop does not work properly

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

    TrailStop does not work properly

    Hi,
    I am trying to configure a trailing stop in my strategy.

    I want to enable trailing stop, after a certain ticks have been made in the right direction. I added an integer variable TrailProfitTrigger that I want to use as an offset between the Average position price and the current close[0].

    The problem is that the trailing stop is always executed without any reference to the offset in the averge position price and the current close.

    It acts as if I have a fixed TrailingStop that is always been added simultaneously with the orde.

    Here is the code that I am using for my long entries...


    if (Position.MarketPosition == MarketPosition.Long
    && Position.AvgPrice + TrailProfitTrigger * TickSize <= Close[0])


    {
    SetTrailStop("EnterLong", CalculationMode.Ticks, TrailingProfitTaker, false);
    }


    Any Ideas?

    #2
    Hello nikolaalx,

    Thank you for your post.

    In Initialize() are you using SetTrailStop() or SetStopLoss()?
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      I do not have either one.

      I place each stop individually when an entry is made as I know the SetStopLoss always overrides the TrailStop...if placed in the intitialize section.

      Here is a copy of my Initialize section:

      protected override void Initialize()
      {

      Add(ROC(ROCPeriod));
      Add(RSI(RSIPeriod, 3));
      Add(VMA(VMAFastPeriod, 9));
      Add(VMA(VMASlowPeriod, 9));
      Add(PeriodType.Minute, SecondBars);



      My biggest concern is why the trail stop is being triggered improperly.

      It is supposed to be triggered when the price of the instrument is in the profit zone. Instead, it is triggered instantly.

      The TrailingStop itself is executed properly. The problem arises from wrong triggering.

      Comment


        #4
        Hello nikolaalx,

        Thank you for your response.

        I place each stop individually when an entry is made
        Can you provide this section of your code? Is this when the entry is placed or in OnExecution() when the entry fills?
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          Sure,
          here is the code for the long entry trail stop.

          // Trail Stop Placer

          if (Variable4 == 1 //Var 4 is enabled whenever I have an active entry
          && Position.MarketPosition == MarketPosition.Long)

          {
          PrintWithTimeStamp("Trail Stop Long Placed at " + (Close[0] + TrailProfitTrigger * TickSize));

          if (Position.AvgPrice < Close[0] - TrailProfitTrigger * TickSize )
          {
          SetTrailStop("EnterLong", CalculationMode.Ticks, TrailingProfitTaker, false);
          }

          }



          Originally posted by NinjaTrader_PatrickH View Post
          Hello nikolaalx,

          Thank you for your response.


          Can you provide this section of your code? Is this when the entry is placed or in OnExecution() when the entry fills?

          Comment


            #6
            Hello nikollalx,

            Thank you for your response.

            Would you mind if we tested the full script on our end? You can send the .cs file for the strategy to platformsupport[at]ninjatrader[dot]com with this thread as a reference if you prefer: "http://www.ninjatrader.com/support/forum/showthread.php?t=72458"
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              Hello nikolaalx,

              Thank you for your patience.

              If you SetTrailStop in the strategy OnBarUpdate() method, you should always reset the trail stop price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your trail stop order on your next open position.

              You strategy is behaving in the same manner on my end. So each time we take a position it automatically updates to the Trail Stop point needed.

              If you want to wait until a specific level is reached you would want to implement your own trail logic using the Exit methods you wish.
              Patrick H.NinjaTrader Customer Service

              Comment


                #8
                I currently have the entries organized in the following order:

                1. When entry conditions are met, a limit order is placed and Variable4 is changed to 1.
                2. Then I have one block that monitors if the current market position = Long. Only in the event if the position is long (a.k the limit order has actually been filled and now we have an open position), and in the event Variable4 = 1 (which stands for enabled Trail Stop), then I do a nested check for if (Position.AvgPrice < Close[0] - TrailProfitTrigger * TickSize ) and then place the trail stop.

                With this being said, I am not sure what you mean by "you should always reset the trail stop price/offset value when your strategy is flat". Basically the TrailStop is placed only when the strategy is not flat.

                Also how can I reset the Trail/Offset? I am not sure I understand this....as those are not stored under any variables, They are executed with a fixed offset/fixed price.

                I am sorry if those questions seem stupid, but I have very basic understanding on programming. If you could elaborate and give an example, it will be very much appreciated!

                Here is the code for the Trail placer that I mentioned above.

                if (Variable4 == 1
                && Position.MarketPosition == MarketPosition.Long
                )
                {
                PrintWithTimeStamp("Trail Stop Long Placed at " + (Close[0] + TrailProfitTrigger * TickSize));
                if (Position.AvgPrice < Close[0] - TrailProfitTrigger * TickSize )
                {
                SetTrailStop("EnterLong", CalculationMode.Ticks, TrailingProfitTaker, false);
                }

                }

                Comment


                  #9
                  Hello nikolaalx,

                  Thank you for your response.

                  The SetTrailStop will be used again on the next entry - immediately.

                  For information on resetting the value please visit the following link and take a look at the SetStopLoss() being reset (same idea here): http://www.ninjatrader.com/support/f...ead.php?t=3222
                  Patrick H.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by ballboy11, Today, 11:57 AM
                  1 response
                  5 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by swcooke, Today, 09:41 AM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Jim  
                  Started by Catalon, Today, 10:02 AM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Jim  
                  Started by pel11, Yesterday, 06:25 PM
                  1 response
                  11 views
                  0 likes
                  Last Post NinjaTrader_ChrisL  
                  Started by dmackay41, Today, 09:35 AM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_SergeyS  
                  Working...
                  X