Below is an animated gif demonstrating a stock chart with monthly prices. Two moving averages #1, #2, buy and sell points are plotted in this chart.

When the moving averages intersects a buy or sell point is created. If you use the value 7 in cell C1, moving average #1 uses the average of 7 months.

As you can see using a 15 month average (#1) returns better and fewer buy and sell points.

S&P500

Extracting buy and sell points

Not only is the chart refreshed as you type new values in cell C1 and C2, the data below the chart is also instantly refreshed.

Array formula in cell B25:

=IFERROR(INDEX(Calculation!$D$2:$D$247, LARGE(IF((IFERROR(Calculation!$M$2:$M$247, "")<>"")+(IFERROR(Calculation!$N$2:$N$247, "")<>""), MATCH(ROW(Calculation!$M$2:$M$247), ROW(Calculation!$M$2:$M$247)), ""), ROW(A1))), "")

Array formula in cell C25:

=IFERROR(IF(INDEX(Calculation!$M$2:$M$300, MATCH(B25, Calculation!$D$2:$D$300, 0))="", "Sell", "Buy"), "")

Array formula in cell D25:

=IFERROR(INDEX(Calculation!$H$2:$H$300, MATCH(B25, Calculation!$D$2:$D$300, 0)), "")

How to create an array formula

  1. Copy array formula
  2. Select cell B25
  3. Paste formula
  4. Press and hold Ctrl+ Shift
  5. Press Enter

How to copy array formula

  1. Select cell B25
  2. Copy cell (not formula in formula bar)
  3. Select cell range B26:B50
  4. Paste

Calculating buy and sell points

Sheet: Calculation

Array formula in cell K2:

=AVERAGE(OFFSET(H2, 0, 0, Overview!$C$1))

Array formula in cell L2:

=AVERAGE(OFFSET(H2, 0, 0, Overview!$C$2))

Formula in cell M2:

=IF((L3<K3)*(L2>K2), K2, "")

Formula in cell N2:

=IF((L3>K3)*(L2<K2), K2, "")

Copy cells and paste down as far as needed.

The calculation sheet imports historical prices using this user defined function:
Excel udf: Import historical stock prices from yahoo – added features

Further reading

If you want to know how to plot buy and sell points in an excel stock chart, read this post:
Add buy and sell points to a stock chart

Download excel *.xlsm file

excel-stock-chart-two-moving-averagesv2.xlsm