PDA

View Full Version : Order error handling


Aussie2
12-17-2007, 08:33 PM
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

NinjaTrader_Dierk
12-17-2007, 10:36 PM
>> 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:

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.

NinjaTrader_Ray
12-18-2007, 07:09 AM
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...

Aussie2
12-19-2007, 08:09 AM
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!

Aussie2
12-27-2007, 06:36 AM
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("xxx@hotmail.com", "xxx@hotmail.com", "Ninja Trader Connection", msgA);}