Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

trailstop in script

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

    trailstop in script

    Hello,

    what I do not understand from the replies in the forum is how to modify settrailstop in a script-strategy so that the trailstop starts trailing only eg after a certain number of ticks in profit. Is this to do with a bool like

    if (Position.MarketPosition == MarketPosition.Flat)
    {trail = false;
    SetStopLoss("La", CalculationMode.Ticks, 5, false);
    SetTrailStop("Lb", CalculationMode.Ticks, 5, false);
    }
    else if (Position.MarketPosition == MarketPosition.Long) && Close[0] > Position.AvgPrice + (10*TickSize))
    trail = true;

    and then ?? How can I do that trailstop is trailing once 10 Ticks in profit.

    Thanks
    Tony

    #2
    Hello Tony,

    If SetTrailStop has never been used in the script with the fromEntrySignal, then it won't be active when the entry order is filled.
    If it has been called once in the script for that fromEntrySignal then it cannot be unset and will be active the moment the entry order fills.

    In other words, you would need to use a unique signalName for the entry order and a unique fromEntrySignal for the trail stop to make sure it doesn't start trailing for 10 ticks.

    Then your condition that submits the trail stop would need to check that the price has moved 10 ticks from the entry price of the order.

    Currently, the code you have sets the trail stop when the position is flat. This would mean that it is active immediately when an entry order fills.

    The orders entry price is the IOrder.AvgFillPrice.
    If the position is long (or if the entry order has filled), and the current price (Close[0]) is greater than or equal to the entry order's AvgFillPrice plus 10 times TickSize (plus 10 ticks), then set the trail stop.

    Below is a link to the help guide on IOrder.


    You could also use the Position.AvgPrice instead.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DannyP96, 05-18-2026, 02:38 PM
    1 response
    27 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 05-11-2026, 05:56 AM
    0 responses
    117 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 05-10-2026, 08:12 PM
    0 responses
    69 views
    0 likes
    Last Post CarlTrading  
    Started by Hwop38, 05-04-2026, 07:02 PM
    0 responses
    226 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    414 views
    0 likes
    Last Post CaptainJack  
    Working...
    X