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 & Stop Loss

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

    Trailing Stop & Stop Loss

    Greetings,

    I have a trailing stop in the OnBarUpdate method of my strategy which works fine. I also wanted a stop-loss, but read that you cannot use the SetStopLoss (?) method, so I programmed into my exit condition manually within the OnBarUpdate method to exit if the current close is less than the MIN of 5 bars prior to BarsSinceEntry. - Trying to have a trailing stop and a stop loss that exits if the close of the current bar is less than the low price of the 5 bars prior to entry.

    However, the manual portion (stop loss) is not functioning and the trailing stop method seems to override all other exit methods.

    Please advise.
    Thank you,
    hbmiles2000

    #2
    Hello,

    Thanks for the post and welcome to the NinjaTrader support forum.

    This is the case, are you saying that you want to stop the auto trail and just switch to a static stop loss at a specified point in time?

    I look forward to assisting you further.

    Comment


      #3
      Brett - thanks; to answer - yes. Upon entry set stop loss and if the price moved in the direction of my trade by a certain amount, cancel the stop loss and activate a trailing stop. I'm fairly new to NT, so if you could make sure to include where (Initialize or OnBarUpdate) to include, I'd appreciate it.
      Thx again,
      hbmiles2000

      Comment


        #4
        Hello,

        Alright, you have two options to do this.

        1) Do not use the SetTrailStop() method. Instead do the auto trail and code it yourself by simply modifying the SetStopLoss() value up as the market goes higher. This would mean the strategy would need to run tick by tick however.

        2) Use ATM Strategies to do this instead.

        Comment


          #5
          Brett-thanks; so by tick-by-tick, do you mean set COBC=false??

          Comment


            #6
            Exactly!

            Then you would just make modification to the stop loss when you want it. Using this as a sample:

            Modifying the price of stop loss and profit target orders

            Comment


              #7
              Brett-thanks for having the patience with us newbies!!

              Comment


                #8
                Brett-one more newbie question - when I reset the stop loss as price moves in a certain direction using a separate if statement, do I have to program in to cancel the previous ones (so no open/naked orders) or does this happen by itself?
                Thx again,
                hbmiles2000

                Comment


                  #9
                  Hello,

                  If you use the below sample this will all happen for you with no problems and will modify the existing stop loss.

                  Let me know if I can be of further assistance.

                  Comment


                    #10
                    Originally posted by NinjaTrader_Brett View Post
                    Exactly!

                    Then you would just make modification to the stop loss when you want it. Using this as a sample:

                    Modifying the price of stop loss and profit target orders
                    Does this mean that you can not update and move the SetStopLoss if you are using a strategy that runs on a CalculateOnBarClose = true basis? Am using Renko Bars so want to make sure that certain conditions are met prior to entry? Is that possible?

                    Comment


                      #11
                      nanook77, I will have Brett get back to you tomorrow.
                      AustinNinjaTrader Customer Service

                      Comment


                        #12
                        Nanook,

                        Correct, the stop would only update on the bar close. If this is not wanted, you would need to run COBC=false, then with the following sample put the code you want to run COBC=true with the following sample will show you how to do this.



                        Let me know if I can be of further assistance.

                        Comment


                          #13
                          I have same problem. I need static stoploss when position is open and then trailing stop if the price raise in my direction. I know that Trailing stop and Stoploss both don't work. In your example http://www.ninjatrader.com/support/f...ead.php?t=3222 Stoploss only once moves. How I can do the stoploss moves to the price always (suach as trailing)?.

                          And second question. How I reset the stoploss if my stop is diferrent for long and short positions?

                          Comment


                            #14
                            Hello,

                            You can simply recall SetStopLoss as many times as you need. For example if you want the stop loss to trail the last traded price by 10 ticks, you could just use:

                            Code:
                            SetStopLoss(CalculationMode.Price, Close[0] - 10 * TickSize);
                            If you have conditional stop losses, you'd have to use the fromEntrySignal string to tie the stop to a specific long or short entry:

                            Code:
                            SetStopLoss("myShortStop", CalculationMode.Price, myShortPrice, false);
                            SetStopLoss("myLongStop", CaclulateionMode.Price, myLongPrice, false);
                            MatthewNinjaTrader Product Management

                            Comment


                              #15
                              Ok, thanks.
                              I have different stop losses only once before open positions. Trailing stop is equal.
                              Part of my code:
                              {
                              if (Position.MarketPosition == MarketPosition.Long)
                              { if (Close[0] > Position.AvgPrice + 10* TickSize)
                              { SetStopLoss(CalculationMode.Price, Position.AvgPrice+TickSize);
                              }
                              }
                              else if (Position.MarketPosition == MarketPosition.Short)
                              {
                              if (Close[0] < Position.AvgPrice - 10* TickSize)
                              {SetStopLoss(CalculationMode.Price, Position.AvgPrice-*TickSize);
                              if ( Stochastics(3, 14, 3).D[0] <= 20)
                              { SetStopLoss("", CalculationMode.Price, Low[0]-TickSize,false);
                              EnterLong(DefaultQuantity,"");}
                              if ( Stochastics(3, 14, 3).D[0] >= 80)
                              { SetStopLoss("", CalculationMode.Price, High[0]+TickSize,false);
                              EnterShort(DefaultQuantity, "");}

                              1. Reset stop-loss is necessary? For example, on the beginning:
                              "if (Position.MarketPosition == MarketPosition.Flat)
                              {SetStopLoss(CalculationMode.Ticks, stoplossticks); }"
                              Because if necessary I must use the fromEntrySignal .

                              2. I move first stop to breakeven and then I can trailing it as you showed before. SetStopLoss(CalculationMode.Price, Close[0] - 10 * TickSize);
                              Where in my code I can post this code?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by rocketman7, Today, 02:12 AM
                              5 responses
                              23 views
                              0 likes
                              Last Post rocketman7  
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              7 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by samish18, 04-17-2024, 08:57 AM
                              17 responses
                              66 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by briansaul, Today, 05:31 AM
                              1 response
                              15 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by PaulMohn, Today, 03:49 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Working...
                              X