Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trouble getting SetTrailStop() to work ...

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

    Trouble getting SetTrailStop() to work ...

    I have a percent trailing stop that is not working, so I added some print code to make sure the statement is being executed:

    ...
    if (Position.GetProfitLoss(Highs[1][0], PerformanceUnit.Points) > pointsTrailLong)
    {
    Print("Setting trail stop long");
    Print(stopTrailPercentLong);
    SetTrailStop(CalculationMode.Percent, stopTrailPercentLong);
    }

    And it was being executed. The Output window shows:

    Setting trail stop long
    1

    But the 1 should be 0.10. Its defined as a double not an int. Is it that the Print statement is rounding 0.10 to 1 OR is there a problem with the 'set' statement and 'Max' function?

    Brooks

    private double stopTrailPercentLong = 0.10;

    public double StopTrailPercentLong
    {
    get { return stopTrailPercentLong; }
    set { stopTrailPercentLong = Math.Max(1, value); }
    }

    #2
    Brooks, for one percent it would be 0.01 - please change the min value in your MAX statement for the public property user input to a lower # to allow this.

    Comment


      #3
      Ok, thanks. I want 10 percent, so it would be 0.10

      Can you explain the purpose and logic behind the Math.Max function in the set statement?

      Comment


        #4
        I changed the statement to:

        set { stopTrailPercentLong = Math.Max(0.10, value); }

        The trailing stop is still not working and the Output box still shows:

        Setting trail stop long
        1

        So why does Print show 1 when it is 0.10?

        Comment


          #5
          Hi brooksrimes,

          It's used to specify the lowest value accepted. Math.Max returns the higher of two numbers, so the 1 becomes your floor for this input.

          It's useful when you don't want to allow negative numbers or decimal values < 1.

          You may currently want to specify your input as .1, but if you'd like to use values lower than that would have to set the Math.Max statement to something lower
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Brooksrimes - make sure you've recompiled and reloaded any instances of the strategy after making these changes.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I did recompile and I disabled and re-enabled the strategy in the chart but that didn't seem to be enough. I had to remove the strategy and re-add it and now it is showing the 0.10 in the Output window. Thx.

              Originally posted by NinjaTrader_RyanM View Post
              Brooksrimes - make sure you've recompiled and reloaded any instances of the strategy after making these changes.

              Comment


                #8
                Correct - disabling and enabling will not use the latest code changes. Removing and adding is one way. You can also right click > reload NinjaScript from chart.
                Ryan M.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

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