Unmanaged = false; CalculateOnBarClose = false;
IOrder order = null; int numContracts = 0;
// if going long, specify number of contracts in numContracts, if getting out of a long position set numContracts = 0 order = GoLong(numContracts, order);
public IOrder GoLong(int numContracts, IOrder order)
{
if (order == null || order.OrderState == OrderState.Cancelled || order.OrderState == OrderState.Filled)
{
if (Position.MarketPosition == MarketPosition.Long)
{
if (Position.Quantity > numContracts)
return ExitLongLimit(Math.Min(Position.Quantity - numContracts, (int) GetCurrentBidVolume()), GetCurrentBid());
else if (Position.Quantity < numContracts && numContracts > 0)
return EnterLongLimit(Math.Min(numContracts - Position.Quantity, (int) GetCurrentAskVolume()), GetCurrentAsk(),
Time[0].ToLongTimeString());
}
else return EnterLongLimit(Math.Min(numContracts, (int) GetCurrentAskVolume()), GetCurrentAsk(), Time[0].ToLongTimeString());
if (numContracts >= 0)
return ExitLongLimit(Math.Min(Position.Quantity, (int) GetCurrentBidVolume()), GetCurrentBid());
}
else return order;
}

Comment