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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        64 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        35 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        51 views
        0 likes
        Last Post CarlTrading  
        Working...
        X