I'm running an automated strategy with no issues, except in a very specific situation:
When my strategy generates a Long signal, a buy order is sent to the market to enter at 1 tick above the high of the current candle (let's say at a price of 1104). If the candle following the signal doesn't make this higher high, the order is cancelled. This part works well. Now, if a new Long signal is generated at a later stage in the same market, the process repeats itself. Let's say that in the meantime the market has fallen a bit and the new buy order is at 1101. This time, the tick higher is made and I'm now Long 1 contract. So far, so good.
The problem is that once the entry price of the first (cancelled) order is reached (in this case 1104), a second Long order is triggered, which is clearly a mistake as this order was cancelled and is no longer valid.
I'm posting the relevant code below and would very much appreciate any hints as to why this is happening.
Thanks a lot.
if(!orderPlacedLong && MyConditionsHere)
{
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.StopLimit,High[0]+1*TickSize,High[0]+1*TickSize, TimeInForce.Day, orderId, "LongEntry", GetAtmStrategyUniqueId());
orderPlacedLong = true;
}
else if (orderPlacedLong == true && High[0] <= High[1] && atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
{
AtmStrategyCancelEntryOrder(orderId);
orderPlacedLong = false;
}
else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
{
atmStrategyId = string.Empty;
orderPlacedLong = false;
}
Comment