Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue when trailing stop loss

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

    Issue when trailing stop loss

    Hi Support,
    I just realized that my trailing stop script that works fine in back testing is not working as I expect it too in live trading. What I expect the script to do is simply check different conditions and trail the current stop loss in order to lock in further profits on each primary bar update. The problem I am experiencing is that the current stop loss is cancelled on bar update but the new stop loss is calculated (as I see it in the Print field) but is not entered, therefore I end up with a position but with no stop loss. Are you able to spot anything erroneous in my script? I was thinking it could be the part highlighted in bold, but if I eliminate that I end up having 2 stops in the market, the old one and the new one..

    Code:
    if(BarsInProgress == 0)	// primary time frame (e.i. 60 min)
    {
    	#region Long - Stop Loss Management
    		{
    		if(Position.MarketPosition == MarketPosition.Long && stopOrderLong != null)
    			{      
                               if(conditionA == true)
                                     {
                                          stopPriceA = Low[0];
                                     }
                               if(conditionB == true)
                                    {
                                           stopPriceB = Low[1];
                                   }
                              }
    double newStop = Math.Max(stopPriceA,stopPriceB); 	// calculate new stop loss
    if(newStop > stopOrderLong.StopPrice) // check if new stop loss is higher than current stop loss
    {
    	if(newStop < Close[0])
    {
    	[B]CancelOrder(stopOrderLong);[/B]
    	stopOrderLong = ExitLongStop(1,true,stopOrderLong.Quantity, newStop,"","");
    }
    else if(newStop >= Close[0])
    {
    	CancelOrder(stopOrderLong);
    	ExitLong(1,stopOrderLong.Quantity,"","");
    }
    }
    Last edited by yades; 08-15-2013, 04:10 PM.

    #2
    yades, the cancellation seen must come from your explicit CancelOrder call since liveUntilCancelled is set to true, meaning the orders would not expire and persist until you cancel them or the session end handling for DAY orders would take over. The stop should only need to be cancelled once the position is closed (for example by your target or market exit) - if you just want to update the stop then a call to the same stop order / signal name would provide the update you seek, also eliminating the issue of having two stop orders in the market to deal with, as you would always update the old one until either stopped out or closed by other means.

    Comment


      #3
      Berthand, yes I just want to update my stop or alternatively exit at market.So if I understand correctly what you are saying is:
      1) I need to remove CancelOrder(stopOrderLong); from the script below;
      (2) I must be sure that the both my initial stop and my new stop loss have the same signal name ( currently that is not the case, as I am calling my initial stop "stoploss" and my new stop "newstop").

      Please advise if I understood correctly what you are saying to me.

      Moreover, in case I exit at market (as described in the last part of my script, will NT automatically cancel my stop loss?


      Originally posted by NinjaTrader_Bertrand View Post
      yades, the cancellation seen must come from your explicit CancelOrder call since liveUntilCancelled is set to true, meaning the orders would not expire and persist until you cancel them or the session end handling for DAY orders would take over. The stop should only need to be cancelled once the position is closed (for example by your target or market exit) - if you just want to update the stop then a call to the same stop order / signal name would provide the update you seek, also eliminating the issue of having two stop orders in the market to deal with, as you would always update the old one until either stopped out or closed by other means.

      Comment


        #4
        You are correct in understanding, just resubmit the order with the same signal name and your new price, this will just be updating the currently residing one. Correct if the managed position is closed, the stop would be cancelled in NT's managed mode.

        Comment


          #5
          Bertrand, could you please further elaborate on this point, I am not sure I understand what you mean here.

          Originally posted by NinjaTrader_Bertrand View Post
          yades, the cancellation seen must come from your explicit CancelOrder call since liveUntilCancelled is set to true, meaning the orders would not expire and persist until you cancel them or the session end handling for DAY orders would take over. T

          Comment


            #6
            Per default in NT's managed approach any order will expire on the next OnBarUpdate(), meaning you would need to resubmit, or use the more advanced overload that would let you explicitly set the liveUntilCancelled parameter to 'true' to override this handling. Then the order will not be cancelled unless you CancelOrder() it, or the end of session handling would if orders were placed with a TimeInForce of DAY.

            Comment


              #7
              ok this is all v clear, thx
              Originally posted by NinjaTrader_Bertrand View Post
              Per default in NT's managed approach any order will expire on the next OnBarUpdate(), meaning you would need to resubmit, or use the more advanced overload that would let you explicitly set the liveUntilCancelled parameter to 'true' to override this handling. Then the order will not be cancelled unless you CancelOrder() it, or the end of session handling would if orders were placed with a TimeInForce of DAY.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              656 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              371 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              579 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X