Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Breakeven Stop

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

    Breakeven Stop

    Is there a way in Ninjascript to place a breakeven stop, once a certain level of ticks above entry price has been reached?
    Seems it would be simple, but I'm a newbie to coding.

    #2
    Absolutely! The following link will take you to a reference sample that will demonstrate this concept.

    RayNinjaTrader Customer Service

    Comment


      #3
      Breakeven Stop

      Thanks Ray, looks good to me.

      Comment


        #4
        Breakeven Stop

        I am getting an error message saying "the name "stoplossticks" does not exist in the current context".

        Comment


          #5
          This means that the variable "stoplossticks" does not exist. Could be a spelling typo or something like that if you believe you have declared this variable.
          RayNinjaTrader Customer Service

          Comment


            #6
            Breakeven Stop

            I copied it from the sample strategy.
            Here's my code:
            protectedoverridevoid Initialize()
            {
            CalculateOnBarClose =
            false;
            // SetProfitTarget(CalculationMode.Ticks, 20);
            SetStopLoss(CalculationMode.Ticks, stoplossticks);


            // ExitOnClose = true;

            }

            Comment


              #7
              If you go back to look at the SamplePriceModification reference sample please take note of the "Variables" and "Properties" sections of the code. In the "Variables" section you will see where stoplossticks was defined. Here is the code snippet from there.
              Code:
              private int        stoplossticks        = 20;
              In the "Properties" section of the code you will see how I made that a user definable input with this code segment.
              Code:
              /// <summary>
              /// </summary>
              [Description("Numbers of ticks away from entry price for the Stop Loss order")]
              [Category("Parameters")]
              public int StopLossTicks
              {
                  get { return stoplossticks; }
                  set { stoplossticks = Math.Max(0, value); }
              }
              Because I defined stoplossticks in the "Variables" section I can use that variable in the Initialize() method. You will need to do the same if you wish to use a variable. Alternatively, you can just input an integer in place of stoplossticks so for example:
              Code:
              [FONT=Courier New][SIZE=2]SetStopLoss(CalculationMode.Ticks, 4);[/SIZE][/FONT]
              http://www.ninjatrader-support.com/H...tStopLoss.html

              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Breakeven Stop

                I think I have it now.
                Thanks

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                633 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                364 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                105 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                567 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                568 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X