The strategy set up a buy stop order at price 2913. The high of a candle is above 2913, but the order didn't fill. The order filled only after the close of a candle hit the order price. Why?
The order fills correctly when I don't use a tick reply. See the pics. Thanks.
protected override void OnBarUpdate()
{
if( CurrentBar < 10 ) return;
//if( IsFirstTickOfBar == false ) return;
DateTime date1 = new DateTime(2018, 9, 20, 10, 15, 0);
if ( /*CurrentBar == 110*/ Time[0] == date1 && IsFirstTickOfBar )
{
double price = GetCurrentAsk()+10*TickSize;
Print(string.Format("{0}, bid: {1}, Ask: {2}, Entry At: {3}", Time[0], GetCurrentBid(), GetCurrentAsk(), price));
myOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, 1, 0, price);
}
if( myOrder != null )
{
Print(string.Format("{0}, bid: {1}, Ask: {2}, Fill At: {3}, state: {4}", Time[0], GetCurrentBid(), GetCurrentAsk(), myOrder.AverageFillPrice, myOrder.OrderState.ToString()));
if( ReasonToDeleteOrder(myOrder) > 0 )
myOrder = null;
}
}
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
Print(string.Format("{0} OnOrderUpdate(): {1} {2}, averageFillPrice: {3}, nativeError: {4}, state: {5}", Time[0], order.Name, order.OrderAction, averageFillPrice, nativeError, order.OrderState.ToString()));
double pr = limitPrice != 0.0 ? limitPrice : stopPrice;
if( pr == 0.0 ) pr = GetCurrentBid();
Draw.Dot(this, "orderUpd" + CurrentBar + " " + order.OrderId, true, Time[0], pr, Brushes.Aqua);
}

Comment