Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order cancel issues in fast moving market

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

    Order cancel issues in fast moving market

    My strategy has 3 separate short entries and exits each with ExitShortStopMarket and ExitShortLimit as the exit orders. I have also tried using ExitShortMIT

    I am not exactly sure the mechanics but in a fast moving market I am getting the error messages below and the strategy terminates and winds up with open long positions.
    Otherwise the exits work perfectly.

    It is structured with 2 contracts on the first entry and 1 contract for each of the other 2 entries.

    As much as I have been able to test If I change to having only 1 contract for each entry this does not happen.

    Any help with this is appreciated.

    Click image for larger version  Name:	Exit Errors.PNG Views:	0 Size:	12.0 KB ID:	1168193
    Attached Files
    Last edited by sdauteuil; 08-17-2021, 04:53 PM.

    #2
    Hello sdauteuil,

    Thanks for your post.

    This error message means that the strategy attempted to change an order to the wrong side of the market. If this is due to market volatility then there isn't really a way to 100% avoid this occurring, as in volatile markets the market could move so far and fast that this would occur.

    Something you could consider is using GetCurrentBid() and GetCurrentAsk() to offset orders so that they are more likely to land on the correct side of the market.

    See these help guide pages for more information.
    GetCurrentBid(): https://ninjatrader.com/support/help...currentbid.htm
    GetCurrentAsk(): https://ninjatrader.com/support/help...currentask.htm

    You could also consider using RealtimeErrorHandling.IgnoreAllErrors to trap order errors in OnOrderUpdate by checking error == ErrorCode.UnableToChangeOrder.

    Please note that setting this property value to IgnoreAllErrors can have serious adverse affects on a running strategy unless you have programmed your own order rejection handling in the OnOrderUpdate() method. To do this you could trap the rejected order by checking if the OrderState is Rejected within OnOrderUpdate() followed by defining your own order rejection handling behavior for the rejected order.

    Please see the example in the help guide link below that demonstrates using RealtimeErrorHandling and trapping a rejected order in OnOrderUpdate().

    RealtimeErrorHandling — https://ninjatrader.com/es/support/h...orhandling.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      This is what is confusing...

      I have 3 named entries and exits.

      When they are all set to 1 contract I am not having this issue.

      When I change one of them to 2 contracts is when the issue starts.
      Winding long 2 contracts seems to be the most common result. Sometimes the strategy disables itself sometimes not.

      I cannot understand why that is the case.

      I will try the GetCurrentBid() GetCurrentAsk()


      This is my exit code
      ExitShortStopMarket(0, true, Contracts, Position.AveragePrice + StopLoss * TickSize, "Stop Loss SX", Convert.ToString(EntryName));
      ExitShortLimit(0, true, Contracts, Position.AveragePrice - ProfitTarget * TickSize, "Profit Target SX", Convert.ToString(EntryName));

      Comment


        #4
        Hello sdauteuil,

        Thanks for your note.

        I do not see anything specific in the code you shared that would cause the behavior you are reporting.

        That said, to understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

        In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121

        Please let me know if I may further assist wi
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 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
        72 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
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X