PDA

View Full Version : NTOrderStatus question


hmmerritt
10-11-2007, 10:00 AM
In an earlier thread touching on a similar topic, it was said:

"You can not retrieve order id values of ATM strategy generated stop/target orders."

Does this also mean that the status of ATM strategy generated stops and targets cannot be acquired through the ATI?

I am trying to determine in a 2 stop 2 target strategy, whether a change of position is due to the target being hit, or the stop being triggered.

Any suggestions on how to do this?

Thanks.

NinjaTrader_Dierk
10-11-2007, 10:06 AM
Correct. However, NT 6.5 will provide a way to
a) get the order IDs of stop/target orders per ATM strategy
b) then call NTOrderStatus for these order IDs

NT 6.5 first beta will be available in ~ 2 weeks.

hmmerritt
10-11-2007, 10:10 AM
Thanks Dierk. I will look forward to v6.5.

arbifox
09-19-2008, 12:29 PM
I am running on 6.5, and I am still not getting back the status of a stop order. I am assigning my stop order its own ID, and then launching a call to NTOrderStatus("my_stop_order_id"). This same call works for my_order_id.

Is there a work around? I just want to make sure that my stop is set.

Thanks again,

Thomas

NinjaTrader_Josh
09-19-2008, 12:38 PM
Use NTStopOrders(string strategyId) to see if you are actually using the right orderId string for the stop.

arbifox
09-19-2008, 12:50 PM
Josh,

This is what I am doing and neither of the calls are returning with data for checking the stop order status:

function main()
{

order_id="1000";

if (isLastBarOnChart() && NTConnected(1))
{
if (!orderPlaced)
{
if (NTBuyMarket("order_id", 1) == 0) // buy 1 unit at market, assign order id (optionally)
orderPlaced = true;
stop_order_id=order_id+1;
NTSellStop(stop_order_id, contract_num, buy_stop_level);

}
else
{
// print some information on the current position and order
debugPrint("Position size: " + NTMarketPosition("") + "\r\n");
debugPrint("AvgEntryPrice: " + NTAvgEntryPrice("") + "\r\n");
debugPrint("OrderStatus: " + NTOrderStatus("order_id") + "\r\n");
debugPrint("StopOrderStatus_1: " + NTOrderStatus("stop_order_id") + "\r\n");
debugPrint("StopOrderStatus_2: " + NTStopOrders("") + "\r\n");
debugPrint("Filled #: " + NTFilled("order_id") + "\r\n");
debugPrint("AvgFillPrice: " + NTAvgFillPrice("order_id") + "\r\n");
debugPrint("RealizedPnL: " + NTRealizedPnL("") + "\r\n");
}
}
}

I see the order accepted in NT, I just can not get the call returned to my EFS.

Let me know what I am missing . . .

T

NinjaTrader_Josh
09-19-2008, 02:11 PM
NTOrderStatus("stop_order_id") is wrong. Your stop_order_id is a string variable. You don't need to use quotes. NTOrderStatus(stop_order_id)

Also, NTStopOrders("") <- you are missing the strategyId.

To get a list of the strategyIds you need to use NTStrategies(string account). Please see this article: http://www.ninjatrader-support.com/HelpGuideV6/Functions1.html

NTStrategies() gets you strategyIds. NTStopOrders() gets you orderIds. NTOrderStatus() gets you the order status.

arbifox
09-19-2008, 02:22 PM
Josh,

I understand the differences between using quotes and not, I was just following the examples that are provided with NT.

Also, if I do not need to use quotes, I just want to let you know the function works perfectly well for:

debugPrint("OrderStatus: " + NTOrderStatus("order_id") + "\r\n");

In my case, I am not using the strategy variable, nor am I using account, so in essence:

1. I need to get the default strategy
2. Pass that in with NTOrderStatus to get the stop order status?

If that is the case, why do I not have to do that with the regular order? Do you think you could just post an example in the same form of NTSample.efs that beginners could follow?

Regards,

Thomas.

NinjaTrader_Josh
09-19-2008, 02:36 PM
Thomas,

The difference between "order_Id" was that that was never a variable. This is why you needed the quotes. When you did NTBuyMarket("order_id", 1) you used quotes so when you call the NTOrderStatus you use quotes also to match up the same order_Id name.

Because you now use NTSellStop(stop_order_id, contract_num, buy_stop_level) with stop_order_id being a string variable as opposed to simply being a string your stop's orderId is NOT "stop_order_id". It is whatever is contained inside that string.

So simply, to get NTOrderStatus() of your stop orders you need to type out the actual string of the stop order. If you did NTOrderStatus(stop_order_id) that will work to get your last stop order, but because you did this earlier stop_order_id=order_id+1; you will now need to decrement it to get your previous stop orders.

In fact, I think you may need to first declare your stop_order_id.
var stop_order_id = "1000";
stop_order_id=order_id+1 <- I don't know what that line will do. When operating on strings the + just concatenates, it doesn't do math. You may be getting strings that look like 10001 or it may be confused by the 1 because thats not another string. stop_order_id = stop_order_id + "1" would work better in getting you unique ids. This way you get strings that look like 1000, 10001, 100011, 1000111.

arbifox
09-19-2008, 03:02 PM
Josh,

I think I am seeing what you are saying.

Change:

if (NTBuyMarket("order_id", 1) == 0)

to

if (NTBuyMarket(order_id, 1) == 0)

And all should work well. I was getting confused between the vars I was passing in and the quotes. I will let you know how my testing goes on Monday. Just let me know if you see any errors below:

