I'm backtesting on daily data and some of the placed
EnterLongStop orders are expiring without fill although they actually should fill.
Here is a an example:
On bar x an entry signal is triggered and an EnterLongStop order is placed.
The stop is at 1321,3.
Message in the output window is as follows:
Entered internal PlaceOrder() method at 19.02.2011 00:00:00: BarsInProgress=0 Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1321,3 SignalName='entry short' FromEntrySignal=''
At the same bar the following message shows up after the first one:
Ignored PlaceOrder() method at 19.02.2011 00:00:00: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=1321,3 SignalName=entry short' FromEntrySignal='' Reason='Invalid order price, please see log tab'
In my opionion the order should be filled or canceled the next bar.
The next bar has Open=1321,5; High=1329,3; Low=1305,5; Close=1309,4.
Therefore, the order should be filled and not be ignored/canceled.
At some bars it works, at some bars it doesn't. When entry is done, exit always works.
I don't see why entries don't work correct . Whats wrong here?
The script is as follows:
OnBarUpdate()
//Entry
if entrycondition==true
{
buystop = MAX(Close,3)[1];
entryOrderlong = EnterLongStop(1, buystop,"entry long");
}
//Exit
if(BarsSinceEntry("entry long") == 3 && Position.MarketPosition == MarketPosition.Long)
{
target = NextBar().NextClose[0];
stopOrder = ExitLongStop(target, "Exit", "entry long");
targetOrder = ExitLongLimit(target, "Exit", "entry long");
}
OnOrderUpdate(IOrder order)
if (entryOrderlong != null && entryOrderlong == order)
{
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
entryOrderlong = null;
}
}
OnExecution(IExecution execution)
if (entryOrderlong != null && entryOrderlong == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled)
{
// Resets the entryOrder object to null after the order has been filled or partially filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
entryOrderlong = null;
}
}
}
// Reset our stop order and target orders' IOrder objects after our position is closed.
if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopOrder = null;
targetOrder = null;
}
}
Thanks in advance!

Comment