Author: Oscar Cronquist Article last updated on September 04, 2019

The image above shows an Excel chart of the S&P 500 with buy and sell signals based on a 50 day average.

It is easy to create a stock chart in Excel. In this article, I am going to describe how to insert buy and sell points to an Excel chart.

To simplify things I will use a 50 day moving average as an indicator. If the 50day average changes from negative to positive a buy signal is generated and a sell signal when the average moves from positive to a negative trend.

I have copied stock data from the Yahoo Finance website, you can easily pick a stock or index and get historical data.

### Calculating moving average

The AVERAGE function calculates the moving average, remember to use the last 50 days as an argument. I am using a relative cell reference that changes accordingly when the cell is copied to cells below.

In cell K2:

=AVERAGE(H2:H51)

Copy cell K2 and paste down as far as needed.

### Find buy and sell dates

The following formulas check if the 50-day average is higher or lower than the previous day and the day before that, this will return the close value only if there is a change in trend.

In other words multiple buy or sell signals won't be displayed, only the first one. The first IF function has two logical expressions (K2-K3>0) and (K3-K4<0), both these conditions must be true to return the value in K2.

In cell L2:

=IF((K2-K3>0)*(K3-K4<0), K2, "")

In cell M2:

=IF((K2-K3<0)*(K3-K4>0), K2*1, "")

Copy cell L2 and M2 and paste down as far as needed.

### Extract year and month from date

Let's extract year and month from dates to avoid a mess on the x axis in our stock chart. The YEAR function returns the year based on an Excel date.

Chandoo has a great post: Show Months & Years in Charts without Cluttering

In cell B2:

=YEAR(D2)

In cell B3:

=IF(YEAR(D3)=YEAR(D2), "", YEAR(D3))

The TEXT function formats an Excel date in this particular example, and displays the month formatted with only first three visible characters.

The IF function makes sure that the formatted month name is shown only when the month changes, this to avoid repeated months.

Cell C2:

=IF(TEXT(D2, "MMM")=TEXT(D3, "MMM"), "", TEXT(D2, "MMM"))

Copy cell B3 and C2 and paste down as far as needed.

### Create stock chart

It is important that the data is arranged in this order: High, Low and Close.

1. Select cell range F1:H300
2. Go to tab "Insert"
3. Click "Other charts"
4. Click "High Low Close stock chart"

### Adjust vertical axis min and max values

If your chart is zoomed out too far you can simply adjust the visible axis range by following these steps.

1. Select vertical axis
2. Right click on vertical axis
3. Click "Format axis..."
4. Click "Axis Options"
5. Click Minimum fixed and type 1050.
6. Click Maximum fixed and type 1450.

### Change horizontal axis labels

These steps change the x-axis numbers to years and months based on the values in column B and C.

1. Right click on chart
2. Click "Select data"
3. Click "Edit" button
4. Select cell range B2:C300
5. Click OK

### Reverse horizontal (category) axis

If the dates are backward then these steps tell you how to change the order.

1. Select horizontal axis
2. Right click on horizontal axis
3. Click "Format axis.."
4. Click "Axis Options"
5. Click "Categories in reverse order"
6. Select "Major tick mark type:" None
7. Click OK

These steps explains how to display the moving average on an Excel chart.

1. Select cell range K1:K300
2. Copy
3. Select chart
4. Got to tab "Home"
5. Click "Paste"
6. Click "Paste Special.."
7. Click "Ok"
8. Click on chart
9. Go to tab "Format"
10. Select "50 day m-avg"
11. Click "Format selection"
12. Click "Series Options"
13. Click "Secondary axis"
14. Click "Line color" and select: Solid Line
15. Click Close button

### How to display buy and sell signals on an Excel chart?

1. Select cell range L2:L300
2. Copy
3. Select chart
4. Go to tab "Home"
5. Click "Paste"
6. Click "Paste special"
7. Click Ok

Select cell range M2:M300 and repeat above steps.

1. Left click on chart to select it
2. Go to tab "Format"
4. Click "Format Selection"
5. Click "Marker Options"
6. Click "Bulit-in"
7. Select a marker type and size
8. Select "Marker Fill"
9. Click "Solid Fill"
10. Select "Line Color": No line
11. Click Close

Repeat above steps with "Sell"

### Change secondary vertical axis

1. Select and right-click on the vertical axis to the left
2. Change minimum and maximum values. They must match the primary axis.
3. Select and right-click on the vertical axis to the right
4. Click "Delete"

1. Left-click on chart to select it
2. Go to tab "Layout"
4. Click "Data Labels"
5. Click "More Data Label Options"
6. Click "Label options"
7. Deselect "Values"
8. Select "Series Name"
9. Label position: Below
10. Click Close

Sell series

1. Left-click on chart to select it
2. Go to tab "Layout"
3. Select "Sell" series
4. Click "Data Labels"
5. Click "More Data Label Options"
6. Click "Label options"
7. Deselect "Values"
8. Select "Series Name"
9. Label position: Above
10. Click Close