Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Issue with Trailing Stop

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

    Issue with Trailing Stop

    I have created a simple EMA crossover strategy and trying to use EMA 50 as a trail stop. however, it is not working. Can anyone please tell me what I am doing wrong.
    I am using Two EMA's (Fast EMA= 21, Slow EMA= 50) for crossover condition to place long and short order. My strategy is not using the trail stop code instead only reversing position per crossover condition or if met profit target. Below is my strategy code.
    I also tried to follow the trailstop thread given on this form but not sure what I am doing wrong.
    I appreciate if somebody can help me!!

    privateint fast = 21; // Default setting for Fast
    privateint slow = 50; // Default setting for Slow
    privateint profitTargetTicks = 50;
    #endregion

    protectedoverridevoid Initialize()
    {
    CalculateOnBarClose =
    true;
    }
    protectedoverridevoid OnBarUpdate()
    {
    if (CrossAbove(EMA(Fast), EMA(Slow), 1))
    {
    SetTrailStop(CalculationMode.Price, EMA(
    50)[0]);
    EnterLong(
    1, "Long1");
    SetProfitTarget(CalculationMode.Ticks, profitTargetTicks);
    }
    if (CrossBelow(EMA(Fast), EMA(Slow), 1))
    {
    SetTrailStop(CalculationMode.Price, EMA(
    50)[0]);
    EnterShort(
    1, "Short1");
    SetProfitTarget(CalculationMode.Ticks, profitTargetTicks);
    }

    #2
    Hi shanibaba,

    The trail stop works tick for tick. While you can set the price, the trailing action will always be tick for tick.

    If you want to have the price of the stop be the price of the ema, then you need to detect there is a position, and update the price by calling SetStopLoss on every new bar, or every new tick.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    657 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    373 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