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

Trailing stop

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

    Trailing stop

    Hi,

    In the strategy builder how do I create a trailing stop which is activated when the low of the previous bar is broken?

    Thanks

    #2
    Hello blueboy,

    Thanks for your post.

    The SetTrailStop() method that can be used in the Stops and Targets section of the Strategy Builder will prep NinjaTrader so a trailing stop is started after the entry order comes back as filled.

    If you would like to create a trail stop that begins when you are already in position and the low of the previous bar is broken, you could use your own Exit methods in the Conditions and Actions section of the Strategy Builder. I have included a demonstration explaining how this could be set up.

    Demo - https://www.screencast.com/t/XgC4Iu29p

    More tips and a walk through on using the Strategy Builder can be found in the Strategy Builder 301 webinar.

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

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

    Comment


      #3
      Jim-
      Thanks for the video. I can't tell you how many hours I have spent trying to get the Strategy builder to work with just a trailing stop. There was no SetstopLoss in my efforts, so your video is very helpful.

      Also do you have a video for using the ATM in a Strategy with Price closing over or under an indicator. I have looked at the sampleATM strategy but I am so lost and exhausted trying to get it to work.

      Basically I want the ATM to manage the trailing stop that goes into effect after a five tick increase (it would be nice if I could also optimize this input), and then trails by 13 ticks or some other number that I can optimize as well as being able to manually move the stop on the chart or Dome, if I want to tighten up the stop.

      I know it can be done from reading the help guide, I just don't know the language and syntax well enough to put the pieces together.

      Thank you if you can help!!!!!

      Comment


        #4
        Hello TradingGuy,

        Thanks for the reply.

        I usually make demonstration videos to describe an expected behavior or to walk through a concept in the Strategy Builder. Creating a video that walks through and explains how a script works and the correct syntax that is used begins to escape the scope of services we can offer for support.

        As the ATM Strategy methods cannot be applied in the Strategy Builder, the best resource that we have available is the working example included with NinjaTrader.

        If you are looking for educational programming resources to learn the syntax, I may suggest to check out the C# programming education resources in the NinjaTrader 7 Help Guide.Another good tip is to use the Strategy Builder to create a strategy and click View Code with each code addition. More robust materials on C# programming can be found external to NinjaTrader.

        C# Programming concepts (NT7 Help Guide) - https://ninjatrader.com/support/help...g_concepts.htm

        Also to consider, we do have an EcoSystem of NinjaScript Consultants who can write this strategy or any other NinjaScript at your request. If this is something that interests you, please let us know and we can have someone reach out with more information.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim,

          I know this is an old thread, but your video was amazing. However, I am wondering. Can I use Low[1] for the ExitLongStopMarket instead of Close[0] and the StopDistance variable? For some reason I'm getting an error: Error on calling 'OnStateChange' method. You are accessing an index with a value that is invalid since it is out of range.

          Thanks!

          Comment


            #6
            Hello ypbtrainer,

            You can use Low[1] with an Exit method and this will reference the low of the previous bar. OnBarUpdate must first process 1 bar before the reference for Low[1] is made. See the Help Guide article below for more details.



            Your error is coming from OnStateChange, however. I suggest using debugging prints to identify the line of code that is throwing this error. Note that if you are referencing Low[1] or another price series in OnStateChange, it is likely that you are referencing a bar that has not yet been processed in OnBarUpdate. I have included information on using debugging prints below.

            Debugging Tips - https://ninjatrader.com/support/help...script_cod.htm

            Let me know if you have any questions.
            JimNinjaTrader Customer Service

            Comment


              #7
              Let me intervene. On the video the story tells us that the strategy is being activated with immediate position opening - no conditions provided for the position entry. Hence the variable can be applied to activate breakeven stop. However, if the strategy presumes any conditions for position entry, the variable becomes useless (unless you advise me differently). Every time you apply variable to become true (after # number of ticks, Pnl or whatever condition under the position price) and fire breakeven order for position exit - price may turn back and make the variable false again which removes the stop back to the initial distance.

              Question is how to play in this case..? When the breakeven condition is not true anymore, everything comes back home again...

              Comment


                #8
                Hello Aporshnev,

                On the video the story tells us that the strategy is being activated with immediate position opening - no conditions provided for the position entry.
                When a strategy is enabled, it processes historical data to determine trades that the strategy would have made on the data that is already on the PC/chart and to determine what position the strategy is in. (Strategy positions are separate from actual Account positions.) If the strategy calculates that is in a virtual position when it transitions to processing realtime data, the strategy's Start Behavior may wait until this position becomes flat before orders are allowed to submit with realtime data. (Wait Until Flat.) You can observe the Strategies tab of the Control Center if the strategy is in a virtual position waiting to become flat. The strategy will be orange/yellow when waiting to for the historical position to be closed, and will be green when allowed to trade live. ImmediatelySubmit would be used to have the strategy resume this position or to have the strategy immediately submit the working historical orders, assuming that the strategy position and account position are in sync. See below for more details.

                Strategy Position vs. Account Position - https://ninjatrader.com/support/help..._account_p.htm

                Start Behaviors - https://ninjatrader.com/support/help..._positions.htm

                However, if the strategy presumes any conditions for position entry, the variable becomes useless (unless you advise me differently). Every time you apply variable to become true (after # number of ticks, Pnl or whatever condition under the position price) and fire breakeven order for position exit - price may turn back and make the variable false again which removes the stop back to the initial distance.

                Question is how to play in this case..? When the breakeven condition is not true anymore, everything comes back home again...
                You would need to control this in your logic. For example, you could reset a bool once the strategy position goes back to flat.

                Making Market Position Comparisons - https://ninjatrader.com/support/help...ionComparisons

                I have attached an example Strategy Builder strategy that models setting up logic to move a stop to breakeven, and I have also linked our Help Guide example if you would like to call SetStopLoss in OnBarUpdate to move the stop to breakeven.

                Modifying Stop Loss and Profit Target orders - https://ninjatrader.com/support/help...of_stop_lo.htm

                We look forward to assisting.
                Attached Files
                JimNinjaTrader Customer Service

                Comment


                  #9
                  thank you for instructions. I imported the ZIP file in my NT8 as per directions, but... Could you guide me further? Should I see new strategy sample in Strategy Builder? I see this sample in the Script Editor, but not in the Builder... How should I use it? Sorry for silly questions...

                  Comment


                    #10
                    Hello Aporshnev,

                    You can double click the script in the NinjaScript Editor and the Strategy Builder will open to edit this strategy, or you can open it from a Strategy Builder as per my attached screenshot.

                    Please let me know if you have any questions.
                    Attached Files
                    JimNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Skifree, Today, 03:41 AM
                    1 response
                    2 views
                    0 likes
                    Last Post Skifree
                    by Skifree
                     
                    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
                    23 views
                    0 likes
                    Last Post xiinteractive  
                    Started by Pattontje, Yesterday, 02:10 PM
                    2 responses
                    23 views
                    0 likes
                    Last Post Pattontje  
                    Working...
                    X