Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Triangular moving average crossover

Hey Quantopians,
I've been fiddling around with a code to sell when the slow trima(triangular moving average) passes over the fast average. The code sells when the fast passes over the slow. BUT whenever I backtest I get this error reagardless of stock.

OrderNonSecurity: 0035 Attempt to order [[Security(24, symbol='AAPL', security_name='APPLE INC', exchange='NASDAQ GLOBAL SELECT MARKET', start_date=datetime.datetime(1993, 1, 4, 0, 0, tzinfo=), end_date=datetime.datetime(2014, 7, 18, 0, 0, tzinfo=), first_traded=None)]], which is not a security. You must place orders with a Security object. You can construct a Security by calling sid(123).

Does anyone know what's going on? If I take out the sell lines the code works fine. I'll add the backtest to this post.
Ignore the normal moving average, it's just for reference.

Thanks everyone.

5 responses

Oh and I'm gonna fix all that context.sids, context.looker garbage so don't worry about that either.

Hi Patrick,

I cloned your algo and it was able to run successfully. Are you still experiencing errors with this code?

Disclaimer

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by Quantopian. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. No information contained herein should be regarded as a suggestion to engage in or refrain from any investment-related course of action as none of Quantopian nor any of its affiliates is undertaking to provide investment advice, act as an adviser to any plan or entity subject to the Employee Retirement Income Security Act of 1974, as amended, individual retirement account or individual retirement annuity, or give advice in a fiduciary capacity with respect to the materials presented herein. If you are an individual retirement or other investor, contact your financial advisor or other fiduciary unrelated to Quantopian about whether any given investment idea, strategy, product or service described herein may be appropriate for your circumstances. All investments involve risk, including loss of principal. Quantopian makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances.

Hi Alisa,

The error was in the last section, but before posting it to the forum I made the section into a comment.
These lines:
# if trimas > trimaf and curs > 0:
# order(context.sids, -1 * curs)
# log.info('Selling ' + str(curs) + ' of these damn things')

#elif trimaf > trimas and curs == 0:  
 #  order(context.sids,shw)  
  # log.info('Bought' + str(shw) + '. Thank me later.') 

Sorry for the confusion.

Patrick, in that last section you passed the list of sids to the order function instead of a single sid, that is where that error is coming from. I'm not positive but I think you wanted that last section included in the for loop above it, and the order was meant to be for the 'cur_sid.' Here's your algo with those changes, let me know if this isn't what you were looking to do.

Thank you David! Looks great!