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"
- Click "Other charts"
- 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.
- Select vertical axis
- Right click on vertical axis
- Click "Format axis..."
- Click "Axis Options"
- Click Minimum fixed and type 1050.
- 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.
Reverse horizontal (category) axis
If the dates are backward then these steps tell you how to change the order.
- Select horizontal axis
- Right click on horizontal axis
- Click "Format axis.."
- Click "Axis Options"
- Click "Categories in reverse order"
- Select "Major tick mark type:" None
- Click 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"
- Click "Paste"
- Click "Paste Special.."
- Click "Ok"
- Click on chart
- Go to tab "Format"
- Select "50 day m-avg"
- Click "Format selection"
- Click "Series Options"
- Click "Secondary axis"
- Click "Line color" and select: Solid Line
- Click 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"
- Click "Paste"
- Click "Paste special"
- Click Ok
Select cell range M2:M300 and repeat above steps.
- Left click on chart to select it
- Go to tab "Format"
- Select "Buy"
- Click "Format Selection"
- Click "Marker Options"
- Click "Bulit-in"
- Select a marker type and size
- Select "Marker Fill"
- Click "Solid Fill"
- Select "Line Color": No line
- Click Close
Repeat above steps with "Sell"
Change secondary vertical axis
- Select and right-click on the vertical axis to the left
- Change minimum and maximum values. They must match the primary axis.
- Select and right-click on the vertical axis to the right
- Click "Delete"
Add Data Labels
Buy series
- Left-click on chart to select it
- Go to tab "Layout"
- Select "Buy" series
- Click "Data Labels"
- Click "More Data Label Options"
- Click "Label options"
- Deselect "Values"
- Select "Series Name"
- Label position: Below
- Click Close
Sell series
- Left-click on chart to select it
- Go to tab "Layout"
- Select "Sell" series
- Click "Data Labels"
- Click "More Data Label Options"
- Click "Label options"
- Deselect "Values"
- Select "Series Name"
- Label position: Above
- Click Close
Plot buy and sell points in an Excel Chart based on two moving averages
This article demonstrates how to display buy and sell signals on an Excel chart based on two moving averages, the […]
Follow stock market trends – Moving Average
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 bar is […]
Follow stock market trends – trailing stop
This time I want to demonstrate an alternative way to identify a major trend in the stock market. The previous post […]
2 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 download 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 […]