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

    #16
    Are you converting the ATR value to a tick value?

    Comment


      #17
      Hi,

      Yes - tried that also. I've to try to remove ConvertToInt. Currently ATR based SL & TP don't seem to give desired PnL results, might skip it for now (or must figure out howto add ATR stops & profits based on daily ATR(14) etc.)

      br,
      Chris

      Comment


        #18
        Hello suroot,

        I would suggest adding print statements to check the values you're submitting as part of your PT and SL. I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
        Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


        I’ve provided a link covering debugging which you may find helpful.
        Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

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

        Comment


          #19
          Thanks, this is useful stuff that I have completely missed, more or less mandatory for all strategies!

          br,
          Chris

          Comment


            #20
            Hello everybody,

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

            Kind regards,
            Harvard

            Comment


              #21
              Hello Harvard,

              Thank you for writing in.

              You could pass a variable to the trailing stop method, the variable which you set in OnBarUpdate to the ATR.

              I put together a sample which will do this however I set the variable equal to the ATR value.

              Note, the ATR value can be so small the stop order will be rejected, however this is a sample for how you could accomplish what you're looking for.

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

              Comment


                #22
                Hi,

                Coded my own indicator (ATR Percentage) and got it working by using "CalculationMode.Price". (could never get it working with using Ticks). Trailing stop with ATR and setting a break-even stop is though something that seems a bigger mystery.

                br,
                Chris

                Comment


                  #23
                  Hello Chris,

                  Could you please provide more information on what it is you are asking?

                  I look forward to your reply.
                  Alan P.NinjaTrader Customer Service

                  Comment


                    #24
                    Thanks a lot

                    Comment


                      #25
                      Hi,

                      It was not a question, only replied to Harvard as I also had issues with getting trailing stop working with ATR & ticks.

                      Got it working with a forked ATR indicator though so all is fine, thanks!

                      br,Chris

                      Comment


                        #26
                        I've been grappling with this same issue for my own strategy development how do you go about converting the ATR value to a percentage or a specific tick number? Where does that calculation go in the syntax, and get stuck in, as a user variable? For example a trade entry signal indicator is generated for whatever reason. The current ATR value is 1.43, We are working in the NQ so that would translate to a rounded up value of 6 ticks. or 1.43 points, right? Now as a user I want my training stop to be placed 1.5 times the current ATR below the entry price which in this case would be 6 ticks for the ATR plus .5 of the ATR for another 3 ticks making the stop location 9 ticks below the entry price of the trade.

                        So would those two aspects of what is going on with the ATR be programmed in the strategy builder by using a group function in the condition builder? or if it has to be programmed in manually what does the line of code actually look like to have that multiplier of the function to convert the 1.43 number generated by the ATR indicator into something that the strategy can actually use in terms of ticks. Or perhaps, in the case of crude oil, pennies.

                        What does the line of code, with that functionality, actually look like?

                        Comment


                          #27
                          Hello Daryl Haaland,

                          Thank you for your note.

                          Adding a multiplier to the ATR would have to be done in the NinjaScript editor.

                          I do not have any samples of the ATR example you mention however if you'd like I can someone reach out with a list of third parties that would interested in writing this logic into your system.

                          I have provided a link to adding prints to your script, which you could use as a means of testing your calculations of the ATR stop.
                          Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


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

                          Comment


                            #28
                            ok I'm looking at your MyCustomStrategy2 strategy that you uploaded here and I'm a little confused as to what goes where exactly. in set one of that strategy you've set the TSValue=ATR(Close,14)[0]) with nothing at all in the upper window to trigger this state there is no "if" to the "all". Does this mean that this is a default state and I should create a Separate window "set" exactly like this, in front of my other entry conditions for long or short trades? "set2" seems to be more straightforward though as it is the enter long and would imply that you enter whatever long position conditions you wanted in the workspace of the above window as well presumably as any markers to go along with the long entry like arrows sounds etc in the bottom workspace window. Is this the right interpretation, Am I reading the gist of your strategy right? To create a dynamic indicator calculated trailing stop? Also is this the __more__ correct procedure for creating a dynamic structured exit, based on re crossing lines, loss of MACD momentum, etc.? I was trying to create a structured exit by adding sets with an Exit long or exit short action, but have been having problems.
                            Last edited by Daryl Haaland; 12-27-2017, 04:35 PM. Reason: typo

                            Comment


                              #29
                              Also you mentioned setting that ATR multiplier manually in the script editor. What about using the VolatilityStop indicator which I think I downloaded here (if not here, then certainly at Futures.io) which has the NumATR parameter as well as the period parameter (both based on the ATR) that you can make into user inputs to adjust where that trailing stop goes? Would that work just as well?

                              Comment


                                #30
                                Hello Daryl Haaland,

                                In the sample, in Set1 I set the value of a variable TSValue, equal to the ATR(14). There is no condition associated with this setting of the variable so it’s set on every bar. Then if you click next in the builder you will see this variable passed to the set stop loss, TSValue. The value the trailing stop would work at would be dynamic.

                                I wouldn’t be able to comment on what’s a more correct procedure, this sample was created to demonstrate how to pass a variable to a trailing stop.

                                I’m not familiar with the indicators you mention in your post so I wouldn’t be able to comment, but if they take a user input and produce a value that would be a valid stop price, I don’t see why it wouldn’t work.

                                Regarding your code which you can’t get to work correctly, If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.

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

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by usazencort, Today, 01:16 AM
                                0 responses
                                1 view
                                0 likes
                                Last Post usazencort  
                                Started by kaywai, 09-01-2023, 08:44 PM
                                5 responses
                                603 views
                                0 likes
                                Last Post NinjaTrader_Jason  
                                Started by xiinteractive, 04-09-2024, 08:08 AM
                                6 responses
                                22 views
                                0 likes
                                Last Post xiinteractive  
                                Started by Pattontje, Yesterday, 02:10 PM
                                2 responses
                                21 views
                                0 likes
                                Last Post Pattontje  
                                Started by flybuzz, 04-21-2024, 04:07 PM
                                17 responses
                                230 views
                                0 likes
                                Last Post TradingLoss  
                                Working...
                                X