Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetTrailStop

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

    SetTrailStop

    Hi,

    After I entered a position, I would like to set a trailing stop based on the EMA(p). To do that, I wrote in OnBarUpdate():

    SetTrailStop(CalculationMode.Price, EMA(p)[0])

    but it doesn't work (even if it appears in the TraceOrders).

    How can I obtain such behaviour?

    Thank you

    #2
    Hello Stefy,

    There may be issues here if you're trying to access the EMA value from the initialize method or if the EMA value is trading higher than the last traded price (for a long position)

    You can add a check for this when in a long position:
    if (Position.MarketPosition == MarketPosition.Long && EMA(14)[0] < Close[0])
    SetStopLoss(CalculationMode.Price, EMA(
    14)[0]);
    Last edited by NinjaTrader_RyanM1; 07-21-2010, 07:55 AM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      I used your code and I got the following message in the Log:

      Trailing Stops for the strategy cannot be calculated with CalculationMode.Price. Please use one of the other modes.

      If I want to set a trailing stop on a moving average, what other mode should I employ?

      Thanks

      Comment


        #4
        Thanks for letting us know Stefy. You can use SetStopLoss() method instead if you want the stop loss submitted at the EMA price. It will update the price continuously.

        Trailing stop will place a stop loss order in relation to the current traded price, so submitting as mode price doesn't make sense here.

        My first reply has been corrected.
        Ryan M.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        666 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        377 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        110 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        580 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X