Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issues with Setting Trailing Stop

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

    Issues with Setting Trailing Stop

    Working on a strategy that will allow the user to switch between a static stop loss and a trailing stop loss.

    In the state change I am using a setstoploss after checking for a bool.
    Code:
                    if(!EnableTrailingStop)
                    {
                        SetStopLoss(CalculationMode.Ticks, StopLoss);
                    }
    
    ​
    Later during the on position update I am checking for the opposite of the bool to set a trailing stop.
    Code:
                    if (EnableTrailingStop)
                    {
                        if (position.MarketPosition == MarketPosition.Long)
                        {
                            SetTrailStop(CalculationMode.Price, Low[1] - (StopLoss * TickSize));
                        }
                        else if (position.MarketPosition == MarketPosition.Short)
                        {
                            SetTrailStop(CalculationMode.Price, High[1] + (StopLoss * TickSize));
                        }
                    }​
    When I disable the "EnableTrailingStop" the SetStopLoss is triggering and working. But when I enable "EnableTrailingStop" the SetTrailStop is not working. When I use the CalculationMode of Ticks it works but then you can't base it off of the low or high of the previous candle. Can I throw a try catch around the settailstop and dig deeper to see why it is not getting set? Or is it something much more obvious?


    #2
    Hello cjtemple7273,

    Welcome to the NinjaTrader forums!

    From the help guide:
    "The SetTrailStop() method can NOT be used concurrently with the SetStopLoss() or SetParabolicStop() method for the same position, if any of methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use all three methods in the same strategy if they reference different signal names.​"


    You can instead control the trailing with custom logic.

    Below is a link to examples.


    Note, Set methods like SetStopLoss() / SetProfitTarget() / SetTrailStop() are intended to be called and set (like a trigger) before the entry order method is submitted.
    Chelsea B.NinjaTrader Customer Service

    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
    126 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