Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
My first algo: ema crossing and request for help

Hi all,
This is my first attempt to write an algorithm based on my own (and many others) trading strategies: The idea is to buy when the fast ema crosses the slow ema and the stock is bullish (price higher than a slow sma, e.g., 100 sma); and to short the stock when the conditions are the exact opposite.
I only use indexes (the ones that I remember anyway) in order to ensure high volume and interest.

As you see from the results, the drawdown is huge which I think the reason is that in real trading, the transactions are performed directly after the crossing. In order to do this, I need the ema values for the previous days. I however, have no idea how to access the ema values or price values for past days and only use the current price or ema values. Can anyone help me here and explains how to do that? I would really appreciate that.

In addition, when checking the transactions, I could not see that a shorting was taking place. Am I doing something wrong here?

Regards

4 responses

Peter Cawthron,
It's very strange. I received an email where you explain to me how to solve my problem. However, when I log in to Quantopian I cannot see your reply in the thread. I wonder where your reply went. Is it possible that you send your reply again?

Hello Omar,

Sorry - the code had a major defect. I'll post it again once that is resolved!

P.

Hello Peter,
Thank you so very much for your help. Your idea about creating a queue of length 2 is actually a good solution. I wouldn't have thought about it myself. I will also experiment with it while waiting for your answer.
/Omar

Hello Peter,
Thank you so very much for your help. Your idea about creating a queue of length 2 is actually a good solution. I wouldn't have thought about it myself. I will also experiment with it while waiting for your answer.
/Omar