View Full Version : crash on order handling
ATI user
11-27-2009, 03:36 PM
I am using AtmStrategyCreate to place sell/buy stop orders close to (2 ticks) the market last trade price
this works fine until the market (NQ) moves 5 ticks while I am in the middle of placing an order
of course checking where the market is prior to placing the order is not working as the market move occurs within a few milliseconds
so I get the attached error and NT8b4 freezes...i.e. must use Task Manager to close NT and then the usual delays occur while restarting and reconnecting....not good during live trading
I do not mind the error as I can work around it.
I do mind the crash/freeze after the error as I can not recover/continue trading
1. From my reading of IOrder, OnOrderUpdate, OnExecution and Unmanaged = true, etc....all these methods seem to only apply to EnterLong and EnterShort orders and not to AtmStategyCreate orders...correct?
2. How can I handle the error to avoid the crash?
Thanks
NinjaTrader_Ray
11-28-2009, 05:28 PM
Somone will follow up Monday.
NinjaTrader_Josh
11-30-2009, 07:42 AM
1. You are correct in that they do not apply to AtmStrategyCreate().
2. Please provide the trace/log files. Did it really crash with an error or was it just hanging for a little bit?
ATI user
11-30-2009, 08:01 AM
NT crashed.....could not select any charts or functions in NT for more than 10 mins
could not close it without using Task Manager
consistent crash everytime at exactly same time of replay data....9:32:31....which is when market jumped 4 or 5 ticks while the trade was being placed
will recreate later today and set you trace/log
ATI user
12-02-2009, 10:59 AM
beta 5 in not crashing under the same circumstances ..i.e. trying to place a sell stop order above the market
however, it does leave a filled position uncovered
my solution at this point is to Close from DOM which clears all positions and then Enable the strategy again
can you please suggest a better way of dealing with/avoiding uncovered orders
thanks
NinjaTrader_Josh
12-02-2009, 11:18 AM
Check status in your code for actual submission of the ATM strategy.
ATI user
12-02-2009, 11:35 AM
the order that is rejected is Stop1 ...coming from an AtmTemplate with a 6 tick initial stop
the Atm was triggered by a BuyStop
mkt goes up, hits the stop, fills the order....mkt drops before 6 tick sell stop can be placed
see attached
long fill at 1748.50....trying to place 6 tick stop at 1747.00....market already too low
obvious answer is to use a wider stop....and I could have atm start wide and close....however, I was hoping for a more elegant solution...i.e. no uncovered long position
NinjaTrader_Josh
12-02-2009, 11:56 AM
ATI user,
Would have to be handled by your code. Check ATM stop/target status. When its rejected like that you want to go ahead and kill that position.
ATI user
12-02-2009, 03:17 PM
Josh
Thanks once again for leading me to the obvious....should have thought of that myself.
One problem remains...
using GetAtmStrategyMarketPosition ( "Stop1", atmStrategyIdLONG ) for the open long position does not return 'Rejected' because in the Log the order that is rejected is not the same ID as related to atmStrategyIdLONG ...and of course the OrderId related to atmStrategyIdLONG is long since set to null as the original buystop has been filled...
in other words, the rejected order ID is not generated from my code but rather seems to be internal from the ATM template.
how do I get my hands on that ID?
NinjaTrader_Josh
12-02-2009, 03:47 PM
Please try using GetAtmStrategyStopTargetOrderStatus().
http://www.ninjatrader-support.com/HelpGuideV6/GetAsmStrategyStopTargetOrderStatus.html
ATI user
12-02-2009, 04:21 PM
yet another Copy/Paste error in my post...I am already using that
here is the whole code:
// check for uncovered long positions
if ( atmStrategyIdLONG[i] != null && atmStrategyIdLONG[i].Length > 0
&& GetAtmStrategyMarketPosition(atmStrategyIdLONG[i]) != Cbi.MarketPosition.Flat )
{
string[,] orders = GetAtmStrategyStopTargetOrderStatus( "Stop1", atmStrategyIdLONG[i] );
if (orders.Length > 0)
{
for ( int k = 0; k < orders.GetLength(0); k++ )
{
Print("399 Current state "+(i+1)+" " + orders[k, 2].ToString() );
Print("399 atmStrategyIdLONG "+(i+1)+" "+ atmStrategyIdLONG[i].ToString() );
Print("399 orderIdLONG"+(i+1)+" "+ orderIdLONG[i].ToString() ); // this is always null at this point
if ( orders[k, 2] == "Rejected" )
{
Print("402 *********** stop loss order rejected *********** " ); // has never printed because wrong ID
}
NinjaTrader_Josh
12-02-2009, 04:35 PM
Not sure I follow. When you get entered you must have provided an ATM strategy ID. That ID is the one you want to use.
ATI user
12-03-2009, 06:57 AM
that is the ID I am using
however the ID of the stop that is rejected does not have that ID....which is why I have not been able to print the rejected error per the code above..
I have been trying to send better data to you however beta 5 keeps freezing
you should be able to reproduce at your end
1. download NQ for 27 nov
2. create an atm template with a 6 tick stop
3. goto 9:32:20 EST i.e. just after open
4. place a buy stop above mkt at 1748.50
5. play MR at 1x and NT will lock up at 9:32:30 ....9 times out of ten it will just freeze...sometimes it will throw the error and I am able to pause and review data....the last 5 times I have tried this, it froze......so consistent it should work for you also
ATI user
12-03-2009, 09:21 AM
that is the ID I am using
however the ID of the stop that is rejected does not have that ID....which is why I have not been able to print the rejected error per the code above..
I have been trying to send better data to you however beta 5 keeps freezing
you should be able to reproduce at your end
1. download NQ for 27 nov
2. create an atm template with a 6 tick stop
3. goto 9:32:20 EST i.e. just after open
4. place a buy stop above mkt at 1748.50
5. play MR at 1x and NT will lock up at 9:32:30 ....9 times out of ten it will just freeze...sometimes it will throw the error and I am able to pause and review data....the last 5 times I have tried this, it froze......so consistent it should work for you also
I just tried my above suggestion and, although there is a slight pause (< 2 sec) at 9:32:30, NT7 beta 5 does not freeze or throw an error message.
So... buy stop is placed and filled fill at 1748.50 ...mkt drops instantly to 7 ticks lower, the stop is placed 6 ticks lower and filled at the entry fill price at 1748.25 (see pic)
for some reason my code does not handle the quick move without beta 5 freezing
what can be the difference in that all my code does is place the exact same buy stop at the same price???
NinjaTrader_Josh
12-03-2009, 02:32 PM
If you can strip your code to the bare essentials (none of those arrays things) and strip all unnecessary logic out. I will try your code on my end. Please also provide the exact replay file you are using and information on how you have your ATM strategy setup in the DOM. Thank you.