Add buy and sell points to a stock chart
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:
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:
In cell M2:
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:
In cell B3:
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:
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.
- Select cell range F1:H300
- Go to tab "Insert"
- Press with left mouse button on "Other charts"
- Press with left mouse button on "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.
- Select vertical axis
- Press with right mouse button on on vertical axis
- Press with left mouse button on "Format axis..."
- Press with left mouse button on "Axis Options"
- Press with left mouse button on Minimum fixed and type 1050.
- Press with left mouse button on 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.
- Press with right mouse button on on chart
- Press with left mouse button on "Select data"
- Press with left mouse button on "Edit" button
- Select cell range B2:C300
- Press with left mouse button on OK
Reverse horizontal (category) axis
If the dates are backward then these steps tell you how to change the order.
- Select horizontal axis
- Press with right mouse button on on horizontal axis
- Press with left mouse button on "Format axis.."
- Press with left mouse button on "Axis Options"
- Press with left mouse button on "Categories in reverse order"
- Select "Major tick mark type:" None
- Press with left mouse button on OK
Add moving average
These steps explains how to display the moving average on an Excel chart.
- Select cell range K1:K300
- Copy
- Select chart
- Got to tab "Home"
- Press with left mouse button on "Paste"
- Press with left mouse button on "Paste Special.."
- Press with left mouse button on "Ok"
- Press with mouse on chart
- Go to tab "Format"
- Select "50 day m-avg"
- Press with left mouse button on "Format selection"
- Press with left mouse button on "Series Options"
- Press with left mouse button on "Secondary axis"
- Press with left mouse button on "Line color" and select: Solid Line
- Press with left mouse button on Close button
 How to display buy and sell signals on an Excel chart?
- Select cell range L2:L300
- Copy
- Select chart
- Go to tab "Home"
- Press with left mouse button on "Paste"
- Press with left mouse button on "Paste special"
- Press with left mouse button on Ok
Select cell range M2:M300 and repeat above steps.
- Press with left mouse button on on chart to select it
- Go to tab "Format"
- Select "Buy"
- Press with left mouse button on "Format Selection"
- Press with left mouse button on "Marker Options"
- Press with left mouse button on "Bulit-in"
- Select a marker type and size
- Select "Marker Fill"
- Press with left mouse button on "Solid Fill"
- Select "Line Color": No line
- Press with left mouse button on Close
Repeat above steps with "Sell"
Change secondary vertical axis
- Select and press with right mouse button on on the vertical axis to the left
- Change minimum and maximum values. They must match the primary axis.
- Select and press with right mouse button on on the vertical axis to the right
- Press with left mouse button on "Delete"
Add Data Labels
Buy series
- Press with left mouse button on on chart to select it
- Go to tab "Layout"
- Select "Buy" series
- Press with left mouse button on "Data Labels"
- Press with left mouse button on "More Data Label Options"
- Press with left mouse button on "Label options"
- Deselect "Values"
- Select "Series Name"
- Label position: Below
- Press with left mouse button on Close
Sell series
- Press with left mouse button on on chart to select it
- Go to tab "Layout"
- Select "Sell" series
- Press with left mouse button on "Data Labels"
- Press with left mouse button on "More Data Label Options"
- Press with left mouse button on "Label options"
- Deselect "Values"
- Select "Series Name"
- Label position: Above
- Press with left mouse button on Close
Stock market trend category
This article demonstrates how to display buy and sell signals on an Excel chart based on two moving averages, the […]
In my previous post, I described how to build a dynamic stock chart that lets you easily adjust the date […]
If you study a stock chart you will discover that sometimes significant trend reversals happen when a stock chart […]
Functions in this article
More than 1300 Excel formulas
Excel categories
3 Responses to “Add buy and sell points to a stock chart”
Leave a Reply
How to comment
How to add a formula to your comment
<code>Insert your formula here.</code>
Convert less than and larger than signs
Use html character entities instead of less than and larger than signs.
< becomes < and > becomes >
How to add VBA code to your comment
[vb 1="vbnet" language=","]
Put your VBA code here.
[/vb]
How to add a picture to your comment:
Upload picture to postimage.org or imgur
Paste image link to your comment.
Hello Oscar,
Your example file shows the error message "#DIV/0!" on the: 50 day m-avg, Buy, Sell columns.
Also when I tried to duplicate your instructions I got a line for both the buy and sell signals symbols on the 0 horizontal line.
How do I get rid of the buy/sell signal symbols on the horizontal 0 line.
One last thing how is it possible to change the date format to "mm dd yy"?
Thank you, have a nice day.
Thank you
[…] 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 […]
Hi Oscar, please could you publish an update with STOCKHISTORY excel function showing all columns and headers as cannot download yahoo anymore