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 kaywai, 07-13-2024, 09:05 PM
    3 responses
    25 views
    0 likes
    Last Post kaywai
    by kaywai
     
    Started by stafe, Today, 01:32 PM
    2 responses
    19 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by Jakub, Today, 11:06 AM
    2 responses
    24 views
    0 likes
    Last Post ashpang
    by ashpang
     
    Started by MatthewLesko, 05-21-2021, 09:37 PM
    4 responses
    167 views
    0 likes
    Last Post Mahmad1323  
    Started by samish18, Today, 03:02 PM
    3 responses
    18 views
    0 likes
    Last Post bltdavid  
    Working...
    X