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

Strategy and Chart completely hang if ChangeOrder price issues.

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

    Strategy and Chart completely hang if ChangeOrder price issues.

    I'm writing an unmanaged order manager and testing it with a simple reversal Calculate.OnBarClose strategy. With RealtimeErrorHandling = RealtimeErrorHandling.IgnoreAllErrors;

    The strategy takes an initial long or short position and thereafter the position is reversed by an opposite entry order which is initially placed in OnExecutionUpdate

    (_LongEntryFilled = cumulative count of contracts filled and/or partfilled. _trailingShort[0] is double price below last.

    Code:
                if     ( _shortEntryStopMar****rder==null)
                {
                       SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.StopMarket,  _longEntryFilled, 0.0,_trailingShort[0], "", "EntryShort");
                }
                else
                {
                        ChangeOrder(_shortEntryStopMar****rder,  _longEntryFilled, 0.0,_trailingShort[0]);
                 }
    Then in OnBarUpdate the active order is adjusted bar by bar as the trailingshort price changes:

    Code:
                if     ( _shortEntryStopMar****rder!=null && Position.MarketPosition == MarketPosition.Long)    
                {
                      if (_shortEntryStopMar****rder.StopPrice < _trailingShort[0] && Close[0] - TickSize  >= _trailingShort[0])
                      {
                           ChangeOrder(_shortEntryStopMar****rder, _contracts  + Position.Quantity,  0.0, _trailingShort[0]);
                      }
                }
    If the open of the following bar gaps above (or below) the ChangeOrder price, results in an error message:

    Click image for larger version  Name:	Error.PNG Views:	0 Size:	8.7 KB ID:	1089494


    This is fair enough, however if the "OK" is not clicked quickly the entire chart just freezes.

    I've found to recover one way is to kill the entire NinjaTrader process stack or to cancel the last entry order from another window, e.g. Superdom. If I am able to cancel the entry order, then the chart spools the buffered ticks but the strategy is dead.

    Any advice on how to add code to avoid encountering this error or better yet to handle it? Is there existing reference code to properly handle rejects somewhere? I see in OnOrderUpdate https://ninjatrader.com/support/help...t8/?charts.htm we get the state and error code which seem to be generic, like ErrorCode.OrderRejected. However Ninja obviously is receiving more detailed information in order to determine to present the above error message.

    Where is this info exposed? I'm assuming its passed back from the broker (simulator) via the OnOrderUpdate string comment field.

    If so, can you provide a list of possible string values by SIM101 and NinjaTrader Continuum?

    Will proper handling of the rejection obviate the need to present the user with an error message, that is to not stop the UI / strategy?
    Last edited by lavalampmj; 03-05-2020, 04:54 PM.

    #2
    Hello lavalampmj,

    Thanks for your post.

    The strategy can ignore these errors with RealtimeErrorHandling set to IgnoreAllErrors, but there is not a supported way to suppress the error messages.

    The chart freezing would not be something we would expect to see. Could you attach a simplified script that takes this approach and encounters this issue on NinjaTrader 8 Release 21? If we have a simplified working test that demonstrates the issue, we can use it to file a report. You could post the script here, or you can email it to me at platformsupport [at] ninjatrader [dot] com with the text "Attn Jim 2445435" and a link to this thread. The script does not need to have complex logic or any real entry signals, it should just have enough order submission logic where we can hit this behavior on our end with NinjaTrader 8 Release 21.

    I look forward to being of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      I'll send you a script via email. I'm on 8.20 not 8.21

      Having errors being displayed (with the result of freezing charts) means the platform cannot be used for 23x5 trading. Its a big deal for me, probably a show stopper. If a user has to click OK at 3:00am its just not going to happen, further the notion of RealtimeErrorHandling.IgnoreAllErrors become pointless because it does not implement the desired functionality. I'm happy with using "unsupported" methods if there are some available to suppress the error msg. Please advise here or by email.

      It would be helpful to me and perhaps others who wish to write their own unmanaged order handlers, to correctly process order rejects.

      In this specific case I might wish to send a market order upon the reject or adjust the price and resubmit. There are probably many many reasons for an order rejection.

      In order to intelligently handle rejects, I need to build some logic for the various reject cases. I believe that contextual "why" data is passed in the last string comment field by the broker in OnOrderUpdate event.

      Can you post all of the possible strings sent from the broker (in my case) NinjaTrader Continiuum and SIM101. Thanks.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Christopher_R, Today, 12:29 AM
      0 responses
      9 views
      0 likes
      Last Post Christopher_R  
      Started by sidlercom80, 10-28-2023, 08:49 AM
      166 responses
      2,235 views
      0 likes
      Last Post sidlercom80  
      Started by thread, Yesterday, 11:58 PM
      0 responses
      3 views
      0 likes
      Last Post thread
      by thread
       
      Started by jclose, Yesterday, 09:37 PM
      0 responses
      8 views
      0 likes
      Last Post jclose
      by jclose
       
      Started by WeyldFalcon, 08-07-2020, 06:13 AM
      10 responses
      1,415 views
      0 likes
      Last Post Traderontheroad  
      Working...
      X