Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order error handling

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

    Order error handling

    Hello,

    As this is my first post I wanted to start by thanking Ray and Dierk et al, for the great forum, which I find to be an invaluable learning tool, and very necessary despite my other programming experience !! I still have a lot to learn about C# !!

    I have just started trading a strategy live, and want to make it more robust, hence the direction of my queries.

    1. I note the Ninja reference manual discusses Live Options, particularly Error handling, but cannot find a list of order error codes. Is there one? I simply wanted to email my mobile on a “strategy stop, cancel and close”.

    2. Could some kind person post an example of order error trap coding? Similarly an example of System.Exception level trapping to generate an email would be appreciated !

    3. Also when a position with stop loss, is stopped out, is there a system data field/variable to advise this?

    4. Finally is there a way to apply a template to a chart within a strategies code? (or add an indicator to panel 2 within the strategy code? )

    Thanking you in advance
    Aussie2 a contented Ninja trader

    #2
    >> but cannot find a list of order error codes. Is there one?
    Unfortunately not.

    >>
    an example of order error trap coding
    You could try something like:
    Code:
    try
    {
        // you code which could throw exception
        // note: NinjaScript NEVER will throw an exception to indicate an error
        // thus, only exceptions from your code would be trapped
    }
    catch (Exception exp)
    {
        // do something, e.g. send mail with error text "exp.Message"
    }
    But this is beyond of what we support, since NinjaScript will not throw any exception which you needed to trap.

    >> when a position with stop loss, is stopped out, is there a system data field/variable to advise this
    Please check out the OnPositionUpdate event in NT6.5

    >>
    is there a way to apply a template to a chart within a strategies code?
    Unfortunately not.

    Comment


      #3
      What we mean by error handling is if an order is rejected for any reason, this "error" could be handled in NT 6.5 OnOrderUpdate() method etc...
      RayNinjaTrader Customer Service

      Comment


        #4
        Just got ver 6.5 Beta

        Hmm, well, thanks ! Now have ver 6.5 beta, .... and all those new methods, and so much more to digest !

        Expect I will start with "ConnectionStatus.Connected" to flag and email/sms an IB outage. Great. Also for the IB AD-NYSE charting support. This was on my wish list, and will be very useful.

        Chritmas came early!

        Comment


          #5
          Postscript - on a broker disconnet emails sent before NT disconnects all strategies

          Just a quick postscript - solved my query about generating an email / sms using NT ver 6.5 BETA without the need for Try/Catch/Exception method handling.

          Problem: You may have noticed that on a broker disconnect NT disconnects all strategies! Also I use IB and they log you out if you dont reset their auto log out feature twice a day (!) & I want an email / sms to advise such log outs / disconnects so I can restart my NT strategy.

          Solution: Create a separate strategy to just email / sms on a broker disconnect using the following code which executes just before NT disconnects the strategy!
          Regards.

          if(orderStatus==ConnectionStatus.Disconnected)
          {Print("Disconnected");
          msgA = "Ninja Trader: ConnectionLost ";
          SendMail("[email protected]", "[email protected]", "Ninja Trader Connection", msgA);}

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          580 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          335 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          102 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X