Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with SetStopLoss

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

    Issue with SetStopLoss

    Hello,
    I've an automated strategy and as a part of it if the price moves 6 ticks in the favor of trade, initial stoploss is brought to breakeven.

    But if you were to look at the chart below, for the two short trades via the strategy today, it did not bring the stoploss back to breakeven and instead exited the position at the initial stoploss of 8 ticks.

    Here is the code I am using and I have it placed under OnBarUpdate. Can someone please help to understand what could be wrong here?
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss(CalculationMode.Ticks, stoplossticks);
    }
    else if (Position.MarketPosition == MarketPosition.Long)
    {
    // Once the price is greater than entry price +6 ticks, set stop loss to breakeven
    if (Close[0] > Position.AvgPrice + 6 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }
    }
    else if (Position.MarketPosition == MarketPosition.Short)
    {
    // Once the price is greater than entry price - 6 ticks, set stop loss to breakeven
    if (Close[0] < Position.AvgPrice - 6 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AvgPrice);
    }
    }
    Attached Files

    #2
    Hello pandyav,

    Looking at your screenshot the reason why the stop loss was probably not moved was because the Close price was not less than 6 ticks, but it was equal 6 ticks below your entry price. The way that it is programmed now it will only move the Stop Loss if the close was more than 7 ticks or greater. So in the picture the Close would have to be 1788 or lower before your Stop Loss is triggered. If you want it to be moved if the close was 6 ticks or greater you may want to use the "<=" or ">=" signs so that if they are equal it will move it as well.

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    118 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    166 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    85 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    130 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    88 views
    0 likes
    Last Post PaulMohn  
    Working...
    X