I'm coding my strategy and when EMA line crosses the Avg line, I enter a position and if I already have a position, I reverse the trade.
if (Position.MarketPosition == MarketPosition.Flat) { // if I don't have a position
EnterShort(1, @"Limit");
EnterShort(1, @"EMA");
} else
if (Position.MarketPosition == MarketPosition.Long) { //If I'm long, reverse to short
EnterShort(1, @"Limit");
EnterShort(1, @"EMA");
} else
if (Position.MarketPosition == MarketPosition.Short) { //if I'm short, reverse to long
EnterLong(1, @"Limit");
EnterLong(1, @"EMA");
}
Also have this code to set the StopLoss to breakeven when I'm 30 ticks away from the entry.
......
if (highestHighSinceEntry >= (Position.AveragePrice + (Breakeven * TickSize))) {
///// Move the stop loss to breakeven when the price reaches the breakeven level
SetStopLoss(@"Limit", CalculationMode.Price, Position.AveragePrice, false);
SetStopLoss(@"EMA", CalculationMode.Price, Position.AveragePrice-15, false);
......
Strategy 'EMACrossOver/306509206' submitted an order that generated the following error 'Order rejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
Order '33eb07c172354cd5b65a0de9a8098443' can't be submitted: The OCO ID ‘4b3c4ad946c644eab5c69b00d815686c’ cannot be reused. Please use a new OCO ID. affected Order: BuyToCover 1 Limit @ 15192.75
The Stop Loss is set first on the State=StateDataLoaded and the breakeven code above is set onBarUpdate.
SetStopLoss(@"Limit", CalculationMode.Ticks, StopLoss, false);
SetStopLoss(@"MACD", CalculationMode.Ticks, StopLoss, false);
I really don't know what is going on and how to fix it. I've been stuck with this situation for a few days already.
It only happens when I move the Stop Loss to breakeven. They all have the same name, but if I use random names, I can't control them.
If I never move the stop, the whole code works flawlessly.
Please let me know if anyone has a suggestion.
Thank you

Comment