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 Rapine Heihei, 04-23-2024, 07:51 PM
    2 responses
    30 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    943 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    9 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    7 views
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    28 views
    0 likes
    Last Post wzgy0920  
    Working...
    X