Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

change stop market to limit order in strategy

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

    change stop market to limit order in strategy

    By default in my strategy a stop market order is used to enter a trade when conditions are met. However sometimes price, I assume, already passes the order price which makes ninjatrader show some pop up saying something along the lines of order rejected.

    Can I use a try catch block so that if the order fails to go through, it tries to put in a limit order instead. What kind of error would I need to catch in this case?

    #2
    Hello dRun22,

    Thank you for the message.

    I'm not sure what you mean by a catch block or anything like that.

    If your Stop Target is too close to the Last Traded price where it is able to land on the incorrect side of the Last Traded Price from a fast moving price in between the Entry Order Filling and the Stop Target Order making it to the servers, then the resolution would be to increase the distance the stop target is being placed from entry until the error no longer happens.
    • Unfortunately, there is no way to disable the Order Entry Errors at this time.
    • The only way to not see them is to avoid hitting them in the first place.

    If you want to use a Stop Limit Order on your ATM Strategy instead of Stop Market:
    • Hover the mouse over your ATM Strategy in the ATM Strategy Dropdown menu > Click edit
    • Click to expand the "More" section
    • Check the box next to "Stop limit for stop loss" > Click OK
      • Now, the Stop Target will be a Stop Limit order with a 20 Tick Limit Offset hard coded into it.
    • Remember to "Save Template" and either give it a new name or overwrite the original one.
    Please let us know if we may provide any further assistance.

    Comment


      #3
      Originally posted by NinjaTrader_Clayton View Post
      Hello dRun22,

      Thank you for the message.

      I'm not sure what you mean by a catch block or anything like that.

      If your Stop Target is too close to the Last Traded price where it is able to land on the incorrect side of the Last Traded Price from a fast moving price in between the Entry Order Filling and the Stop Target Order making it to the servers, then the resolution would be to increase the distance the stop target is being placed from entry until the error no longer happens.
      • Unfortunately, there is no way to disable the Order Entry Errors at this time.
      • The only way to not see them is to avoid hitting them in the first place.

      If you want to use a Stop Limit Order on your ATM Strategy instead of Stop Market:
      • Hover the mouse over your ATM Strategy in the ATM Strategy Dropdown menu > Click edit
      • Click to expand the "More" section
      • Check the box next to "Stop limit for stop loss" > Click OK
        • Now, the Stop Target will be a Stop Limit order with a 20 Tick Limit Offset hard coded into it.
      • Remember to "Save Template" and either give it a new name or overwrite the original one.
      Please let us know if we may provide any further assistance.
      Thank you for the response. I did try to increase the distance but I don't want to push it too far, that's why I'm hoping to use a limit order for the chance of price returning to the targeted entry price.

      As for the try catch block I meant something as follows:
      if (Position.MarketPosition == MarketPosition.Flat && ShouldEnterLong())
      {
      try
      {
      EnterLongStopMarket(entryPrice);
      }
      catch (Exception ex)
      {
      // Check if the exception indicates the price is unfavorable for a stop market order, this would obviously require ninjatrader to throw out an error message with the order error pop up
      if (ex.Message.Contains("Price is at or above stop price"))
      {
      EnterLongLimit(entryPrice);
      }
      }

      I feel like this could work, but I'm not sure about whether an actual error is logged. I could obviously try to update my script with this included and test it out with live data but if someone for sure knows if this is even possible, that would be great

      Comment


        #4
        Hello dRun22,

        This thread has been moved from the Platform Technical Support section of the forums to the NinjaTrader Desktop > Strategy Development​ section of the forums as this is an inquiry about strategy development (programming NinjaScript in C#).

        A try and catch is not going to catch an order error.

        I would recommend you first ensure that your stop order has a valid price. See the article below.


        If you want to detect the order is rejected, this would be done in OnOrderUpdate() when the order.OrderState is OrderState.Rejected.
        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


        For the strategy to not be disabled, you would need to use RealtimeErrorHandling.StopCancelCloseIgnoreRejects .
        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello dRun22,

          This thread has been moved from the Platform Technical Support section of the forums to the NinjaTrader Desktop > Strategy Development​ section of the forums as this is an inquiry about strategy development (programming NinjaScript in C#).

          A try and catch is not going to catch an order error.

          I would recommend you first ensure that your stop order has a valid price. See the article below.
          I was afraid and kind of expecting that was the case. My current implementation has OnBarUpdate running on bar close so i set the entry price 1 tick above the high of bar[0], in case Close[0] == High[0] i set the entry price at 2 ticks above the high for long entries. I thought i could get away with that, but i might have to implement GetCurrentAsk() and GetCurrentBid()

          Thank you

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Today, 05:17 AM
          0 responses
          22 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          120 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          63 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          41 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          45 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X