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

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.
    JimNinjaTrader Customer Service

    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 lightsun47, Today, 03:51 PM
      0 responses
      4 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      8 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      44 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      13 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      9 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X