Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trailing stops

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

    Trailing stops

    I have some code where I enter long 3 contracts with 3 seperate profit targets but the same stop loss.

    If the first profit target is hit I would like to move the stop for the remaining two positions. I realise I can use the following syntax:

    SetStopLoss("LongEntry2",CalculationMode.Price,stoplossnew,true);
    SetStopLoss("LongEntry3",CalculationMode.Price,stoplossnew,true);

    assuming LongEntry1 is closed due to profit being hit. But how would I catch the event that the target is hit for LongEntry1?

    I can use code such as
    profit = GetCurrentBid() - LongOrder.AvgFillPrice;

    to calculate the current profit on an open position but wish to catch the event of a position hitting its target. Is this done using the
    OnPositionUpdate event?


    #2
    mballagan,

    You can check change in positions, then if you had your own variables tracking where the profit value and where the stop values are, you could then check it against price the moment a position change occurred and then you will be able to deduce which order was filled.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      profit target hit

      Is a better way of doing it to use the OnExecution event? -

      protectedoverridevoid OnExecution(IExecution execution)
      {

      if (LongOrder1 != null && LongOrder1.Token == execution.Order.Token)
      {
      if (execution.Order.OrderState == OrderState.Filled ))
      {
      //modify stop loss here for LongEntry2 & LongEntry3 using SetStopLoss

      }

      }


      Comment


        #4
        If you want to use advanced order methods, don't use Set() methods and just handle everything with IOrders.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        109 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        57 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        37 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        39 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        76 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X