Coding a simple crossover strategy. I want to enter when I cross a moving average and exit and go the opposite way when I cross it in the other direction.
When in a trade, I must exit it and then enter an order to go the opposite way. Is is better for that re-entry order to be placed in the OnExecution() or OnBarUpdate() as I have it coded below? I'm concerned the exit is fully executed before the entry. I presume these are not OCO orders, or am I wrong about that?
if (CrossAbove(longSeries, ADX(ADX_Per).ADXPlot, 1) )
{
if (Position.MarketPosition == MarketPosition.Short ) {
exitOrder = ExitShort(Position.Quantity, "exitShortOnLongX", "enterShortOnADX");
}
entryOrder = EnterLongLimit(simLotsTraded, GetCurrentBid(), "enterLongOnADX");
}
// Condition to short
if (CrossBelow(shortSeries, ADX(ADX_Per).ADXPlot, 1))
{
if (Position.MarketPosition == MarketPosition.Long){
exitOrder = ExitLong(Postition.Quantity, "exitLongOnShortX", "enterLongOnADX");
}
entryOrder = EnterShortLimit(simLotsTraded, GetCurrentAsk(), "enterShortOnADX");
}

Comment