Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Where should the SetTrialStop codes go

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

    Where should the SetTrialStop codes go

    protected override void OnBarUpdate() {
    if (Position.MarketPosition == MarketPosition.Long){
    SetTrailStop("",CalculationMode.Percent,2*ATR(20)[0]/Position.AvgPrice,true);
    }}

    Is it correct to code as the above way, if what I want to achieve is set a trail stop at the level I picked and then let the system to handle the trail automatically afterward?

    In fact, I'm not so sure where should SetTrialStop be put, OnBarUpdate or OnOrderUpdate?

    Meanwhile, how to know the most updated trail stop level (once it start trialing) ?

    #2
    kenlo,

    That looks fine. Note that you can't use "SetStopLoss" and "SetTrailStop" together as "SetStopLoss" will override any trailing stop yous et.

    Basically whenever you call "SetTrailStop" it sets your trailing stop to be this value from that point forward. From there NinjaTrader takes over and always uses the value you set as the trailing stop. The stop loss will be submitted as soon as your entrance order is, or the stop loss will be modified if you are already in an order.

    To get the value of the trailing stop likely you will want to use OnOrderUpdate() to grab the trailing stop order object and monitor it.

    From our help guide :

    • It is suggested to call this method from within the strategy Initialize() method if your trail stop price/offset is static
    • You may call this method from within the strategy OnBarUpdate() method should you wish to dynamically change the trail stop price while in an open position
    • Should you call this method to dynamically change the trail stop price in the strategy OnBarUpdate() method, you should always reset the trail stop price/offset value when your strategy is flat otherwise, the last price/offset value set will be used to generate your trail stop order on your next open position
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      thanks and I have one more question...

      Basically whenever you call "SetTrailStop" it sets your trailing stop to be this value from that point forward
      Since I put SetTrailStop inside the OnBarUpdate, I think it will be called more than one time, so what you mean is any subsequent calls will be just ignored until the next new position?

      Comment


        #4
        kenlo,

        If you call the SetTrailingStop() again it will update the trailing stop even if it is active.
        Adam P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        649 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        576 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X