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

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.
    BertrandNinjaTrader Customer Service

    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 bortz, 11-06-2023, 08:04 AM
                47 responses
                1,607 views
                0 likes
                Last Post aligator  
                Started by jaybedreamin, Today, 05:56 PM
                0 responses
                9 views
                0 likes
                Last Post jaybedreamin  
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                19 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                6 views
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                15 views
                0 likes
                Last Post Javierw.ok  
                Working...
                X