Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss() not triggering as expected

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

    SetStopLoss() not triggering as expected

    Click image for larger version

Name:	image.png
Views:	222
Size:	24.5 KB
ID:	1281969Click image for larger version

Name:	image.png
Views:	275
Size:	20.5 KB
ID:	1281968

    Above is a segment of code in the onbarupdate function as you can see from the execution I should be stopped out according to the price action. However, Even when I set this to 1 tick. It never stops me out? What gives?​​
    Attached Files

    #2
    Hello RISKYBUSINEZZ,

    Thank you for your post.

    Are you seeing any errors in the log tab of the Control Center?


    Set methods cannot be unset and will continue to hold their values for new entry orders.

    This means it is important to reset Set methods using a number of Ticks, Percent, or Currency before placing a new entry (or using a unique signalName for each new entry). (Setting to a specific price may be an invalid price when the entry order fills, especially for entry limit and stop orders)

    Please note your fromEntrySignal "Stop Out" does not match the signalName of the entry "DON Long 1".


    Before calling a new entry call the Set methods first, one line above the entry method.

    Code:
    if (Position.MarketPosition == MarketPosition.Flat)
    
    {
    
    // reset the stop loss before entry, so this is no longer set to a specific price which may be invalid when the entry fills
    
    SetStopLoss(CalculationMode.Ticks, 20)
    
    EnterLong();
    
    }
    
    
    
    // after the entry fills, the stop loss can be moved to any desired valid price
    
    if (Position.MarketPosition == Market Position.Long && Close[0] > Position.AveragePrice + 10 * TickSize)
    
    {
    
    // after 10 ticks of profit, set the stop loss to the maximum valid price
    
    SetStopLoss(CalculationMode.Price, GetCurrentBid() - TickSize);
    
    }



    The help guide notes:


    “Notes:

    Since they are submitted upon receiving an execution, the Set method should be called prior to submitting the associated entry order to ensure an initial level is set.“


    “Tips:

    You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the stop loss price while in an open position

    Should you call this method to dynamically change the stop loss price in the strategy OnBarUpdate() method, you should always reset the stop loss price / offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your stop loss order on your next open position”

    NinjaScript > Language Reference > Strategy > Order Methods > Managed Approach > SetStopLoss()

    Comment


      #3
      Just want to reply back that this has been solved, the issue was that the stop loss was looking for an order name to set the stop loss from. Instead of the last order like it was supposed to.

      Comment


        #4
        Hi,
        I have the same issue with SetStopLoss not triggered as expected. Is it because the entry order was placed manually from Chart Trader ?

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        50 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        127 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        69 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 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