Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Placing orders to inverse current position
Collapse
X
-
Hello marticora,
Please see my response at the following link: http://ninjatrader.com/support/forum...637#post463637
-
Stop Order with OnExecution
Hallo, in this thread at #4 there is a reply stating that a position can be reversed placing an order with OnExecution. I am trying to do so, but it does not work.
When a Long order is triggered by the strategy, no other order working, I want to place a reversal EnterShortStop order with OnExecution if the price falls below a certain limit. Unfortunately this does not work as the close order is kept alive while the sell order is immediately canceled automatically (see below the code).
If I place the reversal in OnBarUpdate it works fine, but this is not my intention. How could I fix the issue? Should I rather use OnOrderUpdate or something else?
Thank you
protectedoverridevoid OnExecution(IExecution execution)
{
if (execution.Order != null && execution.Order.OrderState == OrderState.Filled && Position.MarketPosition == MarketPosition.Long)
{
entryshort = EnterShortStop(1, MIN(Low, 5)[0]);
}
}
Leave a comment:
-
The closing order is sent first, so this will be the first execution reported. It would be extremely rare that the reversal order is not filled at the same time. Yes, your position would be flat in the event only one order for your reversals is filled.
Leave a comment:
-
What would happen if the reversing order gets filled, but the closing one does not? Will there be a mix up of tags? Will Position.MarketPosition be flat?The enter methods in managed approach take care of reversal logic, but is done with two transactions as you're seeing there.
Leave a comment:
-
The enter methods in managed approach take care of reversal logic, but is done with two transactions as you're seeing there. It works this way in both sim and live. Only when using an unmanaged strategy could you custom code your own reversal handling that submits it in only one order.NT will just send one order with quantity set to 2, right?
In case of a partial fill, will NT first mark the 'Close Position' order as filled?
This would not be considered a partial fill. Both close position order and the reversal order is quantity 1, so they cannot be filled less than that.
This is not a feature of managed approach necessarily, but the default behavior of orders unless you specify liveUntilCancelled = true using the advanced overload for orders.Using the managed approach as above, will both orders (close, reverse) be cancled at the next bar if they were not filled? What happens in case of a partial fill?
Yes, you can use this approach. It will not change the mechanics of reversal - that they are made with two separate orders. The sample offers a way of capturing the filled events from orders so that you can submit protective orders as soon as possible.Can I use this methods to reverse position in OnExecution(), as described here?
Leave a comment:
-
Thanks Ryan,
I've build the following test code, and it works fine:
I've noticed that the 'Reverse' orders generated two actual limit orders - one tagged 'Close Position' (which I guess is auto-generated by NT), and one tagged 'ReverseShort' / 'ReverseLong', as specified by me.Code:protected override void OnBarUpdate() { if (CurrentBar < 20) return; if (Position.MarketPosition == MarketPosition.Flat) { longOrder = EnterLongLimit(Close[0] - 2 * TickSize, "EnterLong"); } else if (Position.MarketPosition == MarketPosition.Long) { shortOrder = EnterShortLimit(longOrder.AvgFillPrice + 5 * TickSize, "ReverseShort"); } else { // Position.MarketPosition == MarketPosition.Short longOrder = EnterLongLimit(shortOrder.AvgFillPrice - 5 * TickSize, "ReverseLong"); } }
My question is what happens in real time:- NT will just send one order with quantity set to 2, right?
- In case of a partial fill, will NT first mark the 'Close Position' order as filled?
- Using the managed approach as above, will both orders (close, reverse) be cancled at the next bar if they were not filled? What happens in case of a partial fill?
- Can I use this methods to reverse position in OnExecution(), as described here?
Thanks,
Boaz
Leave a comment:
-
Hi Boaz,
Yes, all enter methods with the manage approach will reverse your position. EnterShort() is one example:
Leave a comment:
-
Placing orders to inverse current position
How do I place an order that will inverse the current position? For example, the strategy is Long 1, and by some signal I want to sell 2 contracts to change the position to Short 1.
Can this be achieved using the managed approach?
Is there some sample code for this?
Thanks,
BoazTags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
152 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
87 views
1 like
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
131 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
127 views
1 like
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
106 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Leave a comment: