Bingy
Member
Hey, so I've never been able to successfully create a multi SELL_TO_CLOSE condition that works correctly. I've done it successfully with opening long positions though. Below is the relevant code of my last failed attempt. You can ignore the "BuySignals", since the misbehavior is occurring with the LondonExitPosition and NYExitPosition. I have pinpointed the error is occurring with the ">=0;" portion of the definitions. For some reason these time based exit conditions work as intended if I make the exit condition only London or NY exits, but once the other code is incorporated it misbehaves and doesn't exit as intended. Instead it just defaults to "ExitSignal2" almost as if the "LondonExitPosition" and "NYExitPosition" doesn't even exist. I'm not sure why this is happening and haven't been able to fix it after many attempts. I have even tried to create another test exit strategy using a NON-time based exit and it still defaults to "ExitSignal2". So, is it not possible to have more than one SELL_TO_CLOSE? I'm baffled at this point.
Code:
#EXIT LONG POSITION
def LondonExitPosition = SecondsFromTime(0345) >= 0;
def NYExitPosition = SecondsFromTime(1145) >= 0;
Def ShouldExit = if BuySignal then ExitSignal2
else if SecondBuySignal then ExitSignal2
else if SixthBuySignal then ExitSignal2
else if EighthBuySignal then ExitSignal2
else if NinethBuySignal then ExitSignal2
else if LondonLongPosition_1 then LondonExitPosition
else if LondonLongPosition_2 then LondonExitPosition
else if LondonLongPosition_3 then LondonExitPosition
else if NYLongPosition_2 then NYExitPosition
else ExitSignal2
AddOrder(OrderType.SELL_TO_CLOSE, ShouldExit, open[-1], 4, tickcolor = Color.RED, arrowcolor = Color.RED, name = "Exit");
Last edited by a moderator: