Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop loss at execution price

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

    Stop loss at execution price

    Hi,
    I have a market entry (EnterShort(DefaultQuantity, "S") how can I set a Stop Loss at execution price?

    #2
    Hello dieci,

    Thanks for your post.

    Can you clarify if you are working in Ninjascript or the Strategy Builder?

    Are you looking to provide a "break even" type stop after so many ticks of profit?

    Comment


      #3
      Hi,
      I'm working with Ninjascript
      yes I want to put a stop loss x point below my entry if I'm long
      So I enter Long at market, executed at 1000 I want to put a stop loss at 1000 - x

      Comment


        #4
        Hello dieci,

        Thanks for your reply.

        You can use the SetStopLoss() method that will immediately deploy as soon as the entry order is filled. You can specify the number of ticks away from the entry price to place the stop.

        You can use this two different ways, one is statically meaning the same stop amount is applied to every entry (you can specify x amount of ticks, the method will add or subtract based on the entry direction). the other way is to use dynamically in case you want to change the values. Please see the help guide for the method and its usage: https://ninjatrader.com/support/help...etstoploss.htm

        Comment


          #5
          Hi,
          there's something I can't understand...here a snippet

          protected override void OnStateChange()
          {
          if (State == State.Configure)
          {
          if (sOp == "L")
          SetStopLoss("L", CalculationMode.Price, iSL, false);
          else if (sOp == "S")
          SetStopLoss("S", CalculationMode.Price, iSL, false);
          }
          }

          protected override void OnBarUpdate()
          {
          if (Close[0] >= High[1])
          {
          sOp = "L";
          entryOrderL = EnterLong(DefaultQuantity,"L");
          }
          else if (Close[0] <= Low[1])
          }
          sOp = "S";
          entryOrderS = EnterShort(DefaultQuantity,"S");
          {

          I can see the Long or Short entry but I can't see any Stop Loss among my Orders

          If I give the same entry name both Long and Short and write only one SetStopLoss referring to that name I can see again my entry, now I can see the Stop Loss among my Orders, state Accepted but it's never executed

          What's the issue??

          Last edited by dieci; 06-22-2020, 02:23 PM.

          Comment


            #6
            Hello dieci,

            Thanks for your reply.

            That is setting the stop loss to be 1 specific price level (L or S, likely chosen by the user) in state.Configure which is called when the user applies the strategy.

            I would not think that would be a good practice unless it is a one time use only as that same stop would be used on all entries.

            Comment


              #7
              So I should edit my code like this, right?

              iSL = 5;
              protected override void OnBarUpdate()
              {
              if (Close[0] >= High[1])
              {
              sOp = "L";
              entryOrderL = EnterLong(DefaultQuantity,"L");
              SetStopLoss("L", CalculationMode.Price, iSL, false);
              }
              else if (Close[0] <= Low[1])
              }
              sOp = "S";
              entryOrderS = EnterShort(DefaultQuantity,"S");
              SetStopLoss("S", CalculationMode.Price, iSL, false);
              {

              Comment


                #8
                Hello dieci ,

                Thanks for your reply.

                With reference to your post #3 & #5, I would suggest something like:

                Protected override void OnStateChange()
                {
                if (State == State.Configure)
                {
                if (sOp == "L")
                SetStopLoss("L", CalculationMode.Ticks, iSL, false); // provides a fixed stop-loss of iSL ticks below the Long entry price
                else if (sOp == "S")
                SetStopLoss("S", CalculationMode.Ticks, iSL, false); // provides a fixed stop-loss of iSL ticks above short entry price
                }
                }

                protected override void OnBarUpdate()
                {
                if (Close[0] >= High[1])
                {
                sOp = "L";
                entryOrderL = EnterLong(DefaultQuantity,"L");
                }
                else if (Close[0] <= Low[1])
                {
                sOp = "S";
                entryOrderS = EnterShort(DefaultQuantity,"S");
                }



                Comment


                  #9
                  Hi,
                  so you suggest to use CalculationMode.Tick instead of Price. Does CalculationMode.Price not work??

                  If I launch that strategy (CalculationMode.Price) I see the stop loss but it never runs, it remains Accepted and doesn't stop my entry

                  What's wrong?

                  Comment


                    #10
                    Hello dieci ,

                    Thanks for your reply.

                    To clarify: In the "Set" methods, CalculationMode is used to describe the value that is associated with the stop and should not be confused with the calculate setting of the strategy.

                    If you intend to use the same stop level for all your entries (a static stop) , it is better to set the stop in State.Configure. By using the stop with CalculateMode.Ticks you are setting a specific number of ticks from the entry that the stop will be placed.

                    The purpose of a stop loss is to exit your position when the price goes against your intended direction. It does not prevent entries if that is what you are asking.

                    Please take the time to review the "managed approach" which provides an overview and links to the methods: https://ninjatrader.com/support/help...d_approach.htm

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    30 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    124 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    64 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    41 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    46 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X