• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trail Stop Three Bar H/L

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

    Trail Stop Three Bar H/L

    Hello,

    I would like to create an auto trail stop.
    When Long :Trail Stop - lowest low of 3 bars - 1 tick
    When Short: Trail Stop - Highest high of 3 bars + 1 tick

    #2
    Hello rcmcd,

    Thanks for the post.

    To set a trailing stop in a strategy use SetTrailStop.

    https://ninjatrader.com/support/help...ttrailstop.htm - SetTrailStop()

    To get the value for the trailing stop, there is this example that shows how to get the highest high or lowest low:

    https://ninjatrader.com/support/foru...ead.php?t=8600

    And finally, to add ticks to a value, you can use TickSize to get the correct tick size of the primary series.

    https://ninjatrader.com/support/help.../?ticksize.htm - TickSize property

    Please let me know if I can assist further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChrisL View Post

      To get the value for the trailing stop, there is this example that shows how to get the highest high or lowest low:

      https://ninjatrader.com/support/foru...ead.php?t=8600
      Please can you extend the example so that it can calculate highest high or lowest low not only for a specified time range, but also for a time interval just passed, for ex for the last half hour, or for a specified nr of the last bars just passed, for ex. for the last 20 bars?
      thx
      Last edited by guidoisot; 09-09-2018, 11:24 AM.

      Comment


        #4
        Hello guidoisot,

        Thanks for the post.

        I can not modify the sample, but one way that you could do this would be to add a time series as a secondary series with AddDataSeries.

        You can then use the MAX function, and pass in that data series to be evaluated. So the lookback for MAX would be the number of bars. If you wanted to get the 5-minute max, pass in the secondary 1-minute series and specify a 5 bar lookback.

        Please let me know if you have any questions.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Hello Chris, I have tried to look at the indicated AddDataseries link at the help on line, but I do not see an explanation or guidance of how and where to add a “time” data series. I am sure for a ninjascript programmer it must be pretty easy to do what needed for the modification. However for me, just pretending to be trying and testing trading ideas and not to become a master programmer, it is practically unachievable. Anyway, thank you for taking the time to reply.
          GT

          Comment


            #6
            Hello guidoisot,

            Thanks for the reply.

            I have attached a script that adds a 1 minute series in State.Configure (part of the NinjaScript lifecycle) and used the MAX function in the way we discussed.

            See here for instructions on importing the script:
            https://ninjatrader.com/support/help...us/?import.htm

            Attach it to one of your charts, then observe the output window via New>NinjaScript output.

            The post below from our colleague Chelsea lists many educational resources for NinjaScript:

            https://ninjatrader.com/support/foru...609#post503609

            Please let me know if I can assist further.
            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              You could use a Donchian Channel for this. It does what Chris has described, but easier to plot and visualise on a chart.

              Comment


                #8
                Hello @NinjaTrader_ChrisL

                With regard to the two scripts attached herebelow, breakeven with the strategy builder and trailing stop with the strategy builder, I have a couple of questions:

                why when I add on the “condition tab2” of both sample strategies’ the same “entryLong” conditions (ie group: “threeLinebreak Long Reversal pattern”) the breakeven sample strategy triggers some trades, whereas the trailing stop sample strategy does not trigger any trade.

                When applying strategy “BreakEvenBuilderExampleLINEBREAK30sec” why once a position is filled there are a lot “order cancel” orders in quick sequence ? It appears that the entry orders are correctly exectuded one bar after the signal and not two bars after. Is this interpretation correct ?

                Is it possible to merge into one strategy the two sample strategies (breakeven + trailing stop) so that after entering two trades each position can be set to follow either the BE rules, or just the trailing rules, or either one of the two, or both?

                Thank you.
                Attached Files

                Comment


                  #9
                  Hello guidoisot,

                  Thanks for the post.

                  I'm not sure if I follow your question, please detail your question further so I can assist with that. You can not automatically merge two scripts together. You would need to place the correct logic from one script into the correct location in the other script.

                  I look forward to assisting further.
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    I apologize, I see that I am involuntarily doing some confusion ...



                    Originally posted by guidoisot View Post
                    why when I add on the “condition tab2” of both sample strategies’ the same “entryLong” conditions (ie group: “threeLinebreak Long Reversal pattern”) the breakeven sample strategy triggers some trades, whereas the trailing stop sample strategy does not trigger any trade.
                    here the issue is that if I insert the same long entry conditions in both samples, for the same instrument on the same chart, the breakeven sample works ok, ie it executes some long trades, whereas the trailing stop sample does not trigger any long entry. So I was wondering what kind of error was the cause of this.



                    Originally posted by guidoisot View Post
                    When applying strategy “BreakEvenBuilderExampleLINEBREAK30sec” why once a position is filled there are a lot “order cancel” orders in quick sequence ? It appears that the entry orders are correctly executed one bar after the signal and not two bars after. Is this interpretation correct ?
                    please do not consider this as I have been changing several times the conditions on the strategy builder I have been working on this week. However here the issue was that at certain price levels there were many orders in fast sequence. I remember that some time ago one of your colleagues, Paul perhaps?, posted an example on how to solve this using a bool in the strategy builder, but I cannot find it out in the forum. If you could help me in finding out again this strategy builder sample, I would be very grateful.


                    Originally posted by guidoisot View Post
                    Is it possible to merge into one strategy the two sample strategies (breakeven + trailing stop) so that after entering two trades each position can be set to follow either the BE rules, or just the trailing rules, or either one of the two, or both?
                    here I was just wondering whether by creating a single strategy builder sample, encompassing both the BE sample logic and the trailing stop sample logic, one could end up with a strategy builder sample that basically acts as an ATM strategy.

                    Comment


                      #11
                      Hello guidoisot,

                      Thanks for the reply.

                      First things first, you can certainly use ATM strategies in your automated NinjaScript strategies but this will require you to unlock your code and follow the SampleATMStrategy sample.

                      It sounds like your questions are mainly on design and logic flow. If that is the case I can not directly assist with that but this post will remain open for other members of the community.

                      Please let me know if you have any questions.
                      Chris L.NinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Longhornmark, Today, 08:25 AM
                      3 responses
                      10 views
                      0 likes
                      Last Post bltdavid  
                      Started by mohdhm, Today, 04:09 PM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_ShawnB  
                      Started by BGWTEX, Today, 03:30 PM
                      1 response
                      4 views
                      0 likes
                      Last Post NinjaTrader_Jesse  
                      Started by marekflys, Today, 03:07 PM
                      0 responses
                      10 views
                      0 likes
                      Last Post marekflys  
                      Started by GregoryBaskin, Today, 02:51 PM
                      1 response
                      5 views
                      0 likes
                      Last Post NinjaTrader_Tyler  
                      Working...
                      X