Thanks for your message.
CancelOrder is called on Order objects and Set methods do not return Order objects. Also considering their function to pep NinjaTrader to submit orders for target/stop upon execution, and their internal behavior to update based on the Calculate mode, I would not suggest assigning a stop loss or profit target order submitted with a Set method to an Order object and attempt to cancel it.
If you want to deliberately cancel a stop loss order or profit target order, I suggest using Exit methods or the Unmanaged Approach and assigning Order objects there and then cancelling those order objects.
An example that demonstrates using Exit methods for target/stop and also demonstrates using Order objects is linked below.
SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm
CancelOrder - https://ninjatrader.com/support/help...ancelorder.htm
Calling ExitLong() or ExitShort() will close the position and cancel active orders. You will need to make sure that no FromEntrySingal string is provided and the Exit method is called for the proper BarsInProgress index to ensure that specific position and the stop loss/profit target tied to that entry are closed. If you specify a FromEntrySignalName, the Exit method will only affect what is tied to that entry signal name.
If you are observing behavior where the Exit method is not closing the position and canceling orders when a blank FromEntrySignal string is provided and the Exit method is submitted to the proper BarsInProgress index, please provide a reduced example that demonstrates the behavior so we can report it.
We look forward to assisting.
Comment