PDA

View Full Version : Cancel unfilled Auto order not working ..need help


pdawg
06-26-2007, 03:48 AM
Hello,

I am trying to cancel an unfilled entry order after 1 bar. Here is how I am trying to accomplish this (I'll spare you the if() conditions):

if()
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Limit, Close[0] + -.1, 0, TimeInForce.Day, orderId, "133t Trail", atmStrategyId);
DrawArrowUp("ZLR Long", 0, Low[0] - TickSize, Color.Lime);
Print("The order triggered atmStrategyId# is: " + (atmStrategyId));
Print("The order triggered orderId# is: " + (orderId));
}

// Cancel if order is not filled after close of entry bar
if (atmStrategyId.Length > 0
&& GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
{
AtmStrategyCancelEntryOrder("atmStrategyId");
Print("Cancelling Unfilled ATM Entry #"+(atmStrategyId));
}

Here what the output window gives when an order didn't get filled:

The order triggered atmStrategyId# is: d9e0f3914a974925974d28122e98f3a2
The order triggered orderId# is: f23e4f7d1db64725989917b63131ff74
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Initialized
Cancelling Unfilled ATM Entry #d9e0f3914a974925974d28122e98f3a2
The current ATM Strategy market position is: Flat
The current ATM Strategy position quantity is: 0
The current ATM Strategy average price is: 0
The current ATM Strategy Unrealized PnL is: 0
The current ATM Strategy ID# is: d9e0f3914a974925974d28122e98f3a2
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Working
Cancelling Unfilled ATM Entry #d9e0f3914a974925974d28122e98f3a2
The current ATM Strategy market position is: Flat
The current ATM Strategy position quantity is: 0
The current ATM Strategy average price is: 0
The current ATM Strategy Unrealized PnL is: 0
The current ATM Strategy ID# is: d9e0f3914a974925974d28122e98f3a2
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Working

..and on and on as the entry order never gets cancelled and sits there trying to fill. What am I missing? Can someone point me in the right direction?

Thanks.

NinjaTrader_Ray
06-26-2007, 07:07 AM
Always look in the Control Center log tab to see if there are any error/warning messages. I suspect you might see something like "OrderId does not exist".

Try

AtmStrategyCancelEntryOrder(orderId);

pdawg
06-26-2007, 03:23 PM
Thanks. I checked the log and sure enough I saw an error message:

6/26/2007 10:52:26 AM Strategy AtmStrategyCancelEntryOrder() method error: orderId 'orderId' does not exist

It seems that passing AtmStrategyCancelEntryOrder("orderId") with quotes was passing that text as opposed to the actual variable. So I changed it to just (orderId).

So next I did a test to see if an order would actually be cancelled:

6/26/2007 11:08:53 AM Order Submitting order with strategy id-f82f180169c245c9a5dbb4b717811ca1'
6/26/2007 11:08:53 AM Strategy AtmStrategyCancelEntryOrder() method error: orderId '0f3ad1c6c2a1434f94e9e9a17bbfb80f' does not exist

it seems that the unique values generated from:

atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();

Differ from the strategy id of the sent order. Any ideas here?

NinjaTrader_Ray
06-26-2007, 04:51 PM
Looks like you are in for a debug session.

Add some Print() statements such as printing out the orderId at the time you place the order and then print out the orderId at the time you cancel to make sure they are in fact the same id value.

pdawg
06-27-2007, 03:43 AM
Ray,

Thanks for the responses. Here is the order command:
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Limit, Close[0] + -.1, 0, TimeInForce.Day, orderId, "133t Trail", atmStrategyId);
DrawArrowUp("ZLR Long", 0, Low[0] - TickSize, Color.Lime);
Print("The order triggered atmStrategyId# is: " + (atmStrategyId));
Print("The order triggered orderId# is: " + (orderId));
}

The Id's printed differ from what's in the log. At the moment I don't know what else I could print that would be generating a different Id. As a workaround I used AtmStrategyClose():

// Checks on bar update if any entry order has been filled or not. If not then cancel and reset strategy id.
// Reset the strategy id here too for completed order from prior bar.

if (atmStrategyId.Length > 0
&& GetAtmStrategyMarketPosition(atmStrategyId) == MarketPosition.Flat)
{
AtmStrategyClose(atmStrategyId);
Print("Closing ATM Strategy #"+(atmStrategyId));
atmStrategyId = string.Empty;
Print("Resetting the atmStrategyId. Strategy Value is now: " +(atmStrategyId));
}

NinjaTrader_Ray
06-27-2007, 07:06 AM
You need to make sure that that you do not create a new orderId until after the order is filled or cancelled.

pdawg
06-27-2007, 10:24 AM
Ray,

I have a print command everywhere there is a possible order command and Id reset command so if there was another Id being generated it should show up on the output window.

Here is the output window on a non-filled order:

