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 NullPointStrategies, Today, 05:17 AM
          0 responses
          52 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          70 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          48 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X