Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
Why is my code not executing these orders?

It seems like this should work fine, but I feel like I may be referencing something wrong in my handle_data. The comments explain what is supposed to be happening very well. A transaction only happens once. How can I get it to execute based on the calculated RSI value?

Thanks
Jack

2 responses
    dif = price_history.iloc[[x, x-1]].diff()  

Is going to return a two element DataFrame, the first one will be the imaginary diff between the non-existant previous day.

Secondly you're calculating RSI wrong.

  • First Average Gain = Sum of Gains over the past x periods / x
  • First Average Loss = Sum of Losses over the past x periods / x

Subsequent Average Gain/Loss:

  • Average Gain = [(previous Average Gain) x (x-1) + current Gain] / x
  • Average Loss = [(previous Average Loss) x (x-1) + current Loss] / x.

Try not to reinvent the wheel if you dont have to.

Also I think your RSI checks are backwards. You're buying when the RSI shows overbought.

Also, a 180 day RSI is going to have almost zero signals because it'll average pretty close to 50.

How do I take just the number from the DataFrame or whatever that I get from using history()?