I'm trying to test an algorithm that buys or sells SPY when the latest close has crossed a simple moving average and rebalance weekly. In my backtest, it appears that the algorithm is just buying a position then instantly selling it each rebalance period. Can someone please help me with this?