![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jun 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
I am having problems with cancelling and atm strategy limit order. When it is time to place the limit order, this is my code for it:
orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, limitLevel, 0, TimeInForce.Gtc, GetAtmStrategyUniqueId(), atmName, orderId); limitCloseBars = CurrentBars[1] + unfilledBars; then after x amount of bars if the order isn't filled, I try to close it using this code: if(CurrentBars[1] >= limitCloseBars) { closeEntry = true; } if(closeEntry == true) { // string[] entryInfo = GetAtmStrategyEntryOrderStatus(orderId); // if(entryInfo.Length > 0 && entryInfo[2] != "Filled") // { AtmStrategyCancelEntryOrder(orderId); // } closeEntry = false; } if i delete the // then AtmStrategyCancelEntryOrder(orderId); is never called. Even with the code like this my order isn't cancelled. I even put AtmStrategyCancelEntryOrder(orderId); as the first line of code under OnBarUpdate and it still would not cancel the order. What am I doing wrong? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
laces2, if the AtmStrategyCancelEntryOrder() method isn't called, that means the conditions for the method to be called are not being met. Is the entryInfo.Length longer than zero, and you're sure the order hasn't been filled?
Austin
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jun 2010
Posts: 18
Thanks: 0
Thanked 0 times in 0 posts
|
That is why I have it commented out. To make sure that it was being called I had it draw dots on the chart. I even at one point put the
AtmStrategyCancelEntryOrder(orderId); as the very first thing in my strategy to make sure that it was called and still nothing. I know the order wasn't filled because I could see it on another chart, and it was in the working state in the control panel. The only time orderId is changed is right before a new order or trade is placed so I know that I am trying to cancel the right order. I am going to try to make a simple strategy today to see if I can get it to work. |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hello laces2,
You'll want to work from the SampleAtmStrategy. You can save a copy by right clicking > Save As from within the editor. Cancelling an entry order would take place in this block: Code:
// Check for a pending entry order
if (orderId.Length > 0)
{
string[] status = GetAtmStrategyEntryOrderStatus(orderId);
// If the status call can't find the order specified, the return array length will be zero otherwise it will hold elements
if (status.GetLength(0) > 0)
{
// Print out some information about the order to the output window
if(closeEntry == true)
{
AtmStrategyCancelEntryOrder(orderId);
closeEntry = false;
}
Print("The entry order average fill price is: " + status[0]);
Print("The entry order filled amount is: " + status[1]);
Print("The entry order order state is: " + status[2]);
// If the order state is terminal, reset the order id value
if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
orderId = string.Empty;
}
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| ATM Request -- auto-cancel unfilled Limit Orders | Turtle Trader | ATM Strategies (Discretionary Trading) | 1 | 12-08-2010 02:19 PM |
| Cancel Order on ATM Strategy | jthom | Automated Trading | 70 | 09-09-2010 04:59 AM |
| limit order on IB, how about ATM strategy | asalada | Miscellaneous Support | 5 | 12-31-2008 06:36 AM |
| Multiple Limit Orders in a single ATM Strategy Order? | Acapulco | ATM Strategies (Discretionary Trading) | 1 | 06-19-2008 05:31 AM |
| Cancel and replace a limit order with invoked ATM | daven | Strategy Development | 1 | 05-07-2008 10:10 AM |