Dynamic stock chart
This stock chart built in Excel allows you to change the date range and the chart is instantly updated.
What's on this page
1. Dynamic stock chart - Excel 365
The image above demonstrates a dynamic stock chart, enter the stock quote in cell C2. The start and end date in cells C3 and C4, specify daily, weekly or monthly in cell C5.
The STOCKHISTORY function wants the corresponding number instead of daily, weekly, and monthly in order to work properly. We need a formula that converts the text to a number.
0 - daily
1 - weekly
2 - monthly
Formula in cell D5:
Explaining the formula in cell D5
Step 1 - Populate arguments
The MATCH function returns the relative position of an item in an array that matches a specified value in a specific order.
Function syntax: MATCH(lookup_value, lookup_array, [match_type])
becomes
MATCH(C5,{"Daily","weekly","monthly"},0)
Step 2 - Evaluate MATCH function
MATCH(C5,{"Daily","weekly","monthly"},0)
becomes
MATCH("weekly",{"Daily","weekly","monthly"},0)
and returns 2. "weekly" is the second value in the array.
Step 3 - Subtract with one
MATCH(C5,{"Daily","weekly","monthly"},0)-1
becomes
2-1
and returns 1.
0 - daily
1 - weekly
2 - monthly
Excel 365 dynamic array formula in cell B2:
Explaining the formula in cell B2
Step 1 - Populate arguments
The STOCKHISTORY function downloads stock prices based on a stock quote
Function syntax: STOCKHISTORY(stock, start_date, [end_date], [interval], [headers], [property0], [property1], [property2], [property3], [property4], [property5])
becomes
STOCKHISTORY(Sheet1!C2,Sheet1!C3,Sheet1!C4,Sheet1!D5,1,0,3,4,1)
Step 2 - Evaluate STOCKHISTORY function
STOCKHISTORY(Sheet1!C2,Sheet1!C3,Sheet1!C4,Sheet1!D5,1,0,3,4,1)
becomes
STOCKHISTORY("GOOGL",44197,44967,1,1,0,3,4,1)
and returns
{"Date","High","Low","Close";44193,89.4235,86.4,87.632;44200, ... ,95.01}
2. Dynamic stock chart - earlier Excel versions
Here is how to build this chart.
2.1. Create a date range
I entered "Start:" and "End:" in cell range B16:B17. The date values in cells C16 and C17 will determine when the date range begins and ends.
2.2. Copy data
I found the stock price data on the yahoo finance website, here is a link to S&P 500 historical prices.
- Press with left mouse button on the "Get to spreadsheet" link to the get file, you can find the link below historical data.
- Open the geted file in Excel.
- Copy data from the geted file.
- Paste to cell A20 on your worksheet.
The data starts from the 1950s but I can't show all data, for obvious reasons.
2.3. Build dynamic named ranges
We want the chart to change depending on the start and end date in cell range B16:B17. "Named ranges" is what we are looking for, it can return a cell range of variable size.
- Go to "Formulas" on the ribbon.
- Press with left mouse button on "Named Ranges".
- Press with left mouse button on the "New" button.
- Name it "Date".
- Refers to:
=INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1)):INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
- Press with left mouse button on "OK".
- Press with left mouse button on "New" button.
- Name it "High".
- Refers to:
=INDEX(Sheet1!$C$21:$C$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810, -1)):INDEX(Sheet1!$C$21:$C$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
- Press with left mouse button on OK.
- Press with left mouse button on "New".
- Name it "Low".
- Refers to:
=INDEX(Sheet1!$D$21:$D$810, MATCH(Sheet1!$C$16, Sheet1!$A$21:$A$810, -1)):INDEX(Sheet1!$D$21:$D$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
- Press with left mouse button on OK.
- Press with left mouse button on "New".
- Name it "Close".
- Refers to:
=INDEX(Sheet1!$E$21:$E$810, MATCH(Sheet1!$C$16, Sheet1!$A$21:$A$810, -1)):INDEX(Sheet1!$E$21:$E$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
- Press with left mouse button on OK.
You have now created 4 different named ranges which are to be used in the stock chart. You can find a formula explanation later in this post. But first, let's insert a stock chart above the date range.
2.4. Insert a stock chart
- Select cell range C21:E29, column C:E contain high, low and close values.
- Go to tab "Insert" on the ribbon
- Press with left mouse button on "Stock chart" button
The values are in an incorrect order, they need to be reversed.
- Press with right mouse button on on x axis
- Select "Format Axis..."
- Enable option "Categories in reverse order"
2.5. Change series values
It is now time to use the dynamic named ranges we created earlier. They help us quickly change the cell range we want to be shown in the chart.
- Press with right mouse button on on the chart.
- Press with left mouse button on "Select Data...".
- Select Series1.
- Press with left mouse button on the "Edit" button.
- Series values:
=Sheet1!High
(Don't forget to type the sheet name before the named range.)
- Press with left mouse button on OK.
- Select Series2.
- Press with left mouse button on the "Edit" button.
- Series values:
=Sheet1!Low
- Press with left mouse button on OK.
- Select Series3.
- Press with left mouse button on the "Edit" button.
- Series values:
=Sheet1!Close
- Press with left mouse button on OK.
- Press with left mouse button on the "Edit" button below Horizontal (Category) Axis Labels.
- Axis label range:
=Sheet1!Dates
2.6. Explaining the named range (Date) formula
Step 1 - Find the position of value cell C16 in cell range A21:A810
The MATCH function returns a number representing the relative position of a given value in a cell range or array.
MATCH(lookup_value, lookup_array, [match_type])
MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1)
becomes
MATCH(42248,Sheet1!$A$21:$A$810,-1)
and returns 2.
Step 2 - Calculate the first cell ref in the cell range
The INDEX function returns a value or a cell reference based on a row and column number.
INDEX(array, [row_num], [column_num])
INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1))
becomes
INDEX(Sheet1!$A$21:$A$810, 2)
and returns cell ref A22.
Step 3 - Find the position of value cell C17 in cell range A21:A810
The MATCH function returns a number representing the relative position of a given value in a cell range or array.
MATCH(lookup_value, lookup_array, [match_type])
MATCH(Sheet1!$C$17,Sheet1!$A$21:$A$810,-1)
becomes
MATCH(38353,Sheet1!$A$21:$A$810,-1)
and returns 130.
Step 4 - Calculate the second cell ref in the cell range
The INDEX function returns a value or a cell reference based on a row and column number.
INDEX(array, [row_num], [column_num])
INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
becomes
INDEX(Sheet1!$A$21:$A$810, 130)
and returns cell ref A151.
Step 5 - Combine cell refs to a cell range
You can concatenate two cell references using the colon character to create a cell reference to a cell range.
INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$16,Sheet1!$A$21:$A$810,-1)):INDEX(Sheet1!$A$21:$A$810, MATCH(Sheet1!$C$17, Sheet1!$A$21:$A$810, -1))
returns A22:A151.
2.7. How to make the chart even more dynamic
This user defined function allows you to fetch past data for any quote on yahoo finance. You don't have to go to the yahoo finance website and copy/paste the data, this udf does it for you automatically. Just type the stock quote in cell D17 and press enter.
If you are looking for a particular company, index or commodity go to yahoo finance and use their "Quote lookup" to find the quote you are looking for.
Yes, you still need to manually adjust the y axis values on the chart every time you change the date range or stock quote unless you check out this post.
3. Build a stock chart with two series
This article demonstrates how to create a stock chart with two series.
The picture above shows a weekly stock bar chart of Microsoft and Caterpillar. One bar shows you the highest price and the lowest price during that specific week, it also shows the closing price which is the price of the last deal done that week.
Instructions
- Rearrange columns like this: high, low and close
- Select columns High, Low and close
- Go to tab "Insert" on the ribbon
- Press with left mouse button on "Other Charts" and then "High-Low-Close"
- A chart is inserted on your active sheet
- Press with right mouse button on on chart and press with left mouse button on "Select Data..."
- Press with left mouse button on Edit button below Horizontal (Category) Axis Labels
- Select your date range
- Press with left mouse button on OK button twice
- Press with right mouse button on on chart again
- Press with mouse on "Select Data"
- Press with mouse on "Add" button below Legend Entries (Series)
- Select High column for the other stock you want plotted
- Press with left mouse button on OK twice
- Select the chart
- Go to tab "Layout" on the ribbon
- Select series 4
- Press with left mouse button on "Format Selection" below Series 4
- Change to "Secondary Axis"
- Press with left mouse button on Close
- Press with right mouse button on on chart again and press with left mouse button on "Select Data..."
- Add Low and Close series
- Go to tab "Layout" on the ribbon
- Select "Series 4"
- Press with mouse on "Lines" button and then "High-Low" Lines
- Select "Series 6" (Close)
- Press with left mouse button on "Format Selection"
- Go to "Marker Options", choose built-in marker type and the sixth symbol from the top.
- Select size 3
- Go to "Marker Line Color", select "Solid Line" and finally pick a color. I chose dark blue.
- Select "High Low Lines 2"
- Select "Solid Line" and select a color
- Press with left mouse button on Close
You now know how to change the color of high low lines and the closing line. Change the line color of all series (High, Low and Close) on the primary axis.
I chose black. Now delete the secondary axis and remove entries on the legend except "Close" and "Series 6". Change the name of series "Close" to Microsoft and "Series 6" to Caterpillar.
Get excel *.xlsx file
build-a-stock-chart-with-two-series.xlsx
Built-in Charts
Combo Charts
Combined stacked area and a clustered column chartCombined chart – Column and Line on secondary axis
Combined Column and Line chart
Chart elements
Chart basics
How to create a dynamic chartRearrange data source in order to create a dynamic chart
Use slicers to quickly filter chart data
Four ways to resize a chart
How to align chart with cell grid
Group chart categories
Excel charts tips and tricks
Custom charts
How to build an arrow chartAdvanced Excel Chart Techniques
How to graph an equation
Build a comparison table/chart
Heat map yearly calendar
Advanced Gantt Chart Template
Sparklines
Win/Loss Column LineHighlight chart elements
Highlight a column in a stacked column chart no vbaHighlight a group of chart bars
Highlight a data series in a line chart
Highlight a data series in a chart
Highlight a bar in a chart
Interactive charts
How to filter chart dataHover with mouse cursor to change stock in a candlestick chart
How to build an interactive map in Excel
Highlight group of values in an x y scatter chart programmatically
Use drop down lists and named ranges to filter chart values
How to use mouse hover on a worksheet [VBA]
How to create an interactive Excel chart
Change chart series by clicking on data [VBA]
Change chart data range using a Drop Down List [VBA]
How to create a dynamic chart
Animate
Line chart Excel Bar Chart Excel chartAdvanced charts
Custom data labels in a chartHow to improve your Excel Chart
Label line chart series
How to position month and year between chart tick marks
How to add horizontal line to chart
Add pictures to a chart axis
How to color chart bars based on their values
Excel chart problem: Hard to read series values
Build a stock chart with two series
Change chart axis range programmatically
Change column/bar color in charts
Hide specific columns programmatically
Dynamic stock chart
How to replace columns with pictures in a column chart
Color chart columns based on cell color
Heat map using pictures
Dynamic Gantt charts
Stock charts
Build a stock chart with two seriesDynamic stock chart
Change chart axis range programmatically
How to create a stock chart
Excel categories
3 Responses to “Dynamic 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.
Contact Oscar
You can contact me through this contact form
[…] ← Previous post - […]
I needed to add inside a function over a table index, however
the tables are structured by functions such as "indirect" why the references for me to assemble each table are months of the year, meaning every table has the name of one month of the year. and I need to filter through dates that are on each table, ex?
Table, and their names:
January;
February;
March;
Now need to select dates that are within each table:
01/01/2015 to 02/25/2015.
Each table is in a different folder within the same spreadsheet.
I hope you can help me
THANK YOU
[…] https://www.get-digital-help.com/2016/11/16/build-a-stock-chart-with-two-series/ […]