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 argusthome, 03-08-2026, 10:06 AM
    0 responses
    61 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    39 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    21 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    23 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    51 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X