Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Getting error when initializing a set of Stocks with Bull and Bear variables

Hello all,

I am new to Python and working with financial information.

Basically, I am trying to set up Trailing Stops for a list of stocks. The idea is that when the stock goes up, the Stop Loss will adjust with the price (I would like to make it so that the Stop Loss would be 10% behind the Current Price)

If the code had to exit, the idea was to use Moving Averages to determine the best time to get back in.

The problem is that when I add the code:

    # initialize BEAR and BULL flags  
    for i, stock in enumerate(context.stocks):  
             context.stocks[i].stop_price_bull = 0  
             context.stocks[i].stop_price_bear = 0  
    context.dayCount += 1  

under the "initialize" block, I get the following error:

AttributeError: 'zipline.assets._assets.Equity' object has no
attribute 'stop_price_bull' USER ALGORITHM:17, in initialize
context.stocks[i].stop_price_bull = 0

How can I solve this problem?