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

Strategy Builder: Add ATR-value as TakeProfit and StopLoss

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

    #46
    Hello Daryl Haaland,

    Not using simulated stops and having them work on the exchange/broker.

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #47
      Original poster; apologies in advance for hijacking your thread. I have a ATR related question and don't want to add another thread.

      Question:

      Code:
      			if(Position.MarketPosition==MarketPosition.Long)
      				
      			{
      				SetProfitTarget("Target1", CalculationMode.Price, Position.AveragePrice+(Target1 * ATR1[0]));
      				SetProfitTarget("Target2", CalculationMode.Price, Position.AveragePrice+(Target2 * ATR1[0]));
      				SetProfitTarget("Target3", CalculationMode.Price, Position.AveragePrice+(Target3 * ATR1[0]));		
      	
      			}
      			
      			if(Position.MarketPosition==MarketPosition.Short)
      				
      			{
      				SetProfitTarget("Target1", CalculationMode.Price, Position.AveragePrice-(Target1 * ATR1[0]));
      				SetProfitTarget("Target2", CalculationMode.Price, Position.AveragePrice-(Target2 * ATR1[0]));
      				SetProfitTarget("Target3", CalculationMode.Price, Position.AveragePrice-(Target3 * ATR1[0]));		
      	
      			}
      *above is "ATR1" because I have a multi period strategy. Therefore, I created ATR1 on my daily bars.

      Is the above the correct method to set PT based on ATR? I understand you can't add it to State.Configure?

      Basically my logic states:

      if XYZ happens
      {enter long}

      if abc happens
      {enter short}

      then I'm create the above conditions:

      if long
      {set profit target using ATR}

      if short
      {set profit target using ATR}

      Workable method? Seems to be working fine in my strategy.

      Oh btw, OP; thanks for posting the vol stop indicator. seems super interesting and I will be doing some research on it soon. I'm asking this because when I ran the code, it took my about 10 seconds to run 1 year worth of data. Prior to the code it was taking me 3 seconds to run through all the data. So i guess it's a code efficiency related question/best practice.
      Last edited by staycool3_a; 01-10-2018, 08:14 PM.

      Comment


        #48
        Erm.... I'm not the original poster by a long shot. I merely was asking questions related to attaching an indicator to the ATR type indicator for a trailing stop or presumably other types of actions or other conditions.

        You have a cool idea there. Although my preference is that I personally don't use a defined profit target. Likely a great way to perform predictable scalps based on the price action range. you are welcome for the VolStop indicator and probably can incorporate it into your strategy as either a trailing stop like i have or maybe even use the opposite band as a profit target. Just use two instances of the same indicator one as the trail and the other as your target with long/short variables for each so you can set your ATR multiplier properly. The actual ninja trader people would probably better be able to correct my many mistakes in how I've roughly described it to you.

        Originally posted by calhawk01 View Post
        Original poster; apologies in advance for hijacking your thread. I have a ATR related question and don't want to add another thread.

        Question:

        Code:
                    if(Position.MarketPosition==MarketPosition.Long)
                        
                    {
                        SetProfitTarget("Target1", CalculationMode.Price, Position.AveragePrice+(Target1 * ATR1[0]));
                        SetProfitTarget("Target2", CalculationMode.Price, Position.AveragePrice+(Target2 * ATR1[0]));
                        SetProfitTarget("Target3", CalculationMode.Price, Position.AveragePrice+(Target3 * ATR1[0]));        
            
                    }
                    
                    if(Position.MarketPosition==MarketPosition.Short)
                        
                    {
                        SetProfitTarget("Target1", CalculationMode.Price, Position.AveragePrice-(Target1 * ATR1[0]));
                        SetProfitTarget("Target2", CalculationMode.Price, Position.AveragePrice-(Target2 * ATR1[0]));
                        SetProfitTarget("Target3", CalculationMode.Price, Position.AveragePrice-(Target3 * ATR1[0]));        
            
                    }
        *above is "ATR1" because I have a multi period strategy. Therefore, I created ATR1 on my daily bars.

        Is the above the correct method to set PT based on ATR? I understand you can't add it to State.Configure?

        Basically my logic states:

        if XYZ happens
        {enter long}

        if abc happens
        {enter short}

        then I'm create the above conditions:

        if long
        {set profit target using ATR}

        if short
        {set profit target using ATR}

        Workable method? Seems to be working fine in my strategy.

        Oh btw, OP; thanks for posting the vol stop indicator. seems super interesting and I will be doing some research on it soon. I'm asking this because when I ran the code, it took my about 10 seconds to run 1 year worth of data. Prior to the code it was taking me 3 seconds to run through all the data. So i guess it's a code efficiency related question/best practice.

        Comment


          #49
          Hello calhawk01,

          Thank you for your note.

          You could do it that way and yes, you shouldn’t make those SL PT calls in State.Configure.

          You could also set a variable on the order submission, for example,

          Code:
          if(Close[0]>0)
          {
          EnterLong("EntryOrder ",);
          tPrice= Target1 * ATR1[0];
          }
          Then submit the following within OnOrderUpdate, similar to the attached example.

          SetProfitTarget("EntryOrder ", CalculationMode.Price, order.AverageFillPrice-( tPrice));

          See OnOrderUpdate,


          Please let us know if you need further assistance.
          Attached Files
          Last edited by NinjaTrader_AlanP; 01-11-2018, 09:42 AM.
          Alan P.NinjaTrader Customer Service

          Comment


            #50
            Originally posted by Harvard View Post
            Hello everybody,

            has someone figured out yet how to implement an ATR-Trailing-Stop with the Strategy Builder?

            Kind regards,
            Harvard
            Hi. I am using the strategy builder and testing something out. It is a simple MA crossover that trades both long and short. I have imported the ATRtrailingstop indicator into NT8 and it works fine (I can see it on charts). I want to use the MA crossover for entries and JUST the ATRtrailstop for exits. How would I go about putting this ATRtrailstop indicator into the strategy builder to have it determine my exits. I have tried a few different ways, but having no luck.

            Comment


              #51
              • Hi. I am using the strategy builder and testing something out. It is a simple MA crossover that trades both long and short. I have imported the ATRtrailingstop indicator into NT8 and it works fine (I can see it on charts). I want to use the MA crossover for entries and JUST the ATRtrailstop for exits. How would I go about putting this ATRtrailstop indicator into the strategy builder to have it determine my exits. I have tried a few different ways, but having no luck. Thanks in advance.

              Comment


                #52
                Hello adams016,

                Thanks for your post.

                The Strategy Builder places SetProfitTarget and SetStopLoss in State.DataLoaded before data begins to be processed. This means that the value for the stop loss will not update with appropriate values as the strategy processes data.

                SetAutoTrail() can set auto trails but is not provide the flexibility of placing your own stop loss with an ExitLongStopMarket() submission with your own logic under Conditions and Actions.

                To build your own trailing stop using this indicator, I would suggest the following:

                1. Create your own logic in Conditions and Actions that checks if you are in a position and if your trailing stop should be active.
                2. If the trailing stop should be active, submit a ExitLongStopMarket() order with the appropriate value from the ATR trailing stop indicator. This will keep your stop alive and will update the stop to a new level as the ATR value updates (Stop orders and limit orders must be sent with each iteration of OnBarUpdate() in order to keep the order alive)

                You may wish to use logic to store the Upper or Lower plots to a variable to ensure that you are submitting valid values to the exit method.

                The Managed Approach documentation provides clear direction for creating appropriate order logic. While this provides direction through basic NinjaScript examples, the concepts are applicable for strategies built with the Strategy Builder as the Strategy Builder generates Managed Approach code. I also included a link to the Strategy Builder 301 tutorial that can provide direction for using the Builder.

                Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

                Strategy Builder 301 - https://www.youtube.com/watch?v=HCyt90GAs9k

                Please let us know if you have any questions.
                JimNinjaTrader Customer Service

                Comment


                  #53
                  Thanks Jim. Do you mean this should be done in the strategy builder itself, or is this some form of coding I have to do? Pretty new to all this. When adding an action to exit long, the only market order is Market if touched. Thanks again.

                  Comment


                    #54
                    Hello adams016,

                    The instruction was for using the Strategy Builder.

                    While the Managed Approach documentation includes programming examples, it can still provide some direction for opening and closing positions with the Managed Approach. (The strategy code that the Builder generates) It also documents internal order handling rules which are important to understand when designing strategies.

                    Strategy Builder 301 should be the first stop when creating a strategy with the Builder. I typically would suggest to start with very simple strategies to familiarize yourself with the Builder and NinjaScript strategies, and then to experiment creating your own custom logic.

                    "Exit long position by a stop order" under Actions will create a ExitLongStopMarket() order method.

                    Please let us know if you have any additional questions.
                    JimNinjaTrader Customer Service

                    Comment


                      #55
                      Thanks Jim. Do you mean that I should not use the stops and targets section in strategy builder. Instead, I should use a separate set in conditions and actions to say that if price crosses below ATRtrailing (condition) then ExitLong (action). Does this make sense? Thanks again.

                      Comment


                        #56
                        Yes, I would advise to create your own logic for a custom trailing stop in Conditions and Actions since Stops and Targets would be better suited for stops and targets with a static distance.

                        Let us know if we can be of further assistance.
                        JimNinjaTrader Customer Service

                        Comment


                          #57
                          This is perfect. I've done this and got it working. The strategy seems to be executing the next day at the open, rather than at the close of the previous day. If the condition is such that price has to close above another condition for an entry to be made, can this not execute on that same close, rather than the following morning? I.e. close for market is at 22:00 BST, so at 21:59 execute trigger. I suppose we would have to specify that the close is say at 21:55, so that the system has time to execute before market close? Or would there be a simpler way?

                          Comment


                            #58
                            Hello adams016,

                            Bar closures are triggered once the next bar starts developing. You could have your strategy run against a data series that forms bars in a smaller interval and then use a time check to determine if you should submit an order before the market close. For example, run against a 5 minute data series and check that the timestamp of the iterating bar is greater than or equal to 21:55 and less than or equal to 22:00 in Conditions and Actions to submit your order.

                            I look forward to being of further assistance.
                            JimNinjaTrader Customer Service

                            Comment


                              #59
                              Hi,

                              i created the variables in NT8 and added the necessary conditions, actions and stops&targets. When the order is placed it immediately stops out. I have selected pips in the calculation mode. I have tried price, etc, but then the orders are not even placed.

                              How can I fix this? My thinking is to place the entry order at ATR*0.25 above the closing candle's high. The the stop is ATR*2 below the entry price and the target ATR*2 above the entry.

                              If i understand correctly the ATR on the indicator window in the chart is indicated in price, rather than pips?

                              Comment


                                #60
                                I think you need to set that value to ticks and then use it in the stop and target.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by xiinteractive, 04-09-2024, 08:08 AM
                                2 responses
                                10 views
                                0 likes
                                Last Post xiinteractive  
                                Started by Irukandji, Today, 09:34 AM
                                1 response
                                3 views
                                0 likes
                                Last Post NinjaTrader_Clayton  
                                Started by RubenCazorla, Today, 09:07 AM
                                1 response
                                5 views
                                0 likes
                                Last Post RubenCazorla  
                                Started by TraderBCL, Today, 04:38 AM
                                3 responses
                                25 views
                                0 likes
                                Last Post NinjaTrader_Jesse  
                                Started by WeyldFalcon, 08-07-2020, 06:13 AM
                                11 responses
                                1,423 views
                                0 likes
                                Last Post jculp
                                by jculp
                                 
                                Working...
                                X