Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
How to get order status
Collapse
X
-
How to get order status
Hello, I'm in the middle of developing my strategy and I got stuck at the part where I need to close all orders on opposite signal. Orders could be in pending stage or already triggered, and I'm using multiple orders with different TPs. Is there a way to query an order to see whether it exists or not ? i.e. if its on the market or it hasn't been triggered yet ? Because as soon as stop order on market it get Filled OrderState, and if TP hits for that order its the same state. So depending on whether it was triggered or not I need to use cancel order function or exitlong for example please correct me if I'm wrong. Anyone can suggest please on this topic anything ? maybe some sample of the code where there is some decision making login based on if the order was triggered or not ?or some logic to close all long orders (pending and currently running ones).Tags: None
-
Hello vitaliys,
Welcome to our forum and I am happy to assist you.
While submitting the order you can add an IOrder object to it and check it later on for the order state
Code:IOrder order = EnterLongLimit(limitPrice);
Code:if (order.OrderState != OrderState.Filled) { //do something }
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
-
Thank you for your reply. I was trying to use iOrder object, but i'm getting stuck on the part where OrderState.Filled is true. So my order entered market and its currently open lets say the second order in same direction (buy stop) is not triggered yet, (i have two iOrder objects). To close both of those orders I need to apply ExitLong to the first order and CancelOrder to the second one right ? So if I have the third order which reached TP and has been closed it will have OrderState.Filled state untill I clear iOrder object. So at the point where one order has reached TP and closed and second still working they both will have OrderState.Filled. How can I distinguish between currently open and running order vs the one that hit TP ? Lets say I need to close 3 orders (1-pending buy stop, 2- currently active market order, 3 - Order that reached TP and requires iOrder object to be nulled )?
P.S. I null iOrder objects in execution function if orderstate.Filled or cancelled. But then I can't refer to open order to close it.Last edited by vitaliys; 04-27-2012, 11:08 AM.
Comment
-
Sorry for little messy explanation, third order is buystop order which has been triggered and hit TP so its a closed order. so it looks like this:
1) Order1 - buystop - pending to be triggered
2) Order2 - buystop - that has been triggered and currently open
3) Order3 - buystop - TP was hit and order closed.
so basically I need to cancel first order & null iOrder, exit second order & null iOrder, and null iOrder third one.
Comment
-
Hello vitaliys,
Thanks for the clarification.
I will use unique names for the entry and exit codes and will nullify the objects in the OnExecution event when the exit order gets filled.
for example, if the entry is defined by
Code:IOrder long3 = EnterLong("long3")
Code:ExitLong("exitlong3", "long3")
Code:protected override void OnExecution(IExecution execution) { if (execution.Order != null && execution.Order.Name == "exitlong3" && execution.order.OrderState == OrderState.Filled) { long3 = null; } }
http://www.ninjatrader.com/support/helpGuides/nt7/index.html?onexecution.htm
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
Hello vitaliys,
Please use the below overload for the target orders
http://www.ninjatrader.com/support/helpGuides/nt7/index.html?setprofittarget.htmSetProfitTarget(stringfromEntrySignal, CalculationModemode, doublevalue)
Now you can monitor the targets in the OnExecution event.
Code:if (execution.Order != null && execution.Order.Name = "Profit target" && execution.Order.FromEntrySignal = "long3" && execution.Order.OrderState == Filled) { //do something }
Please let me know if I can assist you any further.
JoydeepNinjaTrader Customer Service
Comment
-
Hello Joydeep,
I got now confused by the use of SetProfitTarget by you.
SetProfitTarget(stringfromEntrySignal, CalculationModemode, doublevalue)
stringfromEntrySignal - argument would be the be signal Name that would be assigned to the entry unique name right ? so how would I refer to that target price or SL in OnExecution function ?
My entry code is:
Order1 = EnterLongStop(0,true,LotSize1, ePrice, "Order1");
Order2 = EnterLongStop(0,true,LotSize2, ePrice, "Order2");
Order3 = EnterLongStop(0,true,LotSize3, ePrice, "Order3");
so each order has its own Signal name,
then there is
protected override void OnExecution(IExecution execution)
{
if(Order1!=null && Order1.OrderState == OrderState.Filled)
{
//***********************TARGET PRICE FOR ORDER1*****************************
if (tpType == 1 || tpType == 0)
{
SetProfitTarget("Order1", CalculationMode.Ticks, TP1); // I Assign TP for Order1, I do almost same same for the next two orders based on different conditions
}
// I add the following code to clear Order1,2,3 objects after TP is hit
if (execution.Order != null && execution.Order.Name == "Profit target" && execution.Order.FromEntrySignal == "Order1" && execution.Order.OrderState == OrderState.Filled)
{
Print ("Order1 hit TP and iOrder was nulled");
Order1 = null;
}
if (execution.Order != null && execution.Order.Name == "Profit target" && execution.Order.FromEntrySignal == "Order2" && execution.Order.OrderState == OrderState.Filled)
{
Print ("Order2 hit TP and iOrder was nulled");
Order2 = null;
}
if (execution.Order != null && execution.Order.Name == "Profit target" && execution.Order.FromEntrySignal == "Order3" && execution.Order.OrderState == OrderState.Filled)
{
Print ("Order3 hit TP and iOrder was nulled");
Order3 = null;
}
}
But execution.Order.Name is always either Sell or Order1,2,3. So there is some error in how do I attach TP(assuming all orders might have different entry price) to the order itself could you please clarify this part or let me know if you need all my code (it kind of lengthy and messy so I got only relevant code in here).Last edited by vitaliys; 04-29-2012, 08:56 PM.
Comment
-
Hello vitaliys,
An order submitted via SetProfitTarget() will have a name of "Profit target".
Please refer to this sample code for more details http://ninjatrader.com/support/forum...ead.php?t=5790
Since you are submitting the target orders in the OnExecution event, and it is filtered by more conditions please make sure your target orders are being placed.
You can also add the code TraceOrders in the Initialize section of the strategy to find out which order is getting filled etc
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
Hello vitaliys,
You have already done so via the code
Code:if (execution.Order != null && execution.Order.Name == "Profit target" && execution.Order.FromEntrySignal == "Order1" && execution.Order.OrderState == OrderState.Filled)
Further you code filters like
Code:if(Order1!=null && Order1.OrderState == OrderState.Filled)
Please remove that filter or make case-by case filter for each order.
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
Thank your for clarifying that, so TP is not attached to the entry order directly but through the entry price. If I resubmit SetTargetPrice with same name but different TP price, will it move TP or create a new one ? Also is there a good logic to deal with Partial Fills ? As I understand order with partial fill may not get filled completely at all so it creates a little bit tricky conditions.
Comment
-
Hello,
Yes, if you reassign the SetProfitTarget() then it will change the target price for that particular order.
You have to custom code any part filled logic. It depends entirely on you how you want to handle such situations.
You may also like to look into this sample coded http://ninjatrader.com/support/forum...ead.php?t=7499
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
Thanks a lot! I have looked at the sample of the code that you provided and got a few question, what is the difference between SetStopLoss and ExitLongStop for example in terms of how the order will be closed? I understand that those two functions have slightly different properties in it but result looks the same. Also second question is I set my stop loss as
SetStopLoss("Order1", CalculationMode.Ticks, slSize, false);
Will the SetStopLoss stay at the same level of entry after entry signal "Order1" order is closed ? Do i have to reset the SetStopLoss function every time to avoid lets say stop loss being higher then TP situations ? if that's the case can ExitLongStop for example be used as a SL and what is the pros and concerns of using ExitLongStop instead on SetStopLoss function ?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by cre8able, Today, 01:16 PM
|
1 response
8 views
0 likes
|
Last Post Today, 01:30 PM | ||
Started by chbruno, 04-24-2024, 04:10 PM
|
3 responses
48 views
0 likes
|
Last Post Today, 01:29 PM | ||
Started by samish18, Today, 01:01 PM
|
1 response
6 views
0 likes
|
Last Post Today, 01:25 PM | ||
Started by WHICKED, Today, 12:56 PM
|
1 response
8 views
0 likes
|
Last Post Today, 01:17 PM | ||
Started by WHICKED, Today, 12:45 PM
|
1 response
11 views
0 likes
|
Last Post Today, 01:08 PM |
Comment