Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there a way to change the order type when the order is not filled

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

    Is there a way to change the order type when the order is not filled

    For example I have the following orders

    Code:
    SetProfitTarget("Trade_001", CalculationMode.Price, tpPrice);
    SetStopLoss("Trade_001", CalculationMode.Price, slPrice, false);
    EnterLong(quantity, "Trade_001");
    When I meet a condition, I want to change the StopLoss to a Trailing order. I have tried SetTrailStop(). It has no effect since the order type is not a trail stop. I look to ChangeOrder() and found that this api cannot change order type too.

    I would like to ask if there is a way to change the order type?
    If no way, then this limitation is due to broker ? for example IB ?

    Thank you very much.

    #2
    Hello Sulfred,

    Thanks for your post.

    The SetTrailStop() and SetStopLoss() cannot be used on the same order, this is advised in the help guide for each of those methods: "The SetTrailStop() method can NOT be used concurrently with the SetStopLoss() or SetParabolicStop() method for the same position, if any of methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use all three methods in the same strategy if they reference different signal names." Reference: https://ninjatrader.com/support/help...ttrailstop.htm https://ninjatrader.com/support/help...etstoploss.htm

    You can create your own trailing stop using the SetStopLoss() with your own logic that would adjust the stop loss as needed by comparing the current price to the entry price and setting the stop loss at some level behind the current price. Typically a trail stop does not move backwards so you would need your logic to prevent going backwards and only adjust going forward.

    Comment


      #3
      Thank you for reply.

      Here is a follow up question.

      Suppose I am going to use the SetStopLoss() and update it in my script which can deliver the same effect as SetTrailStop(). What am I suppose to do is updating the SetStopLoss() tick by tick. Am I right? For example:

      Code:
      OnMarketData()
      {
          if (order is placed and condition is okay)
              SetStopLoss("Order_001", CalculationMode.Price, updateSLPrice, false);
      }
      
      OnBarUpdate()
      {
          if (no order is placed and condition is okay)
         {
            SetStopLoss("Order_001", CalculationMode.Price, firstSLPrice, false);
            EnterLong(1, "Order_001");
         }
      }
      But I cannot backtest this strategy without using Tick replay in strategy analyzer. Then there is another problem, when I use tick replay, the data I added by AddDataSeries() will be gone.

      So I would like to ask what is a better way to do this?

      Thank you very much.

      Comment


        #4
        Hello Sulfred,

        Thanks for your reply.

        You can use the Playback connection with market replay data which will provide all of the data needed and as such however the process will be considerably slower.

        Comment


          #5
          Thank you very much.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by CarlTrading, 03-31-2026, 09:41 PM
          1 response
          43 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          20 views
          0 likes
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          29 views
          1 like
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          46 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          38 views
          0 likes
          Last Post CarlTrading  
          Working...
          X