The order triggered atmStrategyId# is: de4345459cb844b4a5032a55f855bcd9
The order triggered orderId# is: 57e688f32e1f47c4873bb31feb87b9ed
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Initialized
The current ATM Strategy market position is: Flat
The current ATM Strategy position quantity is: 0
The current ATM Strategy average price is: 0
The current ATM Strategy Unrealized PnL is: 0
The current ATM Strategy ID# is: de4345459cb844b4a5032a55f855bcd9
Closing ATM Strategy #de4345459cb844b4a5032a55f855bcd9
Resetting the atmStrategyId. Strategy Value is now:
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: PendingCancel
The entry order average fill price is: 0
The entry order filled amount is: 0
The entry order order state is: Cancelled
The Order state is Cancelled resetting the order id value to:
The strategy has terminated resetting the atmStrategyId. Strategy Value is now:

The log shows:

6/27/2007 6:02:24 AM Order Submitting order with strategy id-ceb7cb4840d24966bc8bbee45d58a9bd'
6/27/2007 6:02:24 AM Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=PendingSubmit Instrument='ER2 09-07' Action=Buy Limit price=835 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
6/27/2007 6:02:24 AM Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Accepted Instrument='ER2 09-07' Action=Buy Limit price=835 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Cancelled Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=PendingCancel Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
6/27/2007 6:02 Strategy Cancelling any remaining strategy orders
6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Working Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Accepted Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
6/27/2007 6:02 Strategy Auto chase price modification to '835.1'
6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=PendingChange Instrument='ER2 09-07' Action=Buy Limit price=835.1 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''
6/27/2007 6:02 Order Order='b6107272cd9b4ac6a6ae04e2284d0280/Sim101' Name='Entry' New State=Working Instrument='ER2 09-07' Action=Buy Limit price=835 Stop price=0 Quantity=2 Type=Limit Filled=0 Fill price=0 Error=NoError Native error=''

The (atmStrategyID) and (orderId) being parsed from from the buy command is differing from the actual values in the log. No new orderId or strategy Id's are being created from the script.

Any ideas?

NinjaTrader_Ray
06-27-2007, 12:41 PM
Hi pdawg,

No ideas here, you will have to debug your code. Attached is a sample strategy that demonstrates the creation and cancellation of an ATM entry order. Works as expected.

You can import this strategy via File > Utilities > Import. Make sure you are on 6.0.1000.3 or higher. Also make sure you have an ATM strategy named "Test".

pdawg
06-27-2007, 01:22 PM
Ray,

Thanks for that. I will test it out let you know what I find.

NinjaTrader_Josh
07-28-2007, 02:41 AM
What about regular strategy entries? If I have an EnterLong() that I need canceled how do I go about achieving this?

NinjaTrader_Dierk
07-28-2007, 11:02 PM
Simply don't resubmit the entry signal on next bar. Note: You can not explicitly cancel out strategy orders.

NinjaTrader_Josh
07-28-2007, 11:27 PM
Hmm. I thought the orders generated would be "working" till the end of the day or till canceled. I'm trying to enter a limit order to do some very quick momentum scalping, but if it does not meet my limit within say 10 seconds I don't want that order anymore because the scalpable gains are already. Should I look into ATM strategy to achieve this? Also what is the reason for not being able to cancel out of strategy orders?

NinjaTrader_Dierk
07-28-2007, 11:32 PM
The concept of NS orders (not ATM... methods, only regular NS signals) is that the orders are canceled out if you don't resubmit the signal with the next bar. This is the same concept as e.g. TS provides it.

However, by fall time frame we will provide an additional feature to fully control your orders (incl. explicit cancellation). Note: You then will not have the convenience of the current implementation. We'll publish details as we roll that release.

dwalls
08-16-2007, 07:59 PM
Hi NinjaTarder Ray,

I'm trying to get one of my Atm Strategies to work with my one of my strategies. I'm trying to use the AtmTest.zip from a post below. I created a ATM Strategy named "Test" like you suggested. My question is about the "testStrategyIdValue" from the code below.
Is this a specfic value that I need to get from somewhere and enter in here like the strategy name or is it a strategy/computer generated value that enters by itself?
If I need to enter a IdValue in there myself and my strategy name was different, like "Test100", would that change that value to "test100StrategyIdValue"?

orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Limit, GetCurrentBid() - 10 * TickSize, 0, TimeInForce.Day, orderId, "Test", "testStrategyIdValue");
orderPlaced = true;


or from the help file I found this under AtmStrategyCreate():

protected override void OnBarUpdate()
{
if (Historical)
return;

// Check for valid condition and create an ATM Strategy
if (Close[0] > SMA(20)[0])
AtmStrategyCreate(Action.Buy, OrderType.Market, 0, 0,
TimeInForce.Day, GetATMStrategyUniqueId(), "MyTemplate",
GetAtmStrategyUniqueId());
}

Is this the same type of Atm Strataegy?


Thanks for your help

NinjaTrader_Dierk
08-17-2007, 12:02 AM
"testStrategyIdValue" is just an ID which will identify your strategy for further calls to manage the ATM strategy. You may pick any unique ID in order to identify your strategy.

MrTicks
05-29-2010, 09:22 AM
Ray,

Thanks for that. I will test it out let you know what I find.

Hi pdawg - Did you find a solution to the orderID does not exist entry in your logs? If so, could you share the code that solved the issue?


Thanks!