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

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:



    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:


      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:


            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:



            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 martin70, 03-24-2023, 04:58 AM
                      14 responses
                      105 views
                      0 likes
                      Last Post martin70  
                      Started by TraderBCL, Today, 04:38 AM
                      0 responses
                      2 views
                      0 likes
                      Last Post TraderBCL  
                      Started by Radano, 06-10-2021, 01:40 AM
                      19 responses
                      606 views
                      0 likes
                      Last Post Radano
                      by Radano
                       
                      Started by KenneGaray, Today, 03:48 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post KenneGaray  
                      Started by thanajo, 05-04-2021, 02:11 AM
                      4 responses
                      470 views
                      0 likes
                      Last Post tradingnasdaqprueba  
                      Working...
                      X