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 charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        65 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        149 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        162 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        99 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        286 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X