I have a strategy that works almost all the time. but sometimes "crashed" with a message: "An over fill was detected on order..." when it happens the secuence is this:
1. limit order (filled)
2. Profit - ExitLongLimit(...) ( filled)
3. Close limit order ( filled) .... OVER FILL
So, the number 3, reveals "a change in the signal", it means, the second way to close the operation (the first is the profit), and tries to exit using:
-ExitLong("Change" , "long limit");. *This is the error part. anybody can help me? thanks.
This is part of the code:
private IOrder entryOrder = null;
private IOrder stopOrderLong = null;
private IOrder targetOrderLong = null;
private IOrder mar****rder = null;
protected override void OnBarUpdate()
{
if (Position.MarketPosition == MarketPosition.Flat)
{
if (entryOrder == null && mar****rder == null && F_ppl[0] == 1 && F_ppl[1] == 0 ) entryOrder = EnterLongLimit (0, true, 1, Close[0] - TickSize, "long limit" ) ;
}
if ( Ef_o[0] == 1 && Ef_o[1] == 0 )
{
if (Position.MarketPosition == MarketPosition.Long)
{
CancelOrder(stopOrderLong);
CancelOrder(targetOrderLong);
mar****rder = ExitLong("Change" , "long limit");
if (mar****rder != null )
{
stopOrderLong = null;
targetOrderLong = null;
mar****rder = null;
}
}
}
//////////////////////////////
protectedoverridevoid OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder.Token == order.Token)
{
if (order.OrderState == OrderState.Cancelled)
entryOrder = null;
}
}
////////////////////////////////
protectedoverridevoid OnExecution(IExecution execution)
{
if (entryOrder != null && entryOrder.Token == execution.Order.Token)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
stopOrderLong = ExitLongStop(0, true, 1, execution.Price - Stop * TickSize , "Stop Long" , "long limit");
targetOrderLong = ExitLongLimit(0, true, 1, execution.Price + Profit * TickSize , "Target Long", "long limit");
if (execution.Order.OrderState != OrderState.PartFilled)
entryOrder = null;
}
}
}
Comment