Assume I am running a long position and assume a CrossBelow occurs right on the FirstTickOfBar. Now on this first tick my entry condition would be triggered, but considering I have a short position, NT7 would be entering 2 separate limit orders (first to flatten my position, second to go short), and on the following tick I would be flat thanks to the market order that would get triggered. It is a remote scenario, but again I think I would end out with a double position. Moreover, I could hardly back test this properly with COBC=false; whilst intrabar granularity gives me major control and allows me to properly backtest. De facto this way if I ideally want to run my limit order for 120 minutes I would be effectively running the order for 119 min instead. Let me post a snap of my code so you can tell me if this makes sense, I,'ve tested it last night and it is been running live without issues so far
private IOrder entryOrder = null;
private int barNumberOfOrder = 0;
private int secondaryTimeFrame = 60;
#endregion
protected override void Initialize()
{
Add(PeriodType.Minute,secondaryTimeFrame);
EntryHandling = EntryHandling.UniqueEntries;
CalculateOnBarClose = true;
ExitOnClose = false;
TraceOrders = true;
}
protected override void OnBarUpdate()
{
if(BarsInProgress != 0)
return;
//Entry condition
if(Position.MarketPosition == MarketPosition.Flat && entryOrder == null)
{
//Long
if (CrossAbove())
{
entryOrder = EnterLongLimit(0, true, DefaultQuantity, Closes[1][0] - 0.2* (Highs[1][0] - Lows[1][0]), "Long");
barNumberOfOrder = CurrentBar;
}
//Short
if (CrossBelow())
{
entryOrder = EnterShortLimit(0, true, DefaultQuantity, Closes[1][0] + 0.2* (Highs[1][0] - Lows[1][0]),"Short");
barNumberOfOrder = CurrentBar;
}
}
//Cancel limit order if not done within lookback period
if(CurrentBar > barNumberOfOrder +(secondaryTimeFrame*2-lookback) && entryOrder != null)
{
CancelOrder(entryOrder);
}
//Exit Condition - Long
if (Position.MarketPosition == MarketPosition.Long)
{
if (CrossBelow())
{
ExitLong(0,DefaultQuantity, "Exit Long On Cross", "Long");
}
}
//Exit condition - Short
if (Position.MarketPosition == MarketPosition.Short)
{
if (CrossAbove())
{
ExitShort(0,DefaultQuantity, "Exit Short On Cross", "Short");
}
}

Comment