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

Adjusting stop order to trailing stop during trade

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

    Adjusting stop order to trailing stop during trade

    Hi,

    Objective: To adjust a fixed stop loss order to a trailing stop based on a price target

    For example, lets say I take a long position. I take the position, set the stop loss. Once the trade is far enough in profit and hits a value i specify, i would like to adjust that stop loss order to become a trailing stop order with a particular trailing value. Is this at all possible? There is no precoded existing solution from my understanding so this has to be manually coded.

    A friend of mine is developing our strategy and he has been having trouble trying to develop this. Is anyone aware of an existing solution? I did a forum search and didnt find anything that works.

    Appreciate any answers and responses. Thanks for your time

    #2
    Hello smegey,

    Thank you for your post.

    You would need to use the Exit methods instead of SetStopLoss and SetTrailStop, as you cannot use both Set methods for Stop Loss together.

    This means adding your own logic to set the Exit orders as your Stop Loss and then adjusting them based on the price target.

    Please let me know if you have any questions.

    Comment


      #3
      Hi,

      I am currently coding the situation mentioned here below. And I haven't find any way to make trailing stop manually. There are just too many scenarios which don't play right, and thus reserved word for trailing stop must be used.

      So the situation is this: you buy two contracts. Then if market goes into wrong direction you sell them. If market goes into right direction you sell one contract and at that price set trailing stop. I have been able to write down those "bad" trade stops manually so there wont be any set methods used before setting trailing stop. However trailing stop won't work. I am not sure why, but it seems that in the first time trailing stop is entered it won't works properly and after that it just closes contracts that are in the market.

      So is there any way to "clear" that trailing stop if it is not hit or do you have any thoughts why trailing stop would work badly? I can send you pieces or pictures about my code and where it makes wrong calls if that could help to find a solution.

      Comment


        #4
        Hello jjsshh,

        Thank you for your post and welcome to the NinjaTrader Support Forum!

        You would need to reset the SetTrailStop() when flat. For example:
        Code:
        if(Position.MarketPosition == MarketPosition.Flat)
        {
        SetTrailStop(CalculationMode.Ticks, 10); // reset to a default distance
        }
        Then when the position is taken and your SetTrailStop() goes in it will not use the previous value but the 10 ticks and then update when your SetTrailStop() method is called in your logic.

        Also keep in mind the Set and Exit methods cannot be used for the same position as one will be ignored base don the Internal Order Handling Rules at the following link: http://ninjatrader.com/support/helpG...d_approach.htm

        Comment


          #5
          Hi Patrick,

          and thank you for help. I am really close to get this finished with SetTrailStop, but there are still couple of trades that doesn't work properly. I checked those Internal Order Handling Rules, but not sure if those are making the problem, because I don't see any problems in log. So does those those rules apply if you are using market orders (ExitLong()) and SetTrailStop to same trade? For example if the code is something like:

          EnterLong(long1);

          if (condition==1 ) {
          ExitLong(long1);
          }

          if (condition == 2) {
          SetTrailStop (long1);
          }

          Comment


            #6
            Hello jjsshh,

            Thank you for your response.

            One of the orders should be ignored. You can enabled TraceOrders and then open the Output under Tools > Output to see the information on the orders.

            TraceOrders: http://ninjatrader.com/support/forum...ead.php?t=3627

            Comment


              #7
              Hi again,

              is it possible to somehow enter orders inside bars without using limitOrders. As far as I have understood all market Orders are executed at next bar open. If for example I have a trigger price for entry inside 15 min bar, I must wait for the bar to complete to get my entry.

              Comment


                #8
                Hello jjsshh,

                Thanks for your post.

                If you are using CalculateOnBarClose = true then yes entry/exit orders are placed on the subsequent bars. If you are using CalculateOnBarClose = false, then orders are placed intrabar.

                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Is this the case also when backtesting with historical data? I understood that this is impossible, because bars cannot see in which order ticks are coming in.

                  Comment


                    #10
                    Hello jjsshh,

                    Thanks for your reply.

                    Backtesting is the same as using CalculateOnBarClose = true. The strategy does not execute until the end of the bar and then makes all decisions at that point (such as order entry/exit which actually occur on the subsequent bar).

                    You can add a lower time frame data series to your strategy to provide the ability to enter/exit orders intrabar (on your larger timeframe). Here is a link to one of our reference sample on the subject of: "Backtesting NinjaScript Strategies with an intrabar granularity": http://ninjatrader.com/support/forum...ead.php?t=6652
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Ok,

                      thanks for your help. It was how I thought. Have to give a shot for secondary bar series.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by George21, Today, 10:07 AM
                      0 responses
                      5 views
                      0 likes
                      Last Post George21  
                      Started by Stanfillirenfro, Today, 07:23 AM
                      8 responses
                      23 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by DayTradingDEMON, Today, 09:28 AM
                      2 responses
                      16 views
                      0 likes
                      Last Post DayTradingDEMON  
                      Started by navyguy06, Today, 09:28 AM
                      1 response
                      6 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by cmtjoancolmenero, Yesterday, 03:58 PM
                      8 responses
                      32 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X