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 pvincent, 06-23-2022, 12:53 PM
        14 responses
        238 views
        0 likes
        Last Post Nyman
        by Nyman
         
        Started by TraderG23, 12-08-2023, 07:56 AM
        9 responses
        383 views
        1 like
        Last Post Gavini
        by Gavini
         
        Started by oviejo, Today, 12:28 AM
        0 responses
        1 view
        0 likes
        Last Post oviejo
        by oviejo
         
        Started by pechtri, 06-22-2023, 02:31 AM
        10 responses
        125 views
        0 likes
        Last Post Leeroy_Jenkins  
        Started by judysamnt7, 03-13-2023, 09:11 AM
        4 responses
        59 views
        0 likes
        Last Post DynamicTest  
        Working...
        X