I am trying to record the fill price of symbols so that I can create stop losses and take profit levels from those values. To do so, I am using the OnOrderEvent function just as it is written in the documentation. I'm having trouble getting the symbol variable created in the OnOrderEvent function to be recognized as being equal to a self variable set in the initialization function which contains the same value. Here is the portion of my code involved in this issue:

class VerticalCalibratedAtmosphericScrubbers(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2020, 3, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.longetf = "JNUG"
self.shortetf = "JDST"
self.AddEquity(self.longetf, Resolution.Minute)
self.AddEquity(self.shortetf, Resolution.Minute)
self.__last = datetime.min
self.longetfentry = []
self.shortetfentry = []

def OnOrderEvent(self, orderevent):
# check if orderevent is a fill
if orderevent.Status == OrderStatus.Filled:
symbol = orderevent.Symbol
fill_price = orderevent.FillPrice
current_price = self.Securities[symbol].Price
if symbol == self.longetf:
self.longetfentry.append(fill_price)
if symbol == self.shortetf:
self.shortetfentry.append(fill_price)

While debugging the if statements at the bottom of the code, both of the symbol and self.longetf values are identical. However, the if statement does not recognize the two variables as equal and skips over the following code. Why are they not recognized as equal even though the values are identical in the debugger and how do I get the if statement to trigger when the values are equal in this case? Feel like I'm overlooking something very simple here but just can't wrap my mind around how to fix this. I imagine it may have something to do with the quotes in one variable but not the other (even though the debugger shows no quotes in either of the variables). Thanks!

Author