Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Thank you very much.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by jaybedreamin, Today, 05:56 PM
          0 responses
          3 views
          0 likes
          Last Post jaybedreamin  
          Started by DJ888, 04-16-2024, 06:09 PM
          6 responses
          18 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by Jon17, Today, 04:33 PM
          0 responses
          1 view
          0 likes
          Last Post Jon17
          by Jon17
           
          Started by Javierw.ok, Today, 04:12 PM
          0 responses
          6 views
          0 likes
          Last Post Javierw.ok  
          Started by timmbbo, Today, 08:59 AM
          2 responses
          10 views
          0 likes
          Last Post bltdavid  
          Working...
          X