Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Issue - Buy/Sell based on MA30

I'm having trouble creating a simple algo that buys a security when the current price rises above the an MA by a certain percentage, and then sells the security when the price is less than the same MA. I have used a previous algo from the community as a base, but the issue I'm finding is that the algo performed differently than if the trade was completed manually while viewing the price chart (link below).

In the example, COST was to be purchased for a total trade value of $10,000 when it exceeded the MA30 by 0.001, and then sold when it moves below the MA30. If you were to look at the price chart for that time period Price Chart, you would see that both buy and sell orders should have taken place in the May 27 - May 28 backtest period (Minutes).

Instead, only one buy order occurred, with no sell orders following. This process (buy -> sell -> buy -> sell) should have taken place at least 2 times according to the price chart.

Can any describe a potential error I made that lead to only one buy, or why theres such a large difference between the price chart action and the algo's actions (if the code is correct) if they are both using Minutes?

Thanks

2 responses

Typo, you wanted 1.001

Thanks, just edited. Still unsure of the error though.