Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Pairs trading issue
Collapse
X
-
Pairs trading issue
I have a strategy that is doing pairs trading. When running in NinjaTrader's sim, everything works properly. However when I run in IB simulation, I get an error message "cannot modify filled order". Anyone know why this might be happening?Tags: None
-
Hi SystemTrading,
Please check your order state before attempting to modify any orders.
If the order reports as filled, then there's nothing NinjaTrader can do to modify it.
Please review this link here - http://www.ninjatrader-support.com/H...derUpdate.html
-
I do. Below is my code. I added this check because I was having the problem in NinjaTrader before I started testing in IB. Now I am only having the problem on IB's sim. My only thought is I am sending 6 orders pretty rapidly, 3 orders on each instrument. Do you think this could cause my problem?
Code:if (SE==null || SE.OrderState!=OrderState.Filled) SE=EnterShortLimit(....);
Comment
-
So you are saying these 3 orders are essentially 1 order placement and 2 rapid order modifications? Where are you submitting the order modifications from? If you are outside of the OnOrderUpdate() method you can run into race conditions where the order has already been filled even though you just checked for it to be != filled. This can easily happen if your modification order is happening in OnBarUpdate() since things are multi-threaded.Josh P.NinjaTrader Customer Service
Comment
-
No basically I send 1 order for each side of the pair, ie. buy instrument #1 and sell instrument #2. In the OnExecution() method, I verify that both #1 and #2 have been filled, then trigger another entry to be allowed. This happens for a total of 3 entries.
Comment
-
Here is what I do OnExecution(). Basically I have LE1 and LE2, which is long entry on instrument 1 and instrument 2, along with SE1 and SE2. Therefore LE1 corresponds with SE2 and vice versa. dp is a variable I use for "destination position". So what I am trying to accomplish here is when both sides are filled, I increment the destination position so I know to place another trade when OnBarUpdate is processed. Hopefully this helps. Let me know if you need more.
Code:protected override void OnExecution(IExecution execution) { if (LE1!=null && execution.Order.Token == LE1.Token) if (SE2!=null && SE2.OrderState==OrderState.Filled) { if (dp==0) dp=1; LE1=null; SE2=null; dp++; } if (LE2!=null && execution.Order.Token == LE2.Token) if (SE1!=null && SE1.OrderState==OrderState.Filled) { if (dp==0) dp=-1; LE2=null; SE1=null; dp--; } if (SE1!=null && execution.Order.Token == SE1.Token) if (LE2!=null && LE2.OrderState==OrderState.Filled) { if (dp==0) dp=-1; SE1=null; LE2=null; dp--; } if (SE2!=null && execution.Order.Token == SE2.Token) if (LE1!=null && LE1.OrderState==OrderState.Filled) { if (dp==0) dp=1; LE1=null; SE2=null; dp++; } if (LX1!=null && execution.Order.Token == LX1.Token) if (SX2!=null && SX2.OrderState==OrderState.Filled) { LX1=null; SX2=null; dp--; } if (LX2!=null && execution.Order.Token == LX2.Token) if (SX1!=null && SX1.OrderState==OrderState.Filled) { LX2=null; SX1=null; dp++; } if (SX1!=null && execution.Order.Token == SX1.Token) if (LX2!=null && LX2.OrderState==OrderState.Filled) { SX1=null; LX2=null; dp++; } if (SX2!=null && execution.Order.Token == SX2.Token) if (LX1!=null && LX1.OrderState==OrderState.Filled) { LX1=null; SX2=null; dp--; } }
Comment
-
SystemTrading,
I need to see everything from start to finish in terms of order placement logic. Please strip out all trade condition logic that is not essential to the orders. Just show me the core where all orders are being placed from. I need to see all the EnterLong()s and all the EnterShort()s. Thank you.Josh P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
553 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
324 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
100 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
543 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
546 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment