I've been testing AdoptAccountPosition so that a strategy can recover from a stoppage.
When the strategy is stopped, it leaves a position in the account and working orders in the account. That's ok - the intention is that AdoptAccountPosition will be able to recover from this.
AdoptAccountPosition fails in this scenario.
It is only if no orders are active in the Account that AdoptAccountPosition successfully creates a virtual execution and gets the strategy in sync.
Note that these orders I am talking about here are from the strategy itself. Other orders (such as those manually placed) create a warning that the strategy cannot be started. I'm fine with that, but I do want the strategy to successfully sync when its own orders from earlier are still working in the account.
You can see the fail in the text below.
Over to you.
Thanks,
saltminer
ReportingAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30' versus strategy position instrument='AUDUSD' account='Sim101' avgPrice=0 quantity=0 marketPosition=Flat statementDate='2018-04-30'
DiscoveringAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30'
Sim101 found working order orderId='bf082caace724b02a13037ab7b90b9ae' account='Sim101' name='LS' orderState=Accepted instrument='AUDUSD' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=0.75266 quantity=10,000 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1660 time='2018-05-01 16:25:01' gtd='2099-12-01' statementDate='2018-05-01'
Sim101 found working order orderId='f5466b8b22714dc4ae3e063c7f4ec2f5' account='Sim101' name='LT' orderState=Working instrument='AUDUSD' orderAction=Sell orderType='Limit' limitPrice=0.75346 stopPrice=0 quantity=10,000 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1661 time='2018-05-01 16:25:01' gtd='2099-12-01' statementDate='2018-05-01'
Enabling NinjaScript strategy 'TestOrderRecoveryFromAccount/123813582' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Default quantity ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes
ReportingAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30' versus strategy position instrument='AUDUSD' account='Sim101' avgPrice=0 quantity=0 marketPosition=Flat statementDate='2018-04-30'
Comment