Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop orders are rarely being submitted when they should be

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

    Stop orders are rarely being submitted when they should be

    Hi,

    I’m experiencing an issue with my trading algorithm where stop orders are rarely getting submitted while backtesting. When my conditions are met, the code is supposed to be placing three orders simultaneously:
    1. EnterLongLimit(assetNum, true, int.Parse(variables.ShareSize.GetValueOrDefault(). ToString()), entryPrice, "");
    2. ExitLongStopLimit(assetNum, true, int.Parse(variables.ShareSize.GetValueOrDefault(). ToString()), riskLimit, stopPrice, "", "");
    3. ExitLongStopMarket(assetNum, true, int.Parse(variables.ShareSize.GetValueOrDefault(). ToString()), stopPrice - (passValue / 2), "", "")

    A fourth take profit order (ExitLongLimit) is being placed in OnOrderUpdate when the EnterLongLimit order is filled. I have an inverse set of orders being placed for taking short positions. The stop-market order is set a good distance beyond the stop-limit order acting as a security in cases where the stop-limit order isn’t able to get filled.

    As you can see in my screenshot of the orders page in the strategy analyzer, stop orders aren’t getting placed when they should be. The first seven orders are all limit orders. The eighth order is a stop-limit with no stop-market. This issue persists throughout every backtest I run. Logs are not showing any warnings or errors. Help with this would be much appreciated!

    #2
    Hello irochester,

    Thanks for your post.

    Please first be sure to review the Managed Approach section of the Help Guide to note when orders would be ignored. There specific rules surrounding the submission of Enter and Exit methods and when they would be ignored.

    Internal Rules of Managed Approach - https://ninjatrader.com/support/help...rnalOrderHandl ingRulesThatReduceUnwantedPositions

    As another item, Exit orders may never exceed the strategy's Position.Quantity and the strategy Position object is driven by Executions. If you are trying to submit an exit order in OnOrderUpdate, we may not yet have seen the Execution that would increase the strategy Position, so the order may be ignored. It is recommended to use OnExecutionUpdate for submission of target/stop orders.

    OnExecutionUpdate - https://ninjatrader.com/support/help...tionupdate.htm

    If there are any other order submissions that are being ignored that are unclear, please do the following:
    1. Add a print beside the order method to confirm it is being reached
    2. Test with TraceOrders enabled and check the Output window for any hints on why the orders were ignored.
    Please then let us know the specific order method and the TraceOrder message so we can comment on any other remaining ignored orders.

    TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

    We look forward to assisting.
    Last edited by NinjaTrader_Jim; 02-25-2022, 07:10 AM.

    Comment


      #3
      Hi Jim,

      Moving all of the exit orders into OnExecutionUpdate solved my problem. Thank you much!
      Last edited by irochester; 02-25-2022, 08:02 PM.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      65 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      139 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X