Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StopLoss Query

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

    StopLoss Query

    Hi guys,

    I am running a long only strategy that has different conditions to trail my stop-loss. However I've noticed that in very rare market conditions the logic of my script would trail the stop-loss lower rather than higher. I don't want this to happen and therefore I was wondering if there is any condition I can use to check the level of my current stop-loss in order to condition my order to trail the stop-loss to this. Please advise if I haven't been clear in what I am looking for.

    #2
    Can you please clarify which stop loss method you're using? Are you using SetStopLoss/SetTrailStop?
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Matthew View Post
      Can you please clarify which stop loss method you're using? Are you using SetStopLoss/SetTrailStop?
      I am using IOrder, with mystoploss = ExitLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)

      Comment


        #4
        Hello,

        Thanks for the clarification. If you're using an IOrder object, you can simply call the StopPrice property of that object:

        Code:
        		protected override void OnOrderUpdate(IOrder order)
        		{
        			if (stopOrder != null)
        			{
        				Print(order.StopPrice);
        				
        			}
        		}
        This would allow you to confirm the price and if it is not what you expect you can add whichever logic you require to get the stop at the desired level.
        MatthewNinjaTrader Product Management

        Comment


          #5
          Originally posted by sburtt View Post
          Hi guys,

          I am running a long only strategy that has different conditions to trail my stop-loss. However I've noticed that in very rare market conditions the logic of my script would trail the stop-loss lower rather than higher. I don't want this to happen and therefore I was wondering if there is any condition I can use to check the level of my current stop-loss in order to condition my order to trail the stop-loss to this. Please advise if I haven't been clear in what I am looking for.
          You could use a Math.Max() for long, or Math.Min() for short to compare the current stop with the proposed new stop.
          Last edited by koganam; 08-05-2013, 09:54 AM. Reason: Changed imperative statement to optional.

          Comment


            #6
            Originally posted by NinjaTrader_Matthew View Post
            Hello,

            Thanks for the clarification. If you're using an IOrder object, you can simply call the StopPrice property of that object:

            Code:
            		protected override void OnOrderUpdate(IOrder order)
            		{
            			if (stopOrder != null)
            			{
            				Print(order.StopPrice);
            				
            			}
            		}
            This would allow you to confirm the price and if it is not what you expect you can add whichever logic you require to get the stop at the desired level.
            this isn't really what I meant, but thanks to your reply and koganam's I might have the solution. Assume I am long AAPL at 465 and my current stop is 460, lets say that OnBarUpdate my new stop condition is triggered and newStop = Low[0] - TickSize;

            Would something like this work:

            Code:
            if(stopOrder != null && order.StopPrice < (Low[0] - TickSize))
            {
               mystoploss = ExitLongStop(..) // adjust stop-loss to newStop
            }

            Comment


              #7
              Originally posted by sburtt View Post
              this isn't really what I meant, but thanks to your reply and koganam's I might have the solution. Assume I am long AAPL at 465 and my current stop is 460, lets say that OnBarUpdate my new stop condition is triggered and newStop = Low[0] - TickSize;

              Would something like this work:

              Code:
              if(stopOrder != null && order.StopPrice < (Low[0] - TickSize))
              {
                 mystoploss = ExitLongStop(..) // adjust stop-loss to newStop
              }
              That looks workable, if your trigger is the Low of the CurrentBar. But, will you instantly understand what you wrote, when you come to look at it 6 months from now, when your logic is no longer fresh in your mind?

              You may want to make your program logic follow the structure of your data.
              Code:
              double NewStop = ??? ; //calculate new stop value
              if (NewStop >CurrentStop)
              {
              CurrentStop = NewStop; //adjust stop price
              mystoploss = ExitLongStop(... CurrentStop,...);
              }

              Comment


                #8
                Thanks for the tip, clearly I am no programmer, but thanks to kind people like you that share knowledge I've been improving massively over the past months

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by sjsj2732, Yesterday, 04:31 AM
                0 responses
                32 views
                0 likes
                Last Post sjsj2732  
                Started by NullPointStrategies, 03-13-2026, 05:17 AM
                0 responses
                286 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                283 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                133 views
                1 like
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                91 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Working...
                X