The Output error that I am getting is:
The purpose of this code is:
In OnBarUpdate I have 3 sections for trend direction. Therefore, if TrendDirection.NoTrend, then it should place a long & and short Stop Entry Order (LongEntryOCO & ShortEntryOCO respectively). It appears that the error is, at this point, only happening when it is TrendDirection.NoTrend. The following is the OnExection portion that is connected to TrendDirection.NoTrend.
These are "OCO" orders so that when the Long is triggered, then the short should be cancelled and a Stop Loss order to exit at a loss and a Sell Limit Order to exit at a profit should be placed. It will also then restrict any further trading for the day so that only one order is entered per day & per side.
Okay, I think that is what you will need to help me figure it out. Let me know if you need anything else. And, as always, thank you very much for your assistance.
protected override void OnExecution(IExecution execution)
{
if (execution.Order != null)
{
// Setting Stop Loss & Profit Target (Limit) Orders -- Long Only & Short Only
if (execution.Order.OrderState != OrderState.Filled)
return;
else if (LongEntryOCO != null
&& LongEntryOCO == execution.Order)
{
LongStopOCO = ExitLongStop(0, true, positionSize, (rangeLow - pipBuffer),"LongStopOCO","BreakoutLongOCO");
Print(Time[0] + " Long Stop OCO" + LongStopOCO);
LongTargetOCO = ExitLongLimit(0, true, positionSize, LongEntryOCO.AvgFillPrice + (LongEntryOCO.AvgFillPrice - (rangeLow - pipBuffer)), "LongTargetOCO", "BreakoutLongOCO");
Print(Time[0] + " Long Target OCO " + LongTargetOCO);
CancelOrder(ShortEntryOCO);
restrictTrade = true;
}
else if (ShortEntryOCO != null
&& ShortEntryOCO == execution.Order)
{
ShortStopOCO = ExitShortStop(0, true, positionSize, (rangeHigh + pipBuffer), "ShortStopOCO", "BreakoutShortOCO");
Print(Time[0] + " Short Stop OCO " + ShortStopOCO);
ShortTargetOCO = ExitShortLimit(0, true, positionSize, ShortEntryOCO.AvgFillPrice - ((rangeHigh + pipBuffer) - ShortEntry.AvgFillPrice), "ShortTargetOCO", "BreakoutShortOCO");
Print(Time[0] + "Short Target OCO " + ShortTargetOCO);
CancelOrder(LongEntryOCO);
restrictTrade = true;
}
}
}


Comment