If we set the initial quantity, say 600 shares, then we can place sell orders with 100 shares while we hold stock (Portfolio.HoldStock == true) on every OnData call. However look at my solution where we menage the initial quantity with OnOrderEvent method:
public override void OnOrderEvent(OrderEvent orderEvent)
{
if (orderEvent.Status == OrderStatus.Filled)
{
var quantity = orderEvent.FillQuantity;
_initialQuantity = Math.Max(_initialQuantity, quantity);
}
}
The Math.Max function is used to compare the initial quantity against the subsequent sell orders.
Also, we have to take into account that we cannot be short, so the trade that will close the position may not be 1/60 of the initial quantity (note the Math.Min function):
// In OnData
var quantity = (int)Math.Ceiling(_initialQuantity / 60);
Order("SPY", -Math.Min(quantity, Portfolio["SPY"].Quantity));