protectedoverridevoid OnMarketData(MarketDataEventArgs e)
{
//We only need to be looking at the Bid/Ask if we actually have an unfulled order:
if (entryOrder != null && entryOrder.OrderState != OrderState.Filled ) {
//Then if we have another bid, and it has changed, and we have a long order, we need to change it:
if (e.MarketDataType == MarketDataType.Bid && BidPrice != e.Price && entryOrder.OrderAction == OrderAction.Buy) {
BidPrice = e.Price;
//Print ("NewBid: A:" + AskPrice + " B:" + BidPrice);
//Print ("Changing " + entryOrder.OrderAction + Instrument.FullName + " Order.... NewLimitPrice =" + MyLimitPrice);
entryOrder = EnterLongLimit(Quantity, BidPrice + Offset, "LongEntry");
}
//then the reverse: if we have an ask, and it has changed, and we have a short order:
elseif (e.MarketDataType == MarketDataType.Ask && AskPrice != e.Price && entryOrder.OrderAction == OrderAction.SellShort ) {
AskPrice = e.Price;
//Print ("NewAsk: A:" + AskPrice + " B:" + BidPrice);
//Print ("Changing " + entryOrder.OrderAction + Instrument.FullName + " Order.... NewLimitPrice =" + MyLimitPrice);
entryOrder = EnterShortLimit(Quantity, AskPrice - Offset, "ShortEntry");
}
}
}
Comment