I am trying to understand the sync account position behaviour and therefore I have written a simple sample strategy that I use for testing:
This testorders strategy does open a long position and a simple stop loss order is set. In a second step this stop order is modified every 10 seconds (just for the sake of having the strategy do something)
NinjaTrader Control Center is set up under options
-> strategies->NinjaScript->Cancel entry Order... IS UNCHECKED
...................................-> Cancel exit Order .. IS UNCHECKED
This means that positions and orders remain active even if the strategy is disabled.
This all works fine, and the TestOrders strategy once enabled enters 1 long position and sets a stop loss order.
Position and Order are maintained even after disabling the strategy.
This is fine and corresponds for what I want in an overnight position, for example 6E or ES.
Then I reenable the strategy (SyncAccountPosition ==true)and something strange happens:
The stop loss order is cancelled the very moment the strategy was enabled!
Here my questions:
1. Is it expected behaviour that the Stop loss order is cancelled at the re- enable of the strategy?
2. Minor bug: I set ES 03-10 as the default Instrument for the Strategy, but all the time the default comes back as FGBL 03-10. So it seems that set default for Instrument does not work.
3. I expected to recover my Stop Loss order by the code
Account.Orders.FindByToken(stoptoken)
The stop loss order is found, but the status is cancelled, so it is not useable any more (or is it possible to reenable a cancelled order?)
If (1. is expected behaviour, does this mean that I have to create a new Stop Loss order in order to have SetStopLoss(...) be sync'ed to my position?
Thank you for your time and please try to answer slow, but looking deep into it.
Thank you
Andreas
Then I disable the strategy and all
Further the strategy
Comment