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 CarlTrading, 03-31-2026, 09:41 PM
                1 response
                81 views
                1 like
                Last Post NinjaTrader_ChelseaB  
                Started by CarlTrading, 04-01-2026, 02:41 AM
                0 responses
                42 views
                0 likes
                Last Post CarlTrading  
                Started by CaptainJack, 03-31-2026, 11:44 PM
                0 responses
                64 views
                2 likes
                Last Post CaptainJack  
                Started by CarlTrading, 03-30-2026, 11:51 AM
                0 responses
                66 views
                0 likes
                Last Post CarlTrading  
                Started by CarlTrading, 03-30-2026, 11:48 AM
                0 responses
                54 views
                0 likes
                Last Post CarlTrading  
                Working...
                X