Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem re-setting StopLoss

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

    #16
    Thank you for your reply. Can you explain a bit about your statement "make sure that you reset your stop loss values when you are flat"...I saw this in the help manual as well...I simply do not understand what that means exactly.

    I would have thought that each call of "SetStopLoss" places it where it is desired...the manual suggests that a previous call is used as a beginning point...or something to that effect. Thanks again.

    Comment


      #17
      Please see the reference sample below. It explains it.

      RayNinjaTrader Customer Service

      Comment


        #18
        Thanks again. I took this code from that strategy link you provided:

        //in "Variables"
        private int stoplossticks = 20;

        //In "OnBarUpdate"
        // Resets the stop loss to the original value when all positions are closed
        if (Position.MarketPosition == MarketPosition.Flat)
        {
        SetStopLoss(CalculationMode.Ticks, stoplossticks);
        }


        I guess that explains what is needed to do, but not why. I'm still not following why this procedure is necessary--seems like extra code...

        Comment


          #19
          It resets the stop loss value otherwise the stop is submitted for a new position at the last known price.
          RayNinjaTrader Customer Service

          Comment


            #20
            Thank you. I've done the following modification to my previous code at the end (replacing the Position.Quantity):

            if(Position.MarketPosition == MarketPosition.Flat)
            {
            if(subsequentCounter == 1)
            {
            subsequentCounter = 0; inflator = 1;
            SetStopLoss(CalculationMode.Ticks, ExitPlace);
            }
            } //reset counter if it needs to be after trade triggers

            I saw no difference. So I replaced:

            "if(Position.MarketPostion == MarketPosition.Flat)"
            with "if(Position.Quantity == 0)"

            I saw no difference. So I replaced:

            "SetStopLoss(CalculationMode.Ticks, ExitPlace);"
            with "SetStopLoss(CalculationMode.Price, ExitPlace);"

            Still no luck, I never expected to have so many problems with something as (what I thought was) simple as moving a StopLoss...I do not believe the other areas of code have a problem...of course I could be wrong.

            Am I supposed to set a new variable in the "Variables" section to be equal to "0" and then use that as the "resetter" (replacing "ExitPlace")?

            Comment


              #21
              Just a follow-up on my last post:

              "Am I supposed to set a new variable in the "Variables" section to be equal to "0" and then use that as the "resetter" (replacing "ExitPlace")?"

              Tried it...same result as before...no difference whatsoever...

              Comment


                #22
                It seems to me that the problems I'm experiencing are related to the resetting of the StopLoss. In debugging my code I've concluded that:

                1. I've stripped the strategy down to only 1 possible trade condition
                2. The calculations seem correct
                3. The condition for entry seems to be working properly
                4. The procedure to prevent "re-submission" of orders on each bar seems correct
                5. The entry point seems correct
                6. The INITIAL StopLoss seems correct
                7. The FIRST reset of the StopLoss on the chart seems correct
                8. Subsequent StopLoss "resets" are problematic...

                As my last couple of posts suggest I'm having a difficult time determining what is wrong with that reset logic...anybody got any ideas? Any advice much appreciated.

                Comment


                  #23
                  Burga1. It is hard to follow your code segments. Just throw up a simple as possible complete version of your code and hopefully someone will be able to spot something more easily.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #24
                    Thank you. I think I've got it now...

                    Comment


                      #25
                      Excellent!
                      RayNinjaTrader Customer Service

                      Comment


                        #26
                        Sharing the Strategy

                        Dear Burga1,

                        please can you share the full strategy. I want to write my own one but doesnt really now to start with and your Stop Loss strategy looks similar to my ones.

                        Thanks Lars

                        Comment


                          #27
                          Lars,

                          I'm not sure what you're asking...are you looking for a "Trailing Stop" only or something else. Please clarify.

                          Regards

                          Comment


                            #28
                            Dear Burgy1,

                            What I am really looking is for a fully Strategy example with entry and exit rules, drawings and outputs to review the compiling etc.

                            Thanks

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            656 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            371 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            109 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            574 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            579 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X