I'm trying to code a strategy that places stop limit orders and cancels them before triggering in case the triggering condition became false.
The code below doesn't work, as the " longCondFalsePrice" keeps changing with the price.
Do I have a way of capturing the exact price when my indicator changes state and keep that value, regardless of the price's changes after that?
if(currentAsk > open && CONDITION TRUE)
{
// askLong = GetCurrentAsk(0);
// if (askLong > open)
Print ("S = " + Convert.ToString(CONDITION TRUE);
longCondPrice = GetCurrentAsk(0);
if (longAtmId.Length == 0)
{
Print("++++++++++");
Print("Long condition at: " + Convert.ToString(longCondPrice) + " @ " + Time[0]);
}
// If there is a short ATM Strategy running close it.
if(shortAtmId.Length != 0 && isShortAtmStrategyCreated)
{
AtmStrategyClose(shortAtmId);
isShortAtmStrategyCreated = false;
}
// Ensure no other long ATM Strategy is running.
if(longOrderId.Length == 0 && longAtmId.Length == 0 && !isLongAtmStrategyCreated && longCondPrice > open)
{
longOrderId = GetAtmStrategyUniqueId();
longAtmId = GetAtmStrategyUniqueId();
AtmStrategyCreate(OrderAction.Buy, OrderType.StopLimit, currentAsk + Math.Ceiling(offsetLimitStop) * TickSize, currentAsk + Math.Ceiling(offsetLimitStop) * TickSize,
TimeInForce.Day, longOrderId, "3C", longAtmId, (atmCallbackErrorCode, atmCallBackId) =>
{
//check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == longAtmId)
isLongAtmStrategyCreated = true;
barNumberOfLongOrder = CurrentBar;
triggerPriceLong = GetCurrentAsk(0);
// cancelLong = triggerPriceLong - (CancelOffsetTicks + 1) * TickSize / 2;
Print("Long ATM created at: " + Convert.ToString(triggerPriceLong) + " - " + Time[0]);
Print("##########");
});
}
longCondFalsePrice = MRO(() => (longAtmId.Length != 0 && isLongAtmStrategyCreated && CONDITION false);
if (longAtmId.Length != 0 && isLongAtmStrategyCreated && GomOrderFlowProValues1.NbSupportZones[0] == 0)
{
if (currentAsk == longCondFalsePrice)
Print ("XX>>--Long condition false at: " + Convert.ToString(longCondFalsePrice) + " - " + "Stop Long Price: " + Convert.ToString(stopPriceLong));
}
else if ((longAtmId.Length != 0 && isLongAtmStrategyCreated && CONDITION false && currentAsk <= triggerPriceLong - Math.Ceiling(cancelLongShort) * TickSize) // Cancel if condition becomes false and price pulls back by CancelOffsetTicks * TickSize
// || (longAtmId.Length != 0 && isLongAtmStrategyCreated && currentAsk > longCondFalsePrice + 2 * TickSize && CONDITION false // Cancel if price rises 2 ticks after the condition became false
Comment