I have hit a brick wall on my excel knowledge, please help.

I am trying to build a tool in excel where I can load historical stock price data. I want to be able to create a simple backtest so that the following rules apply. I will be importing the data via yahoo finances historical price tool.

Basic Trading Rules (based on the book "The Ivy Portfolio")

When price is > 10 period (day,week,month, etc.) moving average = buy (S&P 500, stock, etc.)
When price is < 10 period (day,week,month, etc.) moving average = Sell (sit in cash)

I can create the code to creat the 10 period moving average, but when I try to put it into $$$ and build a historical return column I get into trouble.
The issue is that once a new "buy" signal occurs, I cannot get the data to build on the previous balance.

I am guessing I am not the only one who has ever tried this... any suggestions?

Tech info:
I am running Excel 2010 on a PC