However, when order.Name == "Exit on session close" or order.Name == "Stop loss", I don't see the signal name "fooSignal" in the order object. FromEntrySignal is empty. Is there a different way to correlate these events with an open position, or a way to get the signal name from the order object if it's not in a field?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Correlating order signal name with "Exit on session close" and "Stop loss" executions
Collapse
X
-
Correlating order signal name with "Exit on session close" and "Stop loss" executions
I place an order with EnterLong() and provide signal name "fooSignal", As calls are made to OnExecutionUpdate, most execution.order objects will contain "fooSignal" in either order.FromEntrySignal or order.Name.
However, when order.Name == "Exit on session close" or order.Name == "Stop loss", I don't see the signal name "fooSignal" in the order object. FromEntrySignal is empty. Is there a different way to correlate these events with an open position, or a way to get the signal name from the order object if it's not in a field?
Tags: None
-
Hello pat9rb,
Thanks for your post.
FromEntrySignal strings will only exist in Order objects that were created using an order method overload that includes FromEntrySignal. It would not be possible to get the signal name outside of the order object without having knowledge of how the strategy operates and what positions it may be in.
It would be possible to check for the "Stop loss" order in OnOrderUpdate and then to assign the order object's FromEntrySignal property. When you check the FromEntrySignal property in OnExecutionUpdate(), you should see the string you assigned. You could set a private variable that would hold the current EntrySignal string, and then to assign that string to the "Stop loss" or "Exit on session close" Order object's FromEntrySignal.
My recommendation would be to use the overloads for specifying FromEntrySignal where possible for consistent pairing.
Please let me know if we can be of further assistance.
-
Thanks for your reply. I'm still not clear but I think I may be assuming fromEntrySignal does more than it does.
Regarding: The SetStopLoss() method can NOT be used concurrently with the SetTrailStop() method for the same position, if both methods are called for the same position (fromEntrySignal) the SetStopLoss() will always take precedence. You can however, use both methods in the same strategy if they reference different signal names. (https://ninjatrader.com/support/help...etstoploss.htm)
If I...
Do positions A and B have different stops set or are both set to stopTicksB?Code:_orderA = EnterLong(1,"signalPositionA"); _orderB = EnterLong(1,"signalPositionB"); SetStopLoss("signalPositionA",CalculationMode.Price, stopPriceA); SetStopLoss("signalPositionB",CalculationMode.Ticks, stopTicksB);
Comment
-
Hello pat9rb,
The positions exits are tied to different entries because they have different fromEntrySignals.
As a tip, we would recommend calling Set methods before you submit your entry order when the strategy is flat to ensure that when your entry order comes back, the appropriate profit target and stop loss orders are submitted. An example that demonstrates dynamically using the Set methods can be found here - https://ninjatrader.com/support/help...of_stop_lo.htm
Let me know if you have any other questions that I can answer to help clarify.
Comment
-
Hi Jim-
So if I understand correctly: I am able to have two open positions, signalPositonA and signalPositionB, and dynamically set the stop loss or trail stop for each position independently by using the fromEntrySignal argument to EnterLong() and SetStopLoss()/SetTrailStop(). When a position is exited, OnOrderUpdate() and OnExecutionUpdate() are called. Here is where I'm having trouble. In the order object passed in to OnOrderUpdate() and OnExecutionUpdate(), fromEntrySignal is empty if the order is a "Stop loss" or "Exit on session close". If, for example, I have 5 open positions, and I get 2 stop loss exit orders to OnExecutionUpdate(), how so I find the 2 closed positions from the 5 positions that were open? If I don't mark the correct positions, I may issue additional SetStopLoss and SetTailStop updates for fromEntrySignals that are no longer valid, because those positions have been closed. (For "Exit on session close" I can close all positions, because I know all the positions will be closed, but that's sort of a hack.)
Thanks.
Comment
-
Hello patr9rb,
If you make sure you use order methods that have a fromEntrySignal parameter, your stop loss orders will always be tied to to your entry orders.
"Exit on session close" orders are not tied to entry signals so there will not be a from Entry Signal. You will have to keep track of which position/entry signal that is open and associate it with the Exit on session close on your own.
The Set methods prep NinjaTrader so that when an associated entry order comes back as filled, your profit target/stop loss will be submitted. Calling a Set exit method when the position is flat will not submit additional orders, but set the price levels for next opened position by the associated Entry Signal.
If you assign an Order's FromEntrySignal in OnOrderUpdate() you will see it in OnExecutionUpdate().
For example:
Please let me know if you have any further questions.Code:protected override void OnExecutionUpdate(Cbi.Execution execution, string executionId, double price, int quantity, Cbi.MarketPosition marketPosition, string orderId, DateTime time) { if(execution.Order.Name == "Stop loss") Print(execution.Order.FromEntrySignal); } protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment) { if (order.Name == "Stop loss") order.FromEntrySignal = "MyEntry"; }
Comment
-
Hi Jim-
Looking at your example, doesn't every order that closes with a a Stop Loss get assigned the fromEntrySignal value "MyEntry" regardless of the signal assigned at entry and when the stop loss was set?
For example:
If each of these open positions exits with a stop loss, won't OnExecutionUpdate print:Code:EnterLong("MyEntry"); EnterLong("MyEntry2"); EnterLong("MyEntry3"); EnterLong("MyEntry4");
Code:MyEntry MyEntry MyEntry MyEntry
Comment
-
Hello pat9rd,
Yes, this is what would happen since the FromEntrySignal is deliberately and indiscriminately being applied in OnOrderUpdate without any logic to try and identify a specific order/position that was opened using class level variables. The example is only meant to demonstrate that if you assign a FromEntrySignal in OnOrderUpdate for an order that does not have a FromEntrySignal, then you will see that FromEntrySignal in OnExecutiopnUpdate().
If you only use SetStopLoss with the FromEntrySignal overload, your stop losses will only be created and tied to those specific entries.
Any other way to associate orders would have to come from your own logic to track an open position and associate the position to the (for example) "Exit on session close" order.
If you have any additional questions, please don't hesitate to ask.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
34 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment