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
Matching multiple unmanaged entry orders with their corresponding exit orders
Collapse
X
-
Matching multiple unmanaged entry orders with their corresponding exit orders
I have a strategy that may create more than one entry order at a time. When an entry order fills... how can I create exit orders that are related to that particular entry order. The reason is that I would like the profit and loss lines (and statistics) to reflect each position appropriately.Tags: None
-
Hello BrianARice,
This would need to be done with logic when using the unmanaged approach.
Orders are first in first out.
To provide an idea, your logic could track if an <order>.Name has filled in an entry and set a value to a variable to know this order makes up some of the position. Then you could check that variable to see that value and place an exit order and then remove that value from the variable.Chelsea B.NinjaTrader Customer Service
-
Right... but there is no way to get the profit and loss lines to match up with the proper entry and exit orders on a chart then?
Comment
-
Hi, are there any update in this topic? Is there a way to close the order we need in an unmanaged method? Also, Can you please tell me, I found a method in StrategyBase class
[MethodImpl( MethodImplOptions.NoInlining )
private Order SubmitOrderNow( int selectedBarsInProgress, bool isLiveUntilCancelled, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal, string oco, bool isSimulatedStop )
{
return null;
}
This looks like what I'm looking for, this method has a string argument fromEntrySignal that would help me close the open position I want.Last edited by AdvancedSoftwareFeatures; 04-01-2023, 03:36 AM.
Comment
-
Originally posted by BrianARice View PostI have a strategy that may create more than one entry order at a time. When an entry order fills... how can I create exit orders that are related to that particular entry order. The reason is that I would like the profit and loss lines (and statistics) to reflect each position appropriately.
For entry orders, I use a simple naming scheme. I typically use names that start with a prefix
of 'L' or 'S' (to indicate a Long or Short) followed by a counter, such as CurrentBar.
For example,
L3267 <-- Long entry order at bar 3267
When the entry order fills, I submit matching exit orders (aka, the stop loss and profit target orders)
using the entry order's signalName, but add a suffix, like this,
L3267stp <-- stop loss order
L3267tgt <-- profit target order
If the entry order had Quantity > 1, then the strategy might submit multiple profit target orders, in
which case I numbered them,
L3267stp <-- stop loss order (always the same)
L3267tg1 <-- 1st profit target
L3267tg2 <-- 2nd profit target
...
L3267tg6 <-- 6th profit target (as needed)
The strategy should create the exit orders inside OnOrderUpdate or OnExecutionUpfdate, when
the entry order L3267 state has changed to Filled (or PartFilled).
Is this kind of naming convention what you're talking about?Last edited by bltdavid; 04-01-2023, 07:27 PM.
Comment
-
Originally posted by AdvancedSoftwareFeatures View PostHi, are there any update in this topic? Is there a way to close the order we need in an unmanaged method? Also, Can you please tell me, I found a method in StrategyBase class
[MethodImpl( MethodImplOptions.NoInlining )
private Order SubmitOrderNow( int selectedBarsInProgress, bool isLiveUntilCancelled, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string signalName, string fromEntrySignal, string oco, bool isSimulatedStop )
{
return null;
}
This looks like what I'm looking for, this method has a string argument fromEntrySignal that would help me close the open position I want.
Comment
-
Hello bltdavid,
There is no fromEntrySignal when using the unmanaged approach. In the managed approach, using the fromEntrySignal in an exit will attach the exit order to the signalName of a specific entry order. This will be use used for the pairing of the orders in the performance window. The unmanaged approach does not have this ability to attach exits to specific entries. The matching in the performance window will be purely first in first out. This means the developer would have to make their own report that matches these differently based on signal names and not based on first in first out.
AdvancedSoftwareFeatures,
You can assign orders to variables in OnOrderUpdate() and know which orders are still working and which orders have filled and add up the quantities. When an entry order fills, you can submit a specific exit order with the quantity of that entry.
You also have access the Position.MarketPosition and Position.Quantity, which update when the position changes in OnPositionUpdate().Chelsea B.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_ChelseaB View PostHello bltdavid,
There is no fromEntrySignal when using the unmanaged approach. In the managed approach, using the fromEntrySignal in an exit will attach the exit order to the signalName of a specific entry order. This will be use used for the pairing of the orders in the performance window. The unmanaged approach does not have this ability to attach exits to specific entries. The matching in the performance window will be purely first in first out. This means the developer would have to make their own report that matches these differently based on signal names and not based on first in first out.
AdvancedSoftwareFeatures,
You can assign orders to variables in OnOrderUpdate() and know which orders are still working and which orders have filled and add up the quantities. When an entry order fills, you can submit a specific exit order with the quantity of that entry.
You also have access the Position.MarketPosition and Position.Quantity, which update when the position changes in OnPositionUpdate().
Comment
-
AdvancedSoftwareFeatures The SubmitOrderUnmanaged() method allows specification of a signalName ("A string representing the name of the order. Max 50 characters.").
By tracking individual Orders as recommended by NinjaTrader_ChelseaB with signal names, and using a naming convention for your Orders that allows you to distinguish each one and know it as an entry or exit Order, you should be able to manage this quite well.
Thanks.
Comment
-
Originally posted by jeronymite View PostAdvancedSoftwareFeatures The SubmitOrderUnmanaged() method allows specification of a signalName ("A string representing the name of the order. Max 50 characters.").
By tracking individual Orders as recommended by NinjaTrader_ChelseaB with signal names, and using a naming convention for your Orders that allows you to distinguish each one and know it as an entry or exit Order, you should be able to manage this quite well.
Thanks.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by EnveousColnago, Today, 05:35 AM
|
2 responses
20 views
0 likes
|
Last Post
![]()
by bltdavid
Today, 03:48 PM
|
||
Started by rafaelcoisa, Today, 02:20 PM
|
0 responses
9 views
0 likes
|
Last Post
![]()
by rafaelcoisa
Today, 02:20 PM
|
||
Indicator doesn't show up and no data in the data box are showing under the indicator
by christopher512
Started by christopher512, Today, 02:05 PM
|
0 responses
12 views
0 likes
|
Last Post
![]() |
||
Started by Auchlow, Yesterday, 05:49 AM
|
3 responses
36 views
1 like
|
Last Post
![]()
by sidlercom80
Today, 12:46 PM
|
||
Started by dp8282, Yesterday, 05:05 PM
|
2 responses
28 views
0 likes
|
Last Post
![]()
by dp8282
Today, 08:49 AM
|
Comment