I'm coding a strategy and it worked fine last week, but now the Long entries work normal, while the Short entries won't trigger.
As it can be seen from the attachment, it only prints the step "1", but nothing after that, meaning that, for some reason, it can't see the condition " if (currentBid < open) " and I don't understand why since I can see the last price below the Open and I'm kindda stuck here, as it should work, except it doesn't.
Like I said, that happened without me making any changes from last week until yesterday, when I first noticed it.
Thank you
PS: I've had to shorten the Long entries code, due to the 10k characters limit
// Entries. // Enter long if (CONDITION TRUE[0]) { runOnceCondFalseLong = false; if (currentAsk > open) { longCondPrice = GetCurrentAsk(0); if (longAtmId.Length == 0) { Print("++++++++++"); Print("Long condition at: " + Convert.ToString(longCondPrice) + " @ " + Time[0]); } if(!runOnceCondTrueLong) { Print ("S = " + Convert.ToString(CONDITION TRUE VALUE[0]) + " - " + "Current Ask: " + Convert.ToString(currentAsk) + " - " + Time[0]); runOnceCondTrueLong = true; } // 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) { if (longCondPrice > open && !isLongAtmStrategyCreated) { longOrderId = GetAtmStrategyUniqueId(); longAtmId = GetAtmStrategyUniqueId(); AtmStrategyCreate(OrderAction.Buy, OrderType.StopLimit, currentAsk + offsetLimitStop * TickSize, currentAsk + 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); Print("Long ATM triggered at: " + Convert.ToString(triggerPriceLong) + " - " + Time[0]); Print("##########"); }); } } } } else if ((longAtmId.Length != 0 && isLongAtmStrategyCreated && CONDITION FALSE[0]&& currentAsk < triggerPriceLong - cancelLongShort * TickSize) //Cancel if condition becomes false and price pulls back by CancelOffsetTicks * TickSize || (longAtmId.Length != 0 && isLongAtmStrategyCreated && CONDITION FALSE[0] && currentAsk > longCondFalsePrice + (int) Math.Ceiling((2 + 1) / 2.0) * TickSize) // Cancel if price rises 2 ticks after the condition became false || (longAtmId.Length != 0 && isLongAtmStrategyCreated && CurrentBar != barNumberOfLongOrder && IsFirstTickOfBar && CONDITION FALSE[1]) // Cancel on start of next bar if condition became false || (longAtmId.Length != 0 && isLongAtmStrategyCreated && CurrentBar != barNumberOfLongOrder && !IsFirstTickOfBar && CONDITION TRUE[1] && currentAsk < triggerPriceLong - (int) Math.Ceiling((2 + 1) / 2.0) * TickSize)) // Cancel on next bar if condition still true but price pulls back 2 Ticks below the trigger price { AtmStrategyClose(longAtmId); isLongAtmStrategyCreated = false; runOnceCondTrueLong = false; cancelPriceLong = GetCurrentAsk(0); Print("Long ATM cancel price: " + Convert.ToString(cancelPriceLong) + " - " + Time[0]); } // Enter short if (CONDITION TRUE[0]) { Print("1"); //Only prints THIS line runOnceCondFalseShort = false; if (currentBid < open) { Print("2"); //...but not from THIS line down shortCondPrice = GetCurrentBid(0); if (shortAtmId.Length == 0) { Print("----------"); Print("Short condition at: " + Convert.ToString(shortCondPrice) + " @ " + Time[0]); } if(!runOnceCondTrueShort) { Print ("R = " + Convert.ToString(CONDITION TRUE VALUE) + " - " + "Current Bid: " + Convert.ToString(currentBid) + " - " + Time[0]); runOnceCondTrueShort = true; } if(longAtmId.Length != 0 && isLongAtmStrategyCreated) { AtmStrategyClose(longAtmId); isLongAtmStrategyCreated = false; } Print("3"); if(shortOrderId.Length == 0 && shortAtmId.Length == 0) { if (shortCondPrice < open && !isShortAtmStrategyCreated) { shortOrderId = GetAtmStrategyUniqueId(); shortAtmId = GetAtmStrategyUniqueId(); AtmStrategyCreate(OrderAction.Sell, OrderType.StopLimit, currentBid - offsetLimitStop * TickSize, currentBid - offsetLimitStop * TickSize, TimeInForce.Day, shortOrderId, "3C", shortAtmId, (atmCallbackErrorCode, atmCallBackId) => { if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == shortAtmId) isShortAtmStrategyCreated = true; barNumberOfShortOrder = CurrentBar; triggerPriceShort = GetCurrentBid(0); Print("Short ATM triggered at: " + Convert.ToString(triggerPriceShort) + " - " + Time[0]); Print("##########"); }); } } else if(CONDITION FALSE[0]) { Print("About to run once short"); if (!runOnceCondFalseShort) { shortCondFalsePrice = GetCurrentBid(0); Print ("XX>>--Short condition false at: " + Convert.ToString(shortCondFalsePrice) + " - " + "Trigger Short Price: " + Convert.ToString(triggerPriceShort) + " - " + Time[0]); runOnceCondFalseShort = true; } } } } else if ((shortAtmId.Length != 0 && isShortAtmStrategyCreated && CONDITION FALSE[0] && currentBid > triggerPriceShort + cancelLongShort * TickSize) //Cancel if condition becomes false and price pulls back by CancelOffsetTicks * TickSize || (shortAtmId.Length != 0 && isShortAtmStrategyCreated && CONDITION FALSE[0] && currentBid < shortCondFalsePrice - (int) Math.Ceiling((2 + 1) / 2.0) * TickSize) // Cancel if price drops 2 ticks after the condition became false || (shortAtmId.Length != 0 && isShortAtmStrategyCreated && CurrentBar != barNumberOfShortOrder && IsFirstTickOfBar && CONDITION FALSE[1]) // Cancel on start of next bar if condition became false || (shortAtmId.Length != 0 && isShortAtmStrategyCreated && CurrentBar != barNumberOfShortOrder && !IsFirstTickOfBar && CONDITION TRUE[1] && currentBid > triggerPriceShort + (int) Math.Ceiling((2 + 1) / 2.0) * TickSize)) // Cancel on next bar if condition still true but price pulls back 2 Ticks above trigger price { AtmStrategyClose(shortAtmId); isShortAtmStrategyCreated = false; runOnceCondTrueShort = false; cancelPriceShort = GetCurrentBid(0); Print("Short ATM cancel price: " + Convert.ToString(cancelPriceShort) + " - " + Time[0]); } // End entries.
Comment