I looked through the OrderState properties but do not see one that corresponds to having "filled and exited at the limit price."
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to check IOrder object to see if a trade exited or not?
Collapse
X
-
How to check IOrder object to see if a trade exited or not?
I have an IOrder object and would like to make sure that the trade exited at the limit price (my strategy has multiple entries & exits).
I looked through the OrderState properties but do not see one that corresponds to having "filled and exited at the limit price." -
Hi texasnomad,
You could do something like...
if (order.OrderState == OrderState.Filled && entryOrder.AvgFillPrice == tryOrder.LimitPrice)
But since this is a limit order, the price is guaranteed.Last edited by NinjaTrader_Tim; 07-22-2010, 12:42 PM.TimNinjaTrader Customer Service
-
Tim,Originally posted by NinjaTrader_Tim View PostHi texasnomad,
You could do something like...
if (order.OrderState == OrderState.Filled && entryOrder.AvgFillPrice == tryOrder.AvgFillPrice.LimitPrice)
But since this is a limit order, the price is guaranteed.
I don't understand why you used 3 different object names; order, entryOrder and tryOrder
At the time I place the trade, my code is:
g1 = EnterLongStopLimit(Lots1, currentLimitPrice, "LongG1");
Do I need to track the status of g1 with other IOrder objects? If so, how and when?Last edited by texasnomad; 07-22-2010, 11:30 AM.
Comment
-
Hi texasnomad,
My apologies for the typos, should be "entryOrder"
If you want to create an IOrder and access information, you can set up the order as in at this page:
Code:private IOrder entryOrder = null; protected override void OnBarUpdate() { if (entryOrder == null && Close[0] > Open[0]) entryOrder = EnterLong(); }TimNinjaTrader Customer Service
Comment
-
OK, I stumbled across OnPositionUpdate, which is half the battle. Initially, my problems was that all 3 order groups execute simultaneously. Because OnPositionUpdate keeps getting called, G3 enters and then immediately attempted to update the stops. I resolved it by refusing to update until G3 finishes entering and my total market units matches what I expect.Code:protected override void OnPositionUpdate(IPosition position) { if( position.Quantity == Lots2 + Lots3 && g3.OrderState == OrderState.Filled ) { /*if( position.MarketPosition == MarketPosition.Long ) { SetStopLoss("LongG2", CalculationMode.Price, g2.AvgFillPrice + 0.5 * atr, false); SetStopLoss("LongG3", CalculationMode.Price, g3.AvgFillPrice + 0.5 * atr, false); }*/ if( position.MarketPosition == MarketPosition.Short ) { SetStopLoss("ShortG2", CalculationMode.Price, g2.AvgFillPrice - 0.5 * atr, false); SetStopLoss("ShortG3", CalculationMode.Price, g3.AvgFillPrice - 0.5 * atr, false); } } //Print("Position changed at " + Time[0].ToString() + ". Total lots: " + Position.Quantity); }
That said, I'm still curious how I can know if g1 is an open or closed trade...
Comment
-
Tim,Originally posted by NinjaTrader_Tim View PostHi texasnomad,
My apologies for the typos, should be "entryOrder"
If you want to create an IOrder and access information, you can set up the order as in at this page:
Code:private IOrder entryOrder = null; protected override void OnBarUpdate() { if (entryOrder == null && Close[0] > Open[0]) entryOrder = EnterLong(); }
I just saw your latest post. I tried replacing
if( position.Quantity == Lots2 + Lots3 && g3.OrderState == OrderState.Filled ) {
with
if( g1.OrderState == OrderState.Filled && g1.AvgFillPrice == g1.AvgFillPrice.LimitPrice ) {
but g1.AvgFillPrice.LimitPrice is not recognized as a valid property of AvgFillPrice. Did you intend to say:
g1.AvgFillPrice == g1.LimitPrice ?
Also, do g1's properties update even after I create the object with EnterShortStopLimit()?Last edited by texasnomad; 07-22-2010, 12:45 PM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
647 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment