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

Getting ATR value, converting to ticks, using it within a strategy

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

    Getting ATR value, converting to ticks, using it within a strategy

    Is there any way to get an ATR value, or a value from something like supertrend (or another indicator).... take that, convert it to ticks, then use that as your stoploss, and then 2x stoploss as the target?

    Essentially to create a solid profit over time, 2x ATR (or even 1.5ATR might be acceptable), as a stop loss, then target-ticks = 2x or 3x or 4x ATR?

    I can probably do this unlocking / dropping to code, but is there a way to get the strategy builder to do it? Failing that, is this type of behavior in the master ninjascripters code repo somewhere?

    Thanks!

    #2
    Hello tracer88,

    Thank you for your note.

    You can actually set this up in the Builder, though it might actually be a little more elegant to just unlock the code and set up the logic manually. I've attached a super simple example strategy that takes the ATR and multiplies it by a user defined multiplier and uses that as the number of ticks for the Stop Loss.

    You can use the same logic to add a profit target - you'd need to set it up it's own multiplier as a user input and then set up another variable to hold the result for the profit target. You can then use the variable with the result as the number of ticks for the target, much like I've set up the stop loss.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      I tried using this but I keep getting the Profit and Stop to be the default value of 1 tick.
      Last edited by kal1212; 05-15-2020, 08:18 PM.

      Comment


        #4
        Hello kal1212,

        Thank you for your note.

        Could you please provide screenshots of your modifications to the example strategy that don't seem to be working for you?

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by kal1212 View Post
          I tried using this but I keep getting the Profit and Stop to be the default value of 1 tick.
          Same here

          Comment


            #6
            Originally posted by NinjaTrader_Kate View Post
            Hello tracer88,

            Thank you for your note.

            You can actually set this up in the Builder, though it might actually be a little more elegant to just unlock the code and set up the logic manually. I've attached a super simple example strategy that takes the ATR and multiplies it by a user defined multiplier and uses that as the number of ticks for the Stop Loss.

            You can use the same logic to add a profit target - you'd need to set it up it's own multiplier as a user input and then set up another variable to hold the result for the profit target. You can then use the variable with the result as the number of ticks for the target, much like I've set up the stop loss.

            Please let us know if we may be of further assistance to you.
            Thanks Kate. Looking at the code I was wondering would it not make sense to divide the ATR value by ticks to actually get the ticks? And ATR is returned in points which might not be exact to the tick value. Like say 2.13 ES points whose tick value is 0.25 which is 4 ticks to a point. So would it not make sense to round off the ATR value first and then divide it by ticks?
            Thank you.

            Comment


              #7
              Hello Trader17,

              Thank you for your reply.

              I understand you have a ticket with my colleague Brandon on this topic and he provided you with an example script I created from a different thread. We would ask that you work with him in that ticket.

              ATR is returned in terms of price. When NinjaTrader receives a request to submit an order, it automatically rounds any limit price or stop price to the nearest tick for that specific instrument.

              Please let us know if we may be of further assistance to you.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Thanks Kate. My question was specific to the example you provided. So when do you use Math.Round in Ninjatrader? For things besides targets and stops as NT does round those off? And in the example you provided above why do you have an input for ATRStopLoss? So whether ATR is used directly in point from as returned and say subtracted directly from a low and set as price in a stop loss or converted to ticks and set as ticks in a stop loss NT will round it off automatically taking the tick value automatically from the Instrument on the chart?
                Thanks a lot.

                Comment


                  #9
                  Hello Trader17,

                  Thank you for your reply.

                  As previously stated, when NinjaTrader receives a request to submit an order, it automatically rounds any limit price or stop price to the nearest tick for that specific instrument. In other scenarios, you may want to use Math.Round depending on your intentions.

                  In that particular example, ATRStopLoss is simply used as a variable for holding the calculated ATR times the Multiplier, which is converted to an integer value and used as the number of Ticks for the stop loss.

                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks Kate. I could be totally wrong here but from what I see there is an input for ATRStopLoss set to 1 as an input, then it is used in State.DataLoaded and then calculated again under OnBarUpdate. Is that why it is using "1' from the input value the users above are saying it sets the stop to 1 and not the actual ATR value? I understand the input for the ATR Multiplier.
                    Thank you as always.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Kate View Post
                      Hello Trader17,

                      Thank you for your reply.

                      I understand you have a ticket with my colleague Brandon on this topic and he provided you with an example script I created from a different thread. We would ask that you work with him in that ticket.

                      ATR is returned in terms of price. When NinjaTrader receives a request to submit an order, it automatically rounds any limit price or stop price to the nearest tick for that specific instrument.

                      Please let us know if we may be of further assistance to you.
                      Congratulations on your third anniversary at Ninja Trader!! Keep up the good work. In what you wrote above so Ninja will round off at the final step just before placing the order. So it will take the ATR and directly add/subtract form a high/low or divide by ticks if we are using ticks in a SetStop and use that final number to round off to ticks or price for the actual instrument on the chart. Does this work if we are not using SetStop methods and instead use something like say if ask is less than the previous low plus ATR*2 then exit the trade? Or regardless when using it as an exit method Ninja still rounds it off?
                      Thanks.

                      Comment


                        #12
                        Hello Trader17,

                        Thank you for your reply.

                        Would you be using a market order or a limit/stop limit order? If a market order, it doesn't matter since you're not supplying a price. If it's a limit or stop limit, then that would apply to the limit or stop prices, yes.

                        Please let us know if we may be of further assistance to you.
                        Kate W.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by Trader17 View Post
                          Thanks Kate. I could be totally wrong here but from what I see there is an input for ATRStopLoss set to 1 as an input, then it is used in State.DataLoaded and then calculated again under OnBarUpdate. Is that why it is using "1' from the input value the users above are saying it sets the stop to 1 and not the actual ATR value? I understand the input for the ATR Multiplier.
                          Thank you as always.
                          Did you see this Kate?

                          Comment


                            #14
                            Originally posted by NinjaTrader_Kate View Post
                            Hello Trader17,

                            Thank you for your reply.

                            Would you be using a market order or a limit/stop limit order? If a market order, it doesn't matter since you're not supplying a price. If it's a limit or stop limit, then that would apply to the limit or stop prices, yes.

                            Please let us know if we may be of further assistance to you.
                            Thanks Kate. So when exactly do you use Math.Round to round off ATR to the nearest tick value? Like say when say adding 3 ticks to the ATR for example? Or NT8 will round that off to when it comes to exiting without the Set Method?
                            Thanks.

                            Comment


                              #15
                              Hello Trader17,

                              Thank you for your reply.

                              When NinjaTrader receives a request to submit an order, it automatically rounds any limit price or stop price to the nearest tick for that specific instrument.

                              When debugging and/or printing out order information, this may not be apparent. NinjaTrader includes a Method named RoundToTickSize to apply the same internal rounding to any value you wish, which can help make comparisons easier.

                              Here's an example strategy from our help guide that illustrates this:



                              Please let us know if we may be of further assistance to you.
                              Kate W.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by frankthearm, Yesterday, 09:08 AM
                              13 responses
                              45 views
                              0 likes
                              Last Post frankthearm  
                              Started by PaulMohn, Today, 12:36 PM
                              2 responses
                              16 views
                              0 likes
                              Last Post PaulMohn  
                              Started by Conceptzx, 10-11-2022, 06:38 AM
                              2 responses
                              53 views
                              0 likes
                              Last Post PhillT
                              by PhillT
                               
                              Started by Kaledus, Today, 01:29 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by yertle, Yesterday, 08:38 AM
                              8 responses
                              37 views
                              0 likes
                              Last Post ryjoga
                              by ryjoga
                               
                              Working...
                              X