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 trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    22 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Started by guillembm, Yesterday, 11:25 AM
    2 responses
    9 views
    0 likes
    Last Post guillembm  
    Started by junkone, 04-21-2024, 07:17 AM
    9 responses
    68 views
    0 likes
    Last Post jeronymite  
    Started by mgco4you, Yesterday, 09:46 PM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X