Im unsure if I am setting up my code correctly. Im new to this:
Strategy:
Momentum investing from exponential moving average (EMA) signals.
Every day, we long SPY if EMA 7 is greater than EMA 16, which signals upward price momentum.
Hold 100% cash if SPY crosses below EMA 7.
And short SPY if EMA 16 is greater than EMA 7, which signals downward price momentum.
Also, if a gap of 3.2% opens up between the SPY and EMA 7 (meaning (SPY-EMA7)/EMA7 = 0.032) we short with 50% of capital.
And vice versa, if (EMA7-SPY)/SPY = 0.032 --> we go long with 50% of capital.
I'm totally lost when it comes to coding and would really appreciate some help. Thanks!