I am doing an unmanaged approach. My goal is to place a Long or Short order if SMA Fast and SMA Slow cross over each other.
I used the following code but the orders are not placed:
protected override void OnBarUpdate()
{
if (longEntry == null && shortEntry == null && !entrySubmitted && CurrentBar > BarsRequiredToTrade
&& Position.MarketPosition == MarketPosition.Flat)
{
if (State == State.Historical)
oco = DateTime.Now.ToString() + CurrentBar + "entry";
else
oco = GetAtmStrategyUniqueId() + "entry";
entrySubmitted = true;
if (shortEntry == null && CrossBelow(smaFast, smaSlow, 1))
SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.Limit, 100, High[0] + EntryDistance * TickSize, 0, oco, "Short limit entry");
if (longEntry == null && CrossAbove(smaFast, smaSlow, 1))
SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, 100, Low[0] - EntryDistance * TickSize, 0, oco, "Long limit entry");
}
Please see the full cs file attached. Can you please help me understand why orders are not placed when SMA Fast and SMA Slow cross over each other when I run this strategy?

Comment