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
unmanaged mode / order size problems in own script changeorder
Collapse
X
-
unmanaged mode / order size problems in own script changeorder
Hi, I have my own script, so far so good. if i want to change the order size manually via charttrader, it only works downwards, upwards an additional new order is generated. in the script i query every change of the order in the OnOrderUpdate method. how can i change the existing order size instead of creating a new order?
Tags: None
-
Hello slidercom80,
Thanks for your post.
There is not enough detail provided to understand how your logic is not allowing orders to be changed in the upward direction.
To achieve your goal, I would suggest checking to see which order has changed after your order object assignment and nulling (if order has been cancelled) code in OnOrderUpdate, and then to modify the other order that you have paired with that order.
I have tested the following and I have not had trouble in my test script. I have attached it for your reference.
Code:// Check if entry orders have been modified by user if ((shortEntry != null && longEntry != null) && (order == shortEntry || order == longEntry) && (shortEntry.OrderState == OrderState.Accepted || shortEntry.OrderState == OrderState.Working) && (longEntry.OrderState == OrderState.Accepted || longEntry.OrderState == OrderState.Working)) { if (order.Quantity != shortEntry.Quantity) ChangeOrder(shortEntry, order.Quantity, shortEntry.LimitPrice, shortEntry.StopPrice); // longEntry was changed, update shortEntry else if (order.Quantity != longEntry.Quantity) ChangeOrder(longEntry, order.Quantity, longEntry.LimitPrice, longEntry.StopPrice); // shortEntry was changed, update longEntry }
Attached FilesJimNinjaTrader Customer Service
-
Hi _Jim, thanks for the answer. i found the problem: since i don't use an oco order, the modified existing order couldn't be assigned correctly. i solved it by generating a separate oco id for the stoploss order and the takeprofit order. apparently nt needs an oco order for the assignment, the name of the order to be changed is probably not enough ;-)
Code:if (State == State.Historical) { ocoSL = DateTime.Now.ToString() + CurrentBar + "LongExitsSL"; ocoTP1 = DateTime.Now.ToString() + CurrentBar + "LongExitsTP1"; } else { ocoSL = GetAtmStrategyUniqueId() + "LongExitsSL"; ocoTP1 = GetAtmStrategyUniqueId() + "LongExitsTP1"; }
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by f.saeidi, Today, 07:07 AM
|
6 responses
19 views
0 likes
|
Last Post
by f.saeidi
Today, 03:31 PM
|
||
Started by cmtjoancolmenero, Today, 02:31 PM
|
6 responses
15 views
0 likes
|
Last Post Today, 03:29 PM | ||
Started by Graci117, Yesterday, 11:40 PM
|
5 responses
26 views
0 likes
|
Last Post Today, 03:29 PM | ||
Started by rene69851, Today, 03:25 PM
|
0 responses
3 views
0 likes
|
Last Post
by rene69851
Today, 03:25 PM
|
||
Started by Irukandji, Yesterday, 05:50 AM
|
3 responses
9 views
0 likes
|
Last Post Today, 03:25 PM |
Comment