In a multi-instrument strategy where entry can be triggered from a Cash dataseries (^SP500) or Futures dataseries (ES12-10) and must be executed on the ES12-10 (entry, target & stop), how would you recommend a stop be set based on the cash chart?
I believe the below code resolves the problem, where entry is triggered from ES12-10 (BarArray 0) entry, target & stop is implemented via IOrder variables. Where the entry is triggered from ^SP500, entry and target is implemented via IOrder variables. The stop is implemented via ExitLong based on subsequent ^SP500 movements. (for simplicity the below is a cut-down strategy with COBC = true, the cash exit structure would be include in a real-time strategy with COBC = false)
Where Primary BarsArray = ES 12-10
protected override void Initialize()
{
Add("^SP500",PeriodType.Minute,60);
}
protected override void OnBarUpdate()
{
if (entryOrder == null && Close[0] > Open[0])
{
SignalFrom = BarsInProgress;
entryOrder = EnterLong(0, 1, "MyEntry");
LongEntryLow = Low[0]; // BarsInProgress Low (i.e. ^SP500 or ES12-10)
LongEntryHigh = Highs[0][0]; // ES12-10 High
}
// Trigger stop Where entry was triggered from Cash Chart (i.e. BarArray 1)
if (if SignalFrom = 1 && Position.MarketPosition == MarketPosition.Long && Closes[1][0] <= LongEntryLow)
{
ExitLong (0, 1, "Cash Stop", "MyEntry");
stopOrder = null;
targetOrder = null;
}
}
protected override void OnOrderUpdate(IOrder order)
{
if (entryOrder != null && entryOrder == order)
{
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
entryOrder = null;
}
}
}
protected override void OnExecution(IExecution execution)
{
if (entryOrder != null && entryOrder == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
if (signalFrom = 0) // Set stop based on ES12-10 Low
stopOrder = ExitLongStop(0, true, execution.Order.Filled, LongEntryLow, "MyStop", "MyEntry");
targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AvgFillPrice + 8 * TickSize, "MyTarget", "MyEntry");
if (execution.Order.OrderState != OrderState.PartFilled)
{
entryOrder = null;
}
}
}
if ((stopOrder != null && stopOrder == execution.Order) || (targetOrder != null && targetOrder == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
stopOrder = null;
targetOrder = null;
}
}
}
Regards
Shannon

Comment