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 lorem, Yesterday, 09:18 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by WHICKED, Today, 12:56 PM
        2 responses
        15 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Started by Felix Reichert, Today, 02:12 PM
        0 responses
        1 view
        0 likes
        Last Post Felix Reichert  
        Started by Tim-c, Today, 02:10 PM
        0 responses
        1 view
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by cre8able, Today, 01:16 PM
        2 responses
        9 views
        0 likes
        Last Post cre8able  
        Working...
        X