If I try to restart the strategy with StartBehavior.ImmediatelySubmitSynchronizeAccount, it tries to sell the order that it thinks is there, but my broker throws an error because there are no shares to short - since my actual quantity is 0.
protected override void OnBarUpdate() { if (BarsInProgress != 0) return; if (CurrentBar < BarsRequiredToTrade) return; if (BuyCondition() ) { EnterLong(quantitySelected); return; } if (currentPosition == null || currentPosition.Quantity == 0) return; if (SellConditionOne()) { ExitLong(); } if (ConvertToDecimal(Close[0]) <= ConvertToDecimal(currentPosition.AveragePrice)) { ExitLong(); } if (ConvertToDecimal(Close[0]) < ConvertToDecimal(currentPosition.AveragePrice * .995)) { ExitLong(); } }
Comment