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 Stop

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

    Trailing Stop

    Hello,

    how can I define in a strategy that once when the price has risen for example 3 points my trailstop is set to this price (or another price). Of course I can do this it in the dome in an ATM! But how to write it in a strategy (its not possible in the wizard)? Your "intelligent" trailstop is so good, but I don´t find a video or support how to write it down in a strategy.

    Thanks in advance and best regards.
    Tony

    #2
    Tony,

    Unfortunately this would require custom programming outside the Strategy Wizard. I suggest you check out this reference sample demonstrating how to move stops and targets. The same concept can be applied to moving trail stops. http://www.ninjatrader-support2.com/...ead.php?t=3222
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Trailing Stop

      Josh,

      thank you for you reply. Thank you for your confirmation that it´s not possible in the wizard - that´s why I asked in the support forum HOW to do it.

      Best regards
      Tony

      Comment


        #4
        Please see the reference in my previous post. That is how to do it through custom programming.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Trail Stop

          Hello Josh,

          I have worked out in the meantime what you informed me. This is how to set one time the stoploss to the breakeven - this is clear. My question refers to the "intelligent" trailstop - great thing of NinjaTrader! - and how to write stop loss - frequency - profit trigger so that these are working in the strategy same as in the manual ATM in the dome. This I can not read in the help you´ve sent.

          Thanks in advance.
          Tony

          Comment


            #6
            Tony,

            Guess I don't follow what you mean by "intelligent" trail stop. The idea of the reference shows you how to move the stops. Now what you need to do is set up your own logic to move it whenever you want. You can move it as many times as you would like at whatever frequency you would like.

            Code:
            if (Close[0] > Posiiton.AvgPrice + 5 * TickSize)
                SetStopLoss(...);
            else if (Close[0] > Position.AvgPrice + 3 * TickSize)
                SetStopLoss(...);
            See how it is tiered? You can just make it move as many times as you want.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Trail Stop

              Hello Josh,

              thank you! This is what I mean. To everyone who is reading these lines I want to say that NinjaTrader is great and they have the best support (I have tested different platforms/software and I know what I say).

              Thanks again and best regards
              Tony

              Comment


                #8
                Ironically I was just about to start another thread on this...

                I'm trying to use SetTrailStop instead of SetStopLoss using the SamplePriceModification example and having some trouble. Here's part of my code:

                // If a long position is open, allow for stop loss modification
                elseif (Position.MarketPosition == MarketPosition.Long)
                {
                // Once the price is greater than entry price+ profittargetticks, this tightens the stop even if the target wasn't filled
                if (Close[0] > Position.AvgPrice + (profittargetticks * TickSize))
                {
                SetTrailStop(CalculationMode.Ticks, Position.AvgPrice + (profittargetticks * TickSize) - (trailstopticks2 * TickSize));
                }
                }

                I've got some Variables at the top, meant to be ticks;

                privateint trailstopticks1 = 8; // Initial Trail Stop
                privateint trailstopticks2 = 6; // First Tighter Trail Stop
                privateint trailstopticks3 = 4; // Final Tighter Trail Stop
                privateint profittargetticks = 4; // Initial Profit Target above entry and First Tighter Trail Stop trigger
                privateint profittargetticksa = 6; // Final Tighten Trail Stop trigger

                Do I need to stick with SetStopLoss and all the iterations or did I do something obvious wrong.

                Thanks!

                Comment


                  #9
                  I should have added I'm trying to combine SampleScaleOut with SamplePriceModification to have a "hardcoded" ATM Strategy. SampleScaleOut works great but I'm looking to trail and tighten the second half of the position instead of use a fixed trail stop.

                  Or tighten BOTH halves of the position if my target is hit but not filled, hence the previous code.

                  Comment


                    #10
                    MXASJ, you want to use SetStopLoss if you want control over each step that is taken for the trail, the way you have set it up now, you start the trailing at a certain profit price and then it continues trailing upwards. Of course you would need to scale in first, to scale out later like the ATM templates do.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      TrailStop

                      Hello Josh and Bertrand,

                      I still have a problem with the trailsstop. For example I´ve set in a strategy a stoploss of 12 ticks and then in the code the condition once price has changed 6 ticks that the trailstop will be set 4 ticks below this price.
                      This works - sometimes(?) And sometimes the trailstop is ignored and I exit on the close or with stoploss (not trailstop). How can that be? I get crazy. How can I transmit to you the code and a jpgfile to see the problem.
                      Thanks in advance.
                      Tony

                      Comment


                        #12
                        Tony,

                        Please just copy paste the code here on the forums.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          TrailStop

                          Josh, thank you.

                          protected override void Initialize()
                          {
                          Add(PriorDayOHLC());

                          SetStopLoss("", CalculationMode.Ticks, 12, true);
                          SetProfitTarget("", CalculationMode.Ticks, 100);

                          CalculateOnBarClose = false;
                          }

                          /// <summary>
                          /// Called on each bar update event (incoming tick)
                          /// </summary>
                          protected override void OnBarUpdate()
                          {

                          // Resets the stop loss to the original value when all positions are closed
                          if (Position.MarketPosition == MarketPosition.Flat)
                          {
                          SetStopLoss(CalculationMode.Ticks, 12);
                          }

                          // If a long position is open, allow for stop loss modification to breakeven
                          else if (Position.MarketPosition == MarketPosition.Long)
                          {
                          // Once the price is greater than entry price+10 ticks, set stop loss to
                          if (Close[0] > Position.AvgPrice + 6 * TickSize)
                          {
                          SetTrailStop(CalculationMode.Ticks, 4);
                          }
                          }
                          else if (Position.MarketPosition == MarketPosition.Short)
                          {
                          // Once the price is smaller than entry price-10 ticks, set stop loss to
                          if (Close[0] < Position.AvgPrice - 6 * TickSize)
                          {
                          SetTrailStop(CalculationMode.Ticks, 4);
                          }
                          }

                          // Condition set 1
                          if (Low[0] < Low[1]
                          .....
                          .....

                          Comment


                            #14
                            tonynt,

                            You cannot mix stop loss and trail stops. You have to choose one or the other to use.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              TrailStop

                              Josh,

                              thank you. I thought I can make a "basic" stoploss so that in every case to be safe if prices retrace. So, if I delete the stoploss in my strategy I have to ask you if the trailstop is on the exchange? When the internetconnection is broken do I have a stop then on the exchange when I have no "basic" stoploss? Is then the first trailstop set on the exchange when opening the position (and is this trailstop changed everytime on the exchange when it changes referring to the strategy?)

                              Thank you.

                              Best regards
                              Tony

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AaronKoRn, Yesterday, 09:49 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post AaronKoRn  
                              Started by carnitron, Yesterday, 08:42 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post carnitron  
                              Started by strategist007, Yesterday, 07:51 PM
                              0 responses
                              12 views
                              0 likes
                              Last Post strategist007  
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,981 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Yesterday, 06:48 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post rbeckmann05  
                              Working...
                              X