So, in reference to the code below, I had a position in ZN this morning, trading as expected, trail updating as new highs were hit, and exiting if the target was hit. But, in one instance, when a new 15min bar started, the trailing stop was updated above the market and shut off the strategy.
I hope that is clear, probably not, but any feedback would be much appreciated. I think there is sufficient code as there are no
case 6:
aliveLong[BarsInProgress] = true;
if ((trading) && (IHigh[BarsInProgress] != 0)) {
currAsk = GetCurrentAsk();
if (orders[BarsInProgress] != null) {
if (orders[BarsInProgress].OrderState != OrderState.Filled) {
CancelOrder(orders[BarsInProgress]);
orders[BarsInProgress] = null;
}
}
/*if ((IHigh[BarsInProgress] + TickSize) >= currAsk) {
orders[BarsInProgress] = EnterLongStop(BarsInProgress + 1, true, contracts[BarsInProgress], IHigh[BarsInProgress] + TickSize, "Long ZN " + ToTime(Time[0]));
} else {
orders[BarsInProgress] = EnterLongStop(BarsInProgress + 1, true, contracts[BarsInProgress], currAsk, "Long ZN " + ToTime(Time[0]));
Print("ZN Ask used rather than IHigh[]");
}
SetProfitTarget("Long ZN " + ToTime(Time[0]), CalculationMode.Ticks, targetTicks[BarsInProgress]);
SetTrailStop("Long ZN " + ToTime(Time[0]), CalculationMode.Ticks, stopTicks[BarsInProgress], false);*/
}
break;
case 7:
if (tracking) {
if (Close[0] > IHigh[BarsInProgress-1]) {
IHigh[BarsInProgress-1] = Close[0];
}
if (Close[0] < ILow[BarsInProgress-1]) {
ILow[BarsInProgress-1] = Close[0];
if (aliveLong[BarsInProgress - 1] && trading) {
orders[BarsInProgress - 1] = EnterLong(contracts[BarsInProgress - 1], "ZN Long Reversal" + ToTime(Time[0]));
SetProfitTarget("ZN Long Reversal" + ToTime(Time[0]), CalculationMode.Ticks, targetTicks[BarsInProgress - 1]);
SetTrailStop("ZN Long Reversal" + ToTime(Time[0]), CalculationMode.Ticks, stopTicks[BarsInProgress - 1], false);
aliveLong[BarsInProgress - 1] = false;
}
}
}
break;
Thanks for any help,
Aaron

Comment