Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adjusting stop loss order...

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

    Adjusting stop loss order...

    In my strategy, when I enter a trade I get the results from OnOrderUpdate() and I set my initial stop loss order there. Like so:


    TrailingStop = 8;
    SetStopLoss(strOrder, CalculationMode.Price, order.AvgFillPrice - (TrailingStop * TickSize), true);


    Now when I get so many ticks in profit I want to move my stop loss up to eg: 4 ticks.

    Where would I do this? in OnPositionUpdate() ?

    #2
    OnPositionUpdate() is only called if there has been a change in your position.

    If the condition you're looking for is 4 ticks, you'd want to do this in OnBarUpdate()

    Code:
    if(Close[0] >= order.AvgFillPrice + (4 * TickSize)
    // SetStopLoss @ desired price
    Please have a look at the following sample which shows how to accomplish this:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Ok, thanks for the link. However, the script uses "Position.AvgPrice" but your example in this thread uses "order.AvgFillPrice". I believe it should be Position.AvgPrice, correct?

      Comment


        #4
        I was just quoting your code.

        If you want it based off your entire position, use the Position.AvgPrice.

        If you want it off that specific order, use order.AvgPrice
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        68 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        61 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
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X