I have set this flag to true IsAdoptAccountPositionAware = true; so that my strategy can check the account to see how much volume of which instrument is being traded.
But now this also means that my OnOrderUpdate OnExecutionUpdate OnPostionUpdate will get invoked for any change to any position or order on the account irrespective if it was this strategy that created it or it was created manually or by some other strategy…
Is there absolutely nothing in ninjascript that can help me identify if the order or execution for which the callback is invoked belongs to this strategy or not.
Or is the only solution here is to have some way of identifying that from the signal name.
It sounds like you’re running into a common challenge when using IsAdoptAccountPositionAware = true. While this property is great for letting your strategy “see” the entire account’s exposure, it does indeed “flood” your update methods with data from manual trades or other strategies.
To separate your strategy’s specific activity from the rest of the account, you can use the following methods:
1. Filter by FromEntrySignal
The most reliable way to identify if an execution or order belongs to your specific strategy instance is to check the Signal Name. Even when adopting account positions, NinjaTrader identifies orders generated by the strategy script.
In OnExecutionUpdate: Check if the execution has a signal name associated with your strategy’s entry logic.
In OnOrderUpdate: Use order.Name to verify if it matches the name you assigned during the EnterLong() or EnterShort() call.
2. Use a Custom Member Variable (Order Objects)
When you submit an order, store it in a variable. Then, in your update methods, compare the incoming order object to your stored object.
private Order myEntryOrder = null;
// When submitting:
myEntryOrder = EnterLong("MySignalName");
// In OnOrderUpdate:
if (order == myEntryOrder)
{
// This order belongs to THIS strategy instance
}
3. Check the Strategy Property
In some contexts, you can check if the object’s strategy reference matches the current instance. However, with IsAdoptAccountPositionAware, manual trades will often have a null or generic strategy reference. You can use this to your advantage:
If execution.Order.FromEntrySignal is empty or the order name doesn’t match your predefined strings, it is likely a manual trade or from another source.
Summary Table: Distinguishing Trades
Data Type
Property to Check
Logic
Orders
order.Name
Match against your signal name string.
Executions
execution.Name
Check if it matches your entry/exit signal names.
Positions
Position.Quantity
Note: Position will reflect the entire account; you must track your “internal” position manually if you need to know only what the strategy bought.