function main() {

order_id=1000;

if (isLastBarOnChart() && NTConnected(1)) {
if (!orderPlaced) {
if (NTBuyMarket(order_id, 1) == 0) // buy 1 unit at market, assign order id (optionally)
orderPlaced = true;
stop_order_id=order_id+1;
stop_orderPlaced = true;
NTSellStop(stop_order_id, contract_num, buy_stop_level);
}
else {
// print some information on the current position and order
debugPrint("Position size: " + NTMarketPosition("") + "\r\n");
debugPrint("AvgEntryPrice: " + NTAvgEntryPrice("") + "\r\n");
debugPrint("OrderStatus: " + NTOrderStatus(order_id) + "\r\n");
debugPrint("StopOrderStatus: " + NTOrderStatus(stop_order_id) + "\r\n");
debugPrint("Filled #: " + NTFilled(order_id) + "\r\n");
debugPrint("AvgFillPrice: " + NTAvgFillPrice(order_id) + "\r\n");
debugPrint("RealizedPnL: " + NTRealizedPnL("") + "\r\n");
}
}
}

I assume even if my order_id's are INT in efs, they are treated as strings by the calls.

Regards,

Thomas.

NinjaTrader_Josh
09-19-2008, 03:09 PM
If your assumption is right (I do not know exactly) then you should be fine.

arbifox
09-22-2008, 12:43 PM
Josh,

Thanks for your help, got it working. I have just one question that is confusing between your documentation and what I am seeing in testing.

Once the stop order is sent, it shows in NT as "Accepted" (Order confirmation received by broker). Would this status ever change to "Working" (Order confirmation received by exchange)?

I just need to know which states to code for.

Thanks again,

Thomas.

NinjaTrader_Ray
09-22-2008, 12:47 PM
Which broker are you using?

arbifox
09-22-2008, 02:45 PM
IB is the broker, but I think the other state is for when you place a limit order, and not stop limit.

T

NinjaTrader_Ray
09-22-2008, 02:56 PM
With IB, Accepted means that its on their servers, usually stop orders. I believe you will get a working state once the order is triggered.

tiara50
10-23-2009, 08:00 AM
Hello,

What would be the initial state of an order?
NTOrderStatus(OrderID) = ""

I have a script that checks the status of an order and trying to determine what value it should find when an order has not even been placed yet.

Thanks

NinjaTrader_Josh
10-23-2009, 08:24 AM
If an order has not even been placed yet how would you have the OrderID?

tiara50
10-23-2009, 08:34 AM
Hello,

I set the Order ID within the code. My signal can change quickly, so I will not fire a new order until I get a confirmed cancel or filled in a previous trade, but to fire the initial order it is neither cancelled or filled yet. My condition is to fire an order only if the state is null, cancelled or filled; null only being the beginning of the day.

Thanks

NinjaTrader_Bertrand
10-23-2009, 08:45 AM
You can check all potential states here - http://www.ninjatrader-support.com/HelpGuideV6/IOrder.html

First thing you would see it being in PendingSubmit while going in accepted / working status.

sigworks
12-09-2010, 01:57 AM
Hello,

i use orderrouting from tradestation through Ninjatrader to Patsystems. Almost all works well. However, ninjatrader lost the orderstatus for overnight-positions. At startting a position orderstate is filled. Next day the getting orderstatus is "". Why?

Thanks.

sigworks

NinjaTrader_Josh
12-09-2010, 08:02 AM
sigworks,

What version of NT? Are you shutting NT down?

sigworks
12-16-2010, 01:46 AM
sigworks,

What version of NT? Are you shutting NT down?

Hello,

yes I'm shutting down NT. OrderStatus will be safed locally? Is it lost, when I restart NT?
I use NT 7.

Thank you.

NinjaTrader_Josh
12-16-2010, 08:24 AM
sigworks,

As you connect, NT reads position updates from your brokerage. Whatever comes across the wire when you read them is what will be displayed for those orders. For the most part, if your brokerage has a working order, it will always report that as working.

sigworks
12-16-2010, 08:45 AM
sigworks,

As you connect, NT reads position updates from your brokerage. Whatever comes across the wire when you read them is what will be displayed for those orders. For the most part, if your brokerage has a working order, it will always report that as working.

Josh, maybe for working orders. I have an issue with opened positions, when I start NT next day, I can not determine the orderstatus of the opened position. The Function NTOrderStatus(String OrderID) returns "0". When I restart NT at the same day where the position opened, then NTOrderStatus(String OrderId) returns the correct status.

Is this issued by my brokerage?

Thanks.

NinjaTrader_Josh
12-16-2010, 10:08 AM
sigworks,

I guess I am not following. If you already opened the position, the order's state is Filled because that's how you opened the position. Guess I am not sure which order you are trying to look for exactly? Thanks.

sigworks
12-16-2010, 10:15 AM
Hi Josh,
right, but I do some processes with the orderstatus. When I got not "filled" with an opened position, so this processes are not working. How could I determine the NTOrderStatus for this opened position next day after restart NT?

Thanks.

NinjaTrader_Josh
12-16-2010, 10:51 AM
sigworks,

Unfortunately I am still not following you. Your order is definitely filled if it opened a position. Only other possibility is a partial fill.

NTOrderStatus does not run on positions, it runs on orders.

sigworks
12-16-2010, 11:08 AM
Ok. I understand, but it is a little inconsistent for me, because the OrderId of the running position is existent until the position is closed (at the same day). The OrderStatus of this OrderId is "filled" until it comes overnight. Next day this is empty.
The Status of this ID could be generally deleted after the position will be closed, I think. Little confused

Thanks.

sigworks

NinjaTrader_Josh
12-16-2010, 11:20 AM
sigworks,

Sounds to me you are using some external application to try and read the OrderState of the same OrderID you had prior to shutting down NT. This OrderID may or may not be the same.

Have you considered using NTOrders() to get a list of all the orderIDs? What does it show you then? What do you get when you run NTOrderStatus() off those IDs?