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 in strategy not working.

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

    Trail stop in strategy not working.

    I have this attached picture configured in my strategy but the trail stop is not kicking in when i run the backtest. What am I missing?
    Attached Files

    #2
    Hello rocketstock,

    Thanks for your post.

    The SetTrailStop() method cannot use CalculationMode.Price or CalculationMode.Currency. From the help guide: "CalculationMode.Price and CalculationMode.Currency are irrelevant for trail stops. Attempting to use one of these modes will log a message and the stop order be ignored. " Reference: https://ninjatrader.com/support/help...ttrailstop.htm

    I will see if we can get the Strategy Builder to prevent selecting these modes, in a future release of NinjaTrader.

    So the stop is being ignored with the price "mode" you have selected.

    Please use CalculationMode.Ticks and specify the number of ticks to start from the entry price.



    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks I tried this but still doesnt work.
      Attached Files

      Comment


        #4
        Is the entry signal name correct? How should one name the string?

        Comment


          #5
          Hello rocketstock,

          Thanks for your reply.

          The use of an entry signal name is not needed unless you are trying to tie a specific entry to a specific stop (or profit target).

          The signal name would need to exactly match the Entry signal name.

          I would suggest removing the signal name from the Trailing stop as this then would apply the trailing stop to all entries.

          A 6 tick trailing stop is likely going to be hit quite often, I would suggest starting with a larger value until you see some functional results and then adjusting from there while developing your strategy.
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Hi Paul,

            I tried the above. I get the attached error even if I have a trial stop for 20 in 3 min. Tried various combos. Attached is 15 min trail stop 16
            Attached Files
            Last edited by rocketstock; 01-01-2022, 10:47 AM.

            Comment


              #7
              I changed this to 150 ticks and selected simulated so it started working. However I would still like to understand the error if you dont mind helping me. Was it because of too low ticks? Also sometimes trail stop does not work at near 150. Stops near 200 ticks. What could be the reason? Running on chart startegy with downloaded data for one month. 3 min chart.

              Comment


                #8
                Hello rocketstock,

                Thanks for your replies.

                What is the Calculate setting of the Strategy itself? (Calculate.OnBarClose, or Calculate.OnPriceChange, or Calculate.OnEachTick.)



                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  HI Paul. please see attached file
                  Attached Files

                  Comment


                    #10
                    is there a link that explains the impact of 3 choices you mentioned? thanks

                    any recommendations? i am building scripts for 3 min time frame

                    Comment


                      #11
                      Hello rocketstock,

                      Thanks for your reply.

                      The Strategy is running with Calculate.OnBarClose means that the trailing stop is only adjusted when the bar closes. From the help guide for the setTrailStop() is this specific note: Trail stop orders are modified based on the strategies 'Calculate' settings. In the case of 'Calculate' on bar close, when the bar closes the trail stop order modification will occur using the lowest/highest price of the bar as the reference price to apply the trail offset. Subsequently, if the open price of the next bar is significantly higher or lower than this price then there is a possibility that the calculated trail stop price is now an invalid stop price. This is a risk with modifying any stop order closer to the current market price since any modification above/below the current price would be rejected.
                      Reference: https://ninjatrader.com/support/help...ttrailstop.htm

                      To use the trailing stop, on live or playback with market replay data, the strategy needs to run with Calculate.OnPriceChange or Calculate.OnEachTick.

                      Helpguide page on Calculate: https://ninjatrader.com/support/help...?calculate.htm
                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12
                        Thank you Paul. I totally missed this. Great to know.

                        1. Why does NT have bar close as default. Was there a reason?
                        2. Which one is most accurate and sensitive without breaking other things?
                        3. I am thinking about changing it to On Each Tick just wondering what that will do to my scripts and indicators?

                        Thanks,

                        Comment


                          #13
                          Hello rocketstock,

                          Thanks for your reply.

                          1. Why does NT have bar close as default. Was there a reason? Yes, this mode consumes fewer resources when calculating only once per bar compared to the other modes which can literally happen 1000's of times in a bar (depending on bar size and type). Strategies using this mode are making trade entry/exit decisions based on a bar that has closed (and does not change) and not on bars that are forming (changing), so the advantage is that the trade decision is based on data that does not change, versus the other modes. The disadvantage is that the trade entry/exit must wait for the next bar since the decision bar just closed.

                          2. Which one is most accurate and sensitive without breaking other things? There are too many factors to consider an answer for that. I would just say that with Calculate.OnBarClose, your historical trades, and live trades will be done in the same way using bars that have closed and conditions that would not change.

                          3. I am thinking about changing it to On Each Tick just wondering what that will do to my scripts and indicators? You will likely need additional logic to prevent multiple entries..

                          Note: I just realized you have posted in the NinjaTrader7 Strategy development forum. I will move this topic into the NinjaTrader8 strategy Development forums. When creating a new topic, please make sure you are in the appropriate forum, thanks for your understanding.
                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank you very much. Seems like a complicated issue. I will need to study on. Sorry about NT 7. Will do that in future. I think I will stick to bar on close for now until I get better handle on ontick.

                            Comment


                              #15
                              iv noticed that
                              else if (State == State.Configure)
                              {
                              SetTrailStop(CalculationMode.Percent, .02);


                              percentage works, but two things happen that trouble me

                              1 it places a stop loss regardless of open position, based on previous strategy history even though I may have closed my position manually
                              2. when triggered this becomes a market order and not a market limit order ( this opens up a can of worms where even a small 5 contracts gets filled at 5 different prices)

                              any one know how to avoid or improve 1 and 2 ?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by leonardomocci, Today, 08:28 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Clayton  
                              Started by wuannetraam, Today, 08:20 AM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by HappyTrader76, 02-07-2023, 08:46 AM
                              6 responses
                              333 views
                              0 likes
                              Last Post SnailHorn  
                              Started by geotrades1, Today, 07:54 AM
                              6 responses
                              16 views
                              0 likes
                              Last Post geotrades1  
                              Started by Aviram Y, Today, 06:03 AM